├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md └── com.amitinside.dependency.graph.osgi ├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── pom.xml └── src └── main └── java └── com └── amitinside └── dependency └── graph └── osgi ├── DependencyGraph.java ├── GraphConfigurer.java ├── ResourceInfo.java ├── algo └── CycleDetection.java ├── cli ├── Application.java ├── CliConfiguration.java ├── CliOptions.java └── Namespace.java └── util └── Helper.java /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## 1. Purpose 4 | 5 | A primary goal of Dependency Graph in OSGi is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). 6 | 7 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. 8 | 9 | We invite all those who participate in Dependency Graph in OSGi to help us create safe and positive experiences for everyone. 10 | 11 | ## 2. Open Source Citizenship 12 | 13 | A supplemental goal of this Code of Conduct is to increase open source citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. 14 | 15 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. 16 | 17 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. 18 | 19 | ## 3. Expected Behavior 20 | 21 | The following behaviors are expected and requested of all community members: 22 | 23 | * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. 24 | * Exercise consideration and respect in your speech and actions. 25 | * Attempt collaboration before conflict. 26 | * Refrain from demeaning, discriminatory, or harassing behavior and speech. 27 | * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. 28 | * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. 29 | 30 | ## 4. Unacceptable Behavior 31 | 32 | The following behaviors are considered harassment and are unacceptable within our community: 33 | 34 | * Violence, threats of violence or violent language directed against another person. 35 | * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. 36 | * Posting or displaying sexually explicit or violent material. 37 | * Posting or threatening to post other people’s personally identifying information ("doxing"). 38 | * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. 39 | * Inappropriate photography or recording. 40 | * Inappropriate physical contact. You should have someone’s consent before touching them. 41 | * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. 42 | * Deliberate intimidation, stalking or following (online or in person). 43 | * Advocating for, or encouraging, any of the above behavior. 44 | * Sustained disruption of community events, including talks and presentations. 45 | 46 | ## 5. Consequences of Unacceptable Behavior 47 | 48 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 49 | 50 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 51 | 52 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). 53 | 54 | ## 6. Reporting Guidelines 55 | 56 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. amit@amitinside.com. 57 | 58 | 59 | 60 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. 61 | 62 | ## 7. Addressing Grievances 63 | 64 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify Amit Kumar Mondal with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies. 65 | 66 | 67 | 68 | ## 8. Scope 69 | 70 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues–online and in-person–as well as in all one-on-one communications pertaining to community business. 71 | 72 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. 73 | 74 | ## 9. Contact info 75 | 76 | amit@amitinside.com 77 | 78 | ## 10. License and attribution 79 | 80 | This Code of Conduct is distributed under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). 81 | 82 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). 83 | 84 | Retrieved on November 22, 2016 from [http://citizencodeofconduct.org/](http://citizencodeofconduct.org/) 85 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | First of all, thanks for considering to contribute. We appreciate the time and effort you want to 4 | spend helping to improve things around here. And help we can use :-) 5 | 6 | Here is a (non-exclusive, non-prioritized) list of things you might be able to help us with: 7 | 8 | * bug reports 9 | * bug fixes 10 | * improvements regarding code quality, e.g. improving readability, performance, modularity etc. 11 | * documentation 12 | * features (both ideas and code are welcome) 13 | * tests 14 | 15 | ### File Headers 16 | A proper header must be in place for any file contributed to the project. For a new contribution, please add the below header: 17 | 18 | ``` 19 | /******************************************************************************* 20 | * Copyright (c) and others 21 | * 22 | * All rights reserved. This program and the accompanying materials 23 | * are made available under the terms of the Eclipse Public License v1.0 24 | * which accompanies this distribution, and is available at 25 | * http://www.eclipse.org/legal/epl-v10.html 26 | * 27 | ******************************************************************************/ 28 | ``` 29 | 30 | Please ensure \ is replaced with the current year or range (e.g. 2017 or 2015, 2017). 31 | Please ensure \ is replaced with the relevant information. If you are editing an existing contribution, feel free 32 | to create or add your legal entity to the contributors section as such: 33 | 34 | ``` 35 | /******************************************************************************* 36 | * Copyright (c) and others 37 | * 38 | * All rights reserved. This program and the accompanying materials 39 | * are made available under the terms of the Eclipse Public License v1.0 40 | * which accompanies this distribution, and is available at 41 | * http://www.eclipse.org/legal/epl-v10.html 42 | * 43 | * Contributors: 44 | * 45 | *******************************************************************************/ 46 | ``` 47 | 48 | ### How to Contribute 49 | The easiest way to contribute code/patches/whatever is by creating a GitHub pull request (PR). When you do make sure that you *Sign-off* your commits. 50 | 51 | You do this by adding the `-s` flag when you make the commit(s), e.g. 52 | 53 | $> git commit -s -m "Let's do it." 54 | 55 | ## Making your Changes 56 | 57 | * Fork the repository on GitHub 58 | * Create a new branch for your changes 59 | * Configure your IDE installing: 60 | * [SonarLint](http://www.sonarlint.org/eclipse/index.html) 61 | * Make your changes 62 | * Make sure copyright headers are included in (all) files including updated year(s) 63 | * Make sure proper headers are in place for each file (see above Legal Requirements) 64 | * Commit your changes to that branch 65 | * Use descriptive and meaningful commit messages 66 | * If you have a lot of commits squash them into a single commit 67 | * Make sure you use the `-s` flag when committing as explained above 68 | * Push your changes to your branch in your forked repository 69 | 70 | ## Submitting the Changes 71 | 72 | Submit a pull request via the normal GitHub UI. 73 | 74 | ## After Submitting 75 | 76 | * Do not use your branch for any other development, otherwise further changes that you make will be visible in the PR. 77 | 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 2.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 4 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION 5 | OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial content 12 | Distributed under this Agreement, and 13 | 14 | b) in the case of each subsequent Contributor: 15 | i) changes to the Program, and 16 | ii) additions to the Program; 17 | where such changes and/or additions to the Program originate from 18 | and are Distributed by that particular Contributor. A Contribution 19 | "originates" from a Contributor if it was added to the Program by 20 | such Contributor itself or anyone acting on such Contributor's behalf. 21 | Contributions do not include changes or additions to the Program that 22 | are not Modified Works. 23 | 24 | "Contributor" means any person or entity that Distributes the Program. 25 | 26 | "Licensed Patents" mean patent claims licensable by a Contributor which 27 | are necessarily infringed by the use or sale of its Contribution alone 28 | or when combined with the Program. 29 | 30 | "Program" means the Contributions Distributed in accordance with this 31 | Agreement. 32 | 33 | "Recipient" means anyone who receives the Program under this Agreement 34 | or any Secondary License (as applicable), including Contributors. 35 | 36 | "Derivative Works" shall mean any work, whether in Source Code or other 37 | form, that is based on (or derived from) the Program and for which the 38 | editorial revisions, annotations, elaborations, or other modifications 39 | represent, as a whole, an original work of authorship. 40 | 41 | "Modified Works" shall mean any work in Source Code or other form that 42 | results from an addition to, deletion from, or modification of the 43 | contents of the Program, including, for purposes of clarity any new file 44 | in Source Code form that contains any contents of the Program. Modified 45 | Works shall not include works that contain only declarations, 46 | interfaces, types, classes, structures, or files of the Program solely 47 | in each case in order to link to, bind by name, or subclass the Program 48 | or Modified Works thereof. 49 | 50 | "Distribute" means the acts of a) distributing or b) making available 51 | in any manner that enables the transfer of a copy. 52 | 53 | "Source Code" means the form of a Program preferred for making 54 | modifications, including but not limited to software source code, 55 | documentation source, and configuration files. 56 | 57 | "Secondary License" means either the GNU General Public License, 58 | Version 2.0, or any later versions of that license, including any 59 | exceptions or additional permissions as identified by the initial 60 | Contributor. 61 | 62 | 2. GRANT OF RIGHTS 63 | 64 | a) Subject to the terms of this Agreement, each Contributor hereby 65 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 66 | license to reproduce, prepare Derivative Works of, publicly display, 67 | publicly perform, Distribute and sublicense the Contribution of such 68 | Contributor, if any, and such Derivative Works. 69 | 70 | b) Subject to the terms of this Agreement, each Contributor hereby 71 | grants Recipient a non-exclusive, worldwide, royalty-free patent 72 | license under Licensed Patents to make, use, sell, offer to sell, 73 | import and otherwise transfer the Contribution of such Contributor, 74 | if any, in Source Code or other form. This patent license shall 75 | apply to the combination of the Contribution and the Program if, at 76 | the time the Contribution is added by the Contributor, such addition 77 | of the Contribution causes such combination to be covered by the 78 | Licensed Patents. The patent license shall not apply to any other 79 | combinations which include the Contribution. No hardware per se is 80 | licensed hereunder. 81 | 82 | c) Recipient understands that although each Contributor grants the 83 | licenses to its Contributions set forth herein, no assurances are 84 | provided by any Contributor that the Program does not infringe the 85 | patent or other intellectual property rights of any other entity. 86 | Each Contributor disclaims any liability to Recipient for claims 87 | brought by any other entity based on infringement of intellectual 88 | property rights or otherwise. As a condition to exercising the 89 | rights and licenses granted hereunder, each Recipient hereby 90 | assumes sole responsibility to secure any other intellectual 91 | property rights needed, if any. For example, if a third party 92 | patent license is required to allow Recipient to Distribute the 93 | Program, it is Recipient's responsibility to acquire that license 94 | before distributing the Program. 95 | 96 | d) Each Contributor represents that to its knowledge it has 97 | sufficient copyright rights in its Contribution, if any, to grant 98 | the copyright license set forth in this Agreement. 99 | 100 | e) Notwithstanding the terms of any Secondary License, no 101 | Contributor makes additional grants to any Recipient (other than 102 | those set forth in this Agreement) as a result of such Recipient's 103 | receipt of the Program under the terms of a Secondary License 104 | (if permitted under the terms of Section 3). 105 | 106 | 3. REQUIREMENTS 107 | 108 | 3.1 If a Contributor Distributes the Program in any form, then: 109 | 110 | a) the Program must also be made available as Source Code, in 111 | accordance with section 3.2, and the Contributor must accompany 112 | the Program with a statement that the Source Code for the Program 113 | is available under this Agreement, and informs Recipients how to 114 | obtain it in a reasonable manner on or through a medium customarily 115 | used for software exchange; and 116 | 117 | b) the Contributor may Distribute the Program under a license 118 | different than this Agreement, provided that such license: 119 | i) effectively disclaims on behalf of all other Contributors all 120 | warranties and conditions, express and implied, including 121 | warranties or conditions of title and non-infringement, and 122 | implied warranties or conditions of merchantability and fitness 123 | for a particular purpose; 124 | 125 | ii) effectively excludes on behalf of all other Contributors all 126 | liability for damages, including direct, indirect, special, 127 | incidental and consequential damages, such as lost profits; 128 | 129 | iii) does not attempt to limit or alter the recipients' rights 130 | in the Source Code under section 3.2; and 131 | 132 | iv) requires any subsequent distribution of the Program by any 133 | party to be under a license that satisfies the requirements 134 | of this section 3. 135 | 136 | 3.2 When the Program is Distributed as Source Code: 137 | 138 | a) it must be made available under this Agreement, or if the 139 | Program (i) is combined with other material in a separate file or 140 | files made available under a Secondary License, and (ii) the initial 141 | Contributor attached to the Source Code the notice described in 142 | Exhibit A of this Agreement, then the Program may be made available 143 | under the terms of such Secondary Licenses, and 144 | 145 | b) a copy of this Agreement must be included with each copy of 146 | the Program. 147 | 148 | 3.3 Contributors may not remove or alter any copyright, patent, 149 | trademark, attribution notices, disclaimers of warranty, or limitations 150 | of liability ("notices") contained within the Program from any copy of 151 | the Program which they Distribute, provided that Contributors may add 152 | their own appropriate notices. 153 | 154 | 4. COMMERCIAL DISTRIBUTION 155 | 156 | Commercial distributors of software may accept certain responsibilities 157 | with respect to end users, business partners and the like. While this 158 | license is intended to facilitate the commercial use of the Program, 159 | the Contributor who includes the Program in a commercial product 160 | offering should do so in a manner which does not create potential 161 | liability for other Contributors. Therefore, if a Contributor includes 162 | the Program in a commercial product offering, such Contributor 163 | ("Commercial Contributor") hereby agrees to defend and indemnify every 164 | other Contributor ("Indemnified Contributor") against any losses, 165 | damages and costs (collectively "Losses") arising from claims, lawsuits 166 | and other legal actions brought by a third party against the Indemnified 167 | Contributor to the extent caused by the acts or omissions of such 168 | Commercial Contributor in connection with its distribution of the Program 169 | in a commercial product offering. The obligations in this section do not 170 | apply to any claims or Losses relating to any actual or alleged 171 | intellectual property infringement. In order to qualify, an Indemnified 172 | Contributor must: a) promptly notify the Commercial Contributor in 173 | writing of such claim, and b) allow the Commercial Contributor to control, 174 | and cooperate with the Commercial Contributor in, the defense and any 175 | related settlement negotiations. The Indemnified Contributor may 176 | participate in any such claim at its own expense. 177 | 178 | For example, a Contributor might include the Program in a commercial 179 | product offering, Product X. That Contributor is then a Commercial 180 | Contributor. If that Commercial Contributor then makes performance 181 | claims, or offers warranties related to Product X, those performance 182 | claims and warranties are such Commercial Contributor's responsibility 183 | alone. Under this section, the Commercial Contributor would have to 184 | defend claims against the other Contributors related to those performance 185 | claims and warranties, and if a court requires any other Contributor to 186 | pay any damages as a result, the Commercial Contributor must pay 187 | those damages. 188 | 189 | 5. NO WARRANTY 190 | 191 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 192 | PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" 193 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 194 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF 195 | TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 196 | PURPOSE. Each Recipient is solely responsible for determining the 197 | appropriateness of using and distributing the Program and assumes all 198 | risks associated with its exercise of rights under this Agreement, 199 | including but not limited to the risks and costs of program errors, 200 | compliance with applicable laws, damage to or loss of data, programs 201 | or equipment, and unavailability or interruption of operations. 202 | 203 | 6. DISCLAIMER OF LIABILITY 204 | 205 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 206 | PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS 207 | SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 208 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST 209 | PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 210 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 211 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 212 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE 213 | POSSIBILITY OF SUCH DAMAGES. 214 | 215 | 7. GENERAL 216 | 217 | If any provision of this Agreement is invalid or unenforceable under 218 | applicable law, it shall not affect the validity or enforceability of 219 | the remainder of the terms of this Agreement, and without further 220 | action by the parties hereto, such provision shall be reformed to the 221 | minimum extent necessary to make such provision valid and enforceable. 222 | 223 | If Recipient institutes patent litigation against any entity 224 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 225 | Program itself (excluding combinations of the Program with other software 226 | or hardware) infringes such Recipient's patent(s), then such Recipient's 227 | rights granted under Section 2(b) shall terminate as of the date such 228 | litigation is filed. 229 | 230 | All Recipient's rights under this Agreement shall terminate if it 231 | fails to comply with any of the material terms or conditions of this 232 | Agreement and does not cure such failure in a reasonable period of 233 | time after becoming aware of such noncompliance. If all Recipient's 234 | rights under this Agreement terminate, Recipient agrees to cease use 235 | and distribution of the Program as soon as reasonably practicable. 236 | However, Recipient's obligations under this Agreement and any licenses 237 | granted by Recipient relating to the Program shall continue and survive. 238 | 239 | Everyone is permitted to copy and distribute copies of this Agreement, 240 | but in order to avoid inconsistency the Agreement is copyrighted and 241 | may only be modified in the following manner. The Agreement Steward 242 | reserves the right to publish new versions (including revisions) of 243 | this Agreement from time to time. No one other than the Agreement 244 | Steward has the right to modify this Agreement. The Eclipse Foundation 245 | is the initial Agreement Steward. The Eclipse Foundation may assign the 246 | responsibility to serve as the Agreement Steward to a suitable separate 247 | entity. Each new version of the Agreement will be given a distinguishing 248 | version number. The Program (including Contributions) may always be 249 | Distributed subject to the version of the Agreement under which it was 250 | received. In addition, after a new version of the Agreement is published, 251 | Contributor may elect to Distribute the Program (including its 252 | Contributions) under the new version. 253 | 254 | Except as expressly stated in Sections 2(a) and 2(b) above, Recipient 255 | receives no rights or licenses to the intellectual property of any 256 | Contributor under this Agreement, whether expressly, by implication, 257 | estoppel or otherwise. All rights in the Program not expressly granted 258 | under this Agreement are reserved. Nothing in this Agreement is intended 259 | to be enforceable by any entity that is not a Contributor or Recipient. 260 | No third-party beneficiary rights are created under this Agreement. 261 | 262 | Exhibit A - Form of Secondary Licenses Notice 263 | 264 | "This Source Code may also be made available under the following 265 | Secondary Licenses when the conditions for such availability set forth 266 | in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), 267 | version(s), and exceptions or additional permissions here}." 268 | 269 | Simply including a copy of this Agreement, including this Exhibit A 270 | is not sufficient to license the Source Code under Secondary Licenses. 271 | 272 | If it is not possible or desirable to put the notice in a particular 273 | file, then You may include the notice in a location (such as a LICENSE 274 | file in a relevant directory) where a recipient would be likely to 275 | look for such a notice. 276 | 277 | You may add additional accurate notices of copyright ownership. 278 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | logo 2 | 3 | ## Why? [![start with what and why](https://img.shields.io/badge/start%20with-why%3F-brightgreen.svg?style=flat)]() 4 | 5 | This is an easy to use tool to visualize OSGi Dependencies in a graph. In addition, this tool also supports detection of cyclic dependencies in the plotted graph. The primary goal is to minimize the effort in analyzing big software projects based on OSGi. 6 | 7 | --------------------------------------------------------------------------------------------------------------------------------- 8 | 9 | ### Requirements 10 | 11 | Java 8+ 12 | 13 | 14 | ### Contribution [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)]() 15 | Want to contribute? Great! Check out [Contribution Guide](https://github.com/amitjoy/dependency-graph-osgi/blob/master/CONTRIBUTING.md) 16 | 17 | --------------------------------------------------------------------------------------------------------------------------------- 18 | 19 | #### Project Import 20 | 21 | **Import as Maven Project** 22 | 23 | Import the project as an `Existing Maven Project` (`File -> Import -> Maven -> Existing Maven Projects`) 24 | 25 | ------------------------------------------------------------------------------------------------------------------------ 26 | 27 | #### Building from Source 28 | 29 | 1. Run `mvn clean package` in `com.amitinside.dependency.graph.osgi` 30 | 2. This will build the project 31 | 3. The target directory will contain `dependency.graph.osgi-0.0.1-SNAPSHOT-jar-with-dependencies.jar` 32 | 33 | ------------------------------------------------------------------------------------------------------------------------ 34 | 35 | ### License 36 | 37 | This project is licensed under EPL-2.0 [![License](http://img.shields.io/badge/license-EPL-blue.svg)](http://www.eclipse.org/legal/epl-2.0) 38 | 39 | ---------------------------------------------------------------------------------------------------------------------- 40 | 41 | ### Usage 42 | 43 | To use this application, you need an OBR (`OSGi Bundle Repository`) Index XML File. 44 | 45 | #### OBR Index Generation 46 | 47 | 1. You need to download the bnd command line utility from https://search.maven.org/artifact/biz.aQute.bnd/biz.aQute.bnd 48 | 2. Using terminal, switch to your workspace directory and execute - `java -jar biz.aQute.bnd.jar index */target/*.jar` 49 | 3. This assumes that all the target artifacts are kept in `target` directory in the respective projects 50 | 4. Alternatively, you can copy all your project JARs inside a separate directory 51 | 5. Switch to this newly created directory in command line and execute `java -jar biz.aQute.bnd.jar index *.jar` 52 | 6. Both the aforementioned commands will generate OBR `index.xml` in the respective directories where the command is executed 53 | 54 | #### Create Bundles List 55 | 56 | 1. You need to have a file comprising the bundle symbolic names of the bundles whose dependencies will be plotted on the graph 57 | 2. You can create a `bundles.txt` (or give it a name of your choice) with bundle symbolic names in separate lines. You can also use wildcards. For example, `com.google.*` will consider all the bundles whose symbolic names start with `com.google.` Apart from it, you can also use negations. For example, `!org.apache*` would remove all the bundles from the Graph whose symbolic names start with `org.apache`. 58 | 59 | #### 60 | 61 | Help Command: 62 | 63 | ``` 64 | usage: Dependency Graph in OSGi - Help 65 | -? Show Help 66 | -bundles Bundle List File Location 67 | -cycle Check for Cycle Existence 68 | -debug Turn on Debug Mode 69 | -edge Show Edge Labels 70 | -help Show Help 71 | -ns Namespace Type to Plot [ALL, PACKAGE, SERVICE, 72 | IDENTITY, EE, NATIVE, CONTENT, IMPLEMENTATION, 73 | CONTRACT, BUNDLE, HOST, CUSTOM] (Default ALL) 74 | -ns_custom Custom Namespace (Needs to be set if ns option is set 75 | to CUSTOM 76 | -obr OBR Index File Location 77 | ``` 78 | 79 | #### Example 80 | 81 | `java -jar dependency.graph.osgi-0.0.1-SNAPSHOT-jar-with-dependencies.jar -obr index.xml -bundles bundles.txt -edge` - Plot the matched bundles from bundles.txt using the specified OBR index.xml with edge labels 82 | 83 | -------------------------------------------------------------------------------------------------------------- 84 | 85 | ### Tools Used 86 | 87 | 1. https://bnd.bndtools.org 88 | 2. http://graphstream-project.org 89 | 90 | ------------------------------------------------------------------------------------------------------------ 91 | 92 | plotted graph example 93 | 94 | ------------------------------------------------------------------------------------------------------------ 95 | 96 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | dependency.graph.osgi 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.release=disabled 6 | org.eclipse.jdt.core.compiler.source=1.8 7 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/pom.xml: -------------------------------------------------------------------------------- 1 | 9 | 12 | 4.0.0 13 | com.amitinside 14 | dependency.graph.osgi 15 | 0.0.1-SNAPSHOT 16 | jar 17 | Dependency Graph in OSGi 18 | 19 | 20 | 1.8 21 | UTF-8 22 | UTF-8 23 | 3.7.0 24 | 1.3 25 | 2.7 26 | 3.0 27 | 4.0.0 28 | 1.6.4 29 | 1.2.0 30 | 23.0 31 | 3.1.0 32 | 1.4 33 | 34 | 35 | 36 | 37 | org.graphstream 38 | gs-core 39 | ${graphstream.version} 40 | 41 | 42 | org.graphstream 43 | gs-ui 44 | ${graphstream.version} 45 | 46 | 47 | biz.aQute.bnd 48 | biz.aQute.bndlib 49 | ${bnd.version} 50 | 51 | 52 | commons-io 53 | commons-io 54 | ${commons.io.version} 55 | 56 | 57 | org.apache.commons 58 | commons-lang3 59 | ${commons.lang.version} 60 | 61 | 62 | org.slf4j 63 | slf4j-api 64 | ${slf4j.version} 65 | 66 | 67 | ch.qos.logback 68 | logback-classic 69 | ${logback.version} 70 | 71 | 72 | ch.qos.logback 73 | logback-core 74 | ${logback.version} 75 | 76 | 77 | biz.aQute.bnd 78 | biz.aQute.resolve 79 | ${bnd.version} 80 | 81 | 82 | biz.aQute.bnd 83 | biz.aQute.repository 84 | ${bnd.version} 85 | 86 | 87 | com.google.guava 88 | guava 89 | ${guava.version} 90 | 91 | 92 | commons-cli 93 | commons-cli 94 | ${commons.cli.version} 95 | 96 | 97 | 98 | 99 | 100 | 101 | maven-compiler-plugin 102 | ${compiler.plugin.version} 103 | 104 | ${project.java.version} 105 | ${project.java.version} 106 | ${project.build.sourceEncoding} 107 | -proc:none 108 | 109 | 110 | 111 | org.apache.maven.plugins 112 | maven-assembly-plugin 113 | ${maven.assembly.plugin.version} 114 | 115 | 116 | package 117 | 118 | single 119 | 120 | 121 | 122 | 123 | 124 | com.amitinside.dependency.graph.osgi.cli.Application 125 | 126 | 127 | 128 | 129 | jar-with-dependencies 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/DependencyGraph.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi; 11 | 12 | import java.awt.Dimension; 13 | import java.awt.Toolkit; 14 | import java.awt.Window; 15 | import java.util.UUID; 16 | 17 | import javax.swing.JFrame; 18 | import javax.swing.SwingUtilities; 19 | 20 | import org.graphstream.graph.Edge; 21 | import org.graphstream.graph.Graph; 22 | import org.graphstream.graph.Node; 23 | import org.graphstream.graph.implementations.Graphs; 24 | import org.graphstream.graph.implementations.MultiGraph; 25 | import org.graphstream.ui.swingViewer.ViewPanel; 26 | import org.graphstream.ui.view.Viewer; 27 | 28 | public final class DependencyGraph { 29 | 30 | private static final int MAX_LENGTH_FOR_SHORTENING = 15; 31 | private final Graph graph; 32 | 33 | public DependencyGraph(final String name) { 34 | System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); 35 | 36 | graph = Graphs.synchronizedGraph(new MultiGraph(name)); 37 | graph.addAttribute("ui.quality"); 38 | } 39 | 40 | public void addBaseNode(final String bsn) { 41 | addNode(bsn, true); 42 | } 43 | 44 | public void addNode(final String bsn) { 45 | addNode(bsn, false); 46 | } 47 | 48 | public void addNode(final String bsn, final boolean isBase) { 49 | final String shortenedBSN = shortenBSN(bsn); 50 | final Node node = graph.addNode(shortenedBSN); 51 | if (!isBase) { 52 | node.addAttribute("ui.style", 53 | "text-alignment: under; text-color: white; text-style: bold; text-background-mode: rounded-box; text-background-color: #222C; text-padding: 5px, 4px; text-offset: 0px, 5px; "); 54 | } else { 55 | node.addAttribute("ui.style", 56 | "text-alignment: under; text-color: white; text-style: bold; text-background-mode: rounded-box; text-background-color: red; text-padding: 5px, 4px; text-offset: 0px, 5px; "); 57 | } 58 | 59 | node.addAttribute("ui.label", shortenedBSN); 60 | node.addAttribute("ui.quality"); 61 | node.addAttribute("ui.antialias"); 62 | } 63 | 64 | public void removeNode(final String bsn) { 65 | graph.removeNode(shortenBSN(bsn)); 66 | } 67 | 68 | public void addEdge(final String source, final String dependsOn, final String edgeLabel, final boolean showLabel) { 69 | final Edge edge = graph.addEdge(UUID.randomUUID().toString(), shortenBSN(source), shortenBSN(dependsOn), true); 70 | edge.addAttribute("ui.style", "shape: freeplane;"); 71 | if (showLabel) { 72 | edge.addAttribute("ui.label", edgeLabel); 73 | } 74 | } 75 | 76 | public void addEdge(final String source, final String dependsOn, final String edgeLabel) { 77 | addEdge(source, dependsOn, edgeLabel, true); 78 | } 79 | 80 | public void addEdge(final String source, final String dependsOn) { 81 | addEdge(source, dependsOn, null, false); 82 | } 83 | 84 | public boolean hasNode(final String bsn) { 85 | return graph.getNode(shortenBSN(bsn)) != null; 86 | } 87 | 88 | public boolean hasEdgeBetween(final String bsn1, final String bsn2) { 89 | return graph.getNode(shortenBSN(bsn1)).hasEdgeBetween(shortenBSN(bsn2)); 90 | } 91 | 92 | public void display() { 93 | final Viewer viewer = graph.display(); 94 | final ViewPanel panel = viewer.getDefaultView(); 95 | viewer.enableAutoLayout(); 96 | final JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(panel); 97 | topFrame.setTitle("Dependency Graph in OSGi"); 98 | topFrame.setSize(Toolkit.getDefaultToolkit().getScreenSize()); 99 | centreWindow(topFrame); 100 | } 101 | 102 | public boolean isEmpty() { 103 | return graph.getNodeSet().isEmpty(); 104 | } 105 | 106 | public int getNodeCount() { 107 | return graph.getNodeCount(); 108 | } 109 | 110 | public Graph internal() { 111 | return graph; 112 | } 113 | 114 | private String shortenBSN(final String bsn) { 115 | if (bsn.length() > MAX_LENGTH_FOR_SHORTENING && bsn.indexOf('.') != -1) { 116 | final String[] parts = bsn.split("\\."); 117 | if (parts.length > 2) { 118 | final StringBuilder builder = new StringBuilder(); 119 | builder.append(parts[0].charAt(0)); 120 | builder.append("."); 121 | builder.append(parts[1].charAt(0)); 122 | builder.append("."); 123 | for (int i = 2; i < parts.length; i++) { 124 | builder.append(parts[i]); 125 | if (i != parts.length - 1) { 126 | builder.append("."); 127 | } 128 | } 129 | return builder.toString(); 130 | } 131 | } 132 | return bsn; 133 | } 134 | 135 | private void centreWindow(final Window frame) { 136 | final Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); 137 | final int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2); 138 | final int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2); 139 | frame.setLocation(x, y); 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/GraphConfigurer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi; 11 | 12 | import static java.nio.charset.StandardCharsets.UTF_8; 13 | import static java.util.stream.Collectors.toSet; 14 | import static org.slf4j.Logger.ROOT_LOGGER_NAME; 15 | 16 | import java.net.URI; 17 | import java.util.Collections; 18 | import java.util.List; 19 | import java.util.Set; 20 | import java.util.function.Predicate; 21 | 22 | import org.apache.commons.io.FileUtils; 23 | import org.apache.commons.lang3.StringUtils; 24 | import org.osgi.resource.Capability; 25 | import org.osgi.resource.Resource; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import com.amitinside.dependency.graph.osgi.algo.CycleDetection; 29 | import com.amitinside.dependency.graph.osgi.cli.CliConfiguration; 30 | import com.amitinside.dependency.graph.osgi.util.Helper; 31 | import com.google.common.collect.Lists; 32 | import com.google.common.collect.Sets; 33 | 34 | import aQute.bnd.osgi.repository.ResourcesRepository; 35 | import aQute.bnd.osgi.repository.XMLResourceParser; 36 | import aQute.bnd.osgi.resource.ResourceUtils; 37 | import aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability; 38 | import ch.qos.logback.classic.Level; 39 | import ch.qos.logback.classic.Logger; 40 | 41 | public final class GraphConfigurer { 42 | 43 | private final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME); 44 | 45 | private final DependencyGraph dependencyGraph; 46 | private final CliConfiguration cliConfiguration; 47 | 48 | public GraphConfigurer(final CliConfiguration cliConfiguration) { 49 | dependencyGraph = new DependencyGraph("OSGi Dependency Graph"); 50 | this.cliConfiguration = cliConfiguration; 51 | 52 | if (cliConfiguration.isDebug) { 53 | logger.setLevel(Level.DEBUG); 54 | } 55 | } 56 | 57 | public void init() throws Exception { 58 | final List bundles = FileUtils.readLines(cliConfiguration.bundles, UTF_8); 59 | final ResourcesRepository repo = getRepository(cliConfiguration.obrIndex.toURI()); 60 | 61 | if (repo == null) { 62 | logger.info("Invalid OBR XML"); 63 | return; 64 | } 65 | final Set bundlesToPlot = matchWildCards(bundles, repo); 66 | 67 | if (bundlesToPlot.isEmpty()) { 68 | logger.info("No Element to plot on the Graph"); 69 | return; 70 | } 71 | // plot all base nodes 72 | bundlesToPlot.forEach(dependencyGraph::addBaseNode); 73 | 74 | for (final String bundle : bundlesToPlot) { 75 | if (!bundle.trim().isEmpty()) { 76 | //@formatter:off 77 | final Resource resource = repo.getResources() 78 | .stream() 79 | .filter(r -> bundle.equals(getBSN(r))) 80 | .findFirst() 81 | .orElse(null); 82 | //@formatter:on 83 | if (resource == null) { 84 | logger.info("Bundle with BSN [{}] not found", bundle); 85 | continue; 86 | } 87 | final List requiredResources = getResourcesRequiredBy(repo, resource); 88 | prepareGraph(dependencyGraph, resource, requiredResources, cliConfiguration.showEdgeLabel); 89 | } 90 | } 91 | if (dependencyGraph.isEmpty()) { 92 | logger.info("No Element to plot on the Graph"); 93 | return; 94 | } 95 | if (cliConfiguration.checkCycle) { 96 | final CycleDetection cycleFinderAlgo = new CycleDetection(cliConfiguration.isDebug); 97 | cycleFinderAlgo.init(dependencyGraph.internal()); 98 | cycleFinderAlgo.compute(); 99 | logger.info("Existence of Cycle => {}", cycleFinderAlgo.hasCycle()); 100 | } 101 | dependencyGraph.display(); 102 | } 103 | 104 | private ResourcesRepository getRepository(final URI uri) throws Exception { 105 | List resources = null; 106 | try { 107 | resources = XMLResourceParser.getResources(uri); 108 | } catch (final Exception e) { 109 | return null; 110 | } 111 | return new ResourcesRepository(resources); 112 | } 113 | 114 | private String getBSN(final Resource resource) { 115 | final IdentityCapability identity = ResourceUtils.getIdentityCapability(resource); 116 | return identity.getAttributes().get("osgi.identity").toString(); 117 | } 118 | 119 | private List getResourcesRequiredBy(final ResourcesRepository repo, final Resource resource) { 120 | logger.debug("OSGi Resource to search => {} ", resource); 121 | if (resource == null) { 122 | return Collections.emptyList(); 123 | } 124 | final List resources = Lists.newArrayList(); 125 | resource.getRequirements(null).forEach(r -> { 126 | logger.debug("Resource Requirement => {}", r); 127 | final List capabilities = repo.findProvider(r); 128 | final Set requiredResources = ResourceUtils.getResources(capabilities); 129 | logger.debug("Resources providing the Requirement => {}", requiredResources); 130 | final ResourceInfo rInfo = new ResourceInfo(); 131 | rInfo.requirement = r; 132 | rInfo.requiredResources = requiredResources; 133 | resources.add(rInfo); 134 | }); 135 | return resources; 136 | } 137 | 138 | private void prepareGraph(final DependencyGraph dependencyGraph, final Resource resource, 139 | final List requiredResources, final boolean showEdgeLabel) { 140 | if (resource == null) { 141 | return; 142 | } 143 | final String bsn = getBSN(resource); 144 | 145 | // sorting is required since osgi.wiring.package has least priority. That is, if a bundle A uses a service 146 | // from another bundle B, A not only has osgi.service requirement to B, it also has osgi.wiring.package 147 | // requirement to B. And if osgi.service is already found, we don't need to show the osgi.wiring.package 148 | // requirement on the graph since it is a default requirement in this case 149 | Collections.sort(requiredResources); 150 | 151 | requiredResources.stream().filter(this::checkNamespace).forEach(r -> r.requiredResources.forEach(res -> { 152 | final String rbsn = getBSN(res); 153 | if (!dependencyGraph.hasNode(rbsn)) { 154 | dependencyGraph.addNode(rbsn); 155 | } 156 | final String edgeLabel = StringUtils.substringAfterLast(r.requirement.getNamespace(), "."); 157 | if (!dependencyGraph.hasEdgeBetween(bsn, rbsn) && !bsn.equalsIgnoreCase(rbsn)) { 158 | if (showEdgeLabel) { 159 | dependencyGraph.addEdge(bsn, rbsn, edgeLabel); 160 | } else { 161 | dependencyGraph.addEdge(bsn, rbsn); 162 | } 163 | } 164 | })); 165 | } 166 | 167 | private boolean checkNamespace(final ResourceInfo r) { 168 | switch (cliConfiguration.namespace) { 169 | case ALL: 170 | return true; 171 | case CUSTOM: 172 | return cliConfiguration.customNamespace.equals(r.requirement.getNamespace()); 173 | default: 174 | return cliConfiguration.namespace.ns().equals(r.requirement.getNamespace()); 175 | } 176 | } 177 | 178 | private Set matchWildCards(final List input, final ResourcesRepository repo) { 179 | final Predicate hasWildcardInclusion = e -> (e.endsWith("*") || e.endsWith("?")) 180 | && !e.startsWith("!"); 181 | final Predicate hasExclusion = e -> e.startsWith("!"); 182 | 183 | final Set wildcardEntriesInclusion = input.stream().filter(hasWildcardInclusion).collect(toSet()); 184 | final Set entriesExclusion = input.stream().filter(hasExclusion).collect(toSet()); 185 | 186 | final Set bundles = Sets.newHashSet(input); 187 | bundles.removeAll(wildcardEntriesInclusion); 188 | bundles.removeAll(entriesExclusion); 189 | 190 | for (final String wildcardEntry : wildcardEntriesInclusion) { 191 | for (final Resource resource : repo.getResources()) { 192 | final String bsn = getBSN(resource); 193 | if (Helper.isMatch(bsn, wildcardEntry)) { 194 | bundles.add(bsn); 195 | } 196 | } 197 | } 198 | for (final String wildcardEntry : entriesExclusion) { 199 | final String entry = wildcardEntry.substring(1, wildcardEntry.length()); 200 | for (final Resource resource : repo.getResources()) { 201 | final String bsn = getBSN(resource); 202 | if (Helper.isMatch(bsn, entry)) { 203 | bundles.remove(bsn); 204 | } 205 | } 206 | } 207 | return bundles; 208 | } 209 | 210 | } 211 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/ResourceInfo.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi; 11 | 12 | import java.util.Set; 13 | 14 | import org.apache.commons.lang3.builder.EqualsBuilder; 15 | import org.apache.commons.lang3.builder.HashCodeBuilder; 16 | import org.apache.commons.lang3.builder.ToStringBuilder; 17 | import org.osgi.resource.Requirement; 18 | import org.osgi.resource.Resource; 19 | 20 | import com.google.common.collect.ComparisonChain; 21 | 22 | public final class ResourceInfo implements Comparable { 23 | 24 | public Requirement requirement; 25 | public Set requiredResources; 26 | 27 | @Override 28 | public int compareTo(final ResourceInfo o) { 29 | return ComparisonChain.start().compare(requirement.getNamespace(), o.requirement.getNamespace()).result(); 30 | } 31 | 32 | @Override 33 | public boolean equals(final Object other) { 34 | if (!(other instanceof ResourceInfo)) { 35 | return false; 36 | } 37 | final ResourceInfo castOther = (ResourceInfo) other; 38 | return new EqualsBuilder().append(requirement, castOther.requirement) 39 | .append(requiredResources, castOther.requiredResources).isEquals(); 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | return new HashCodeBuilder().append(requirement).append(requiredResources).toHashCode(); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return new ToStringBuilder(this).append("requirement", requirement) 50 | .append("requiredResources", requiredResources).toString(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/algo/CycleDetection.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi.algo; 11 | 12 | import java.util.List; 13 | import java.util.Set; 14 | 15 | import org.graphstream.algorithm.Algorithm; 16 | import org.graphstream.algorithm.TarjanStronglyConnectedComponents; 17 | import org.graphstream.graph.Graph; 18 | import org.graphstream.graph.Node; 19 | 20 | import com.google.common.collect.Lists; 21 | import com.google.common.collect.Sets; 22 | 23 | public final class CycleDetection implements Algorithm { 24 | 25 | private final boolean debug; 26 | private Graph graph; 27 | private TarjanStronglyConnectedComponents tscc; 28 | private boolean hasCycle; 29 | 30 | public CycleDetection(final boolean debug) { 31 | this.debug = debug; 32 | } 33 | 34 | @Override 35 | public void init(final Graph graph) { 36 | this.graph = graph; 37 | tscc = new TarjanStronglyConnectedComponents(); 38 | tscc.init(graph); 39 | } 40 | 41 | @Override 42 | public void compute() { 43 | tscc.compute(); 44 | final List sccIndices = Lists.newArrayList(); 45 | for (final Node n : graph.getEachNode()) { 46 | final Integer attribute = n.getAttribute(tscc.getSCCIndexAttribute(), Integer.class); 47 | if (debug) { 48 | n.addAttribute("label", attribute); 49 | } 50 | sccIndices.add(attribute); 51 | } 52 | final Set set = Sets.newHashSet(sccIndices); 53 | hasCycle = sccIndices.size() != set.size(); 54 | } 55 | 56 | public boolean hasCycle() { 57 | return hasCycle; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/cli/Application.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi.cli; 11 | 12 | import static ch.qos.logback.classic.Level.DEBUG; 13 | import static ch.qos.logback.classic.Level.INFO; 14 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.BUNDLE_FILE; 15 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.CYCLE; 16 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.HELP_1; 17 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.HELP_2; 18 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.IS_DEBUG; 19 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.NAMESPACE; 20 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.NAMESPACE_CUSTOM; 21 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.OBR_FILE; 22 | import static com.amitinside.dependency.graph.osgi.cli.CliOptions.SHOW_EDGE; 23 | import static com.amitinside.dependency.graph.osgi.cli.Namespace.ALL; 24 | import static com.amitinside.dependency.graph.osgi.cli.Namespace.CUSTOM; 25 | import static org.slf4j.Logger.ROOT_LOGGER_NAME; 26 | 27 | import java.io.File; 28 | 29 | import org.apache.commons.cli.CommandLine; 30 | import org.apache.commons.cli.CommandLineParser; 31 | import org.apache.commons.cli.DefaultParser; 32 | import org.apache.commons.cli.HelpFormatter; 33 | import org.apache.commons.cli.Options; 34 | import org.apache.commons.cli.ParseException; 35 | import org.slf4j.LoggerFactory; 36 | 37 | import com.amitinside.dependency.graph.osgi.GraphConfigurer; 38 | import com.google.common.base.Enums; 39 | import com.google.common.base.Optional; 40 | import com.google.common.collect.Lists; 41 | 42 | import aQute.lib.io.IO; 43 | import ch.qos.logback.classic.Logger; 44 | 45 | public final class Application { 46 | 47 | private static final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME); 48 | 49 | static { 50 | logger.setLevel(INFO); 51 | } 52 | 53 | public static void main(final String... args) throws Exception { 54 | boolean showEdgeLabel = false; 55 | boolean cycle = false; 56 | boolean isDebug = false; 57 | Namespace namespace = ALL; 58 | String customNamespace = null; 59 | 60 | final CommandLineParser parser = new DefaultParser(); 61 | final Options options = new Options(); 62 | 63 | addOptions(options); 64 | 65 | String obrIndexFile = null; 66 | String bundleListFile = null; 67 | try { 68 | final CommandLine line = parser.parse(options, args); 69 | if (line.getOptions().length == 0) { 70 | throw new ParseException("No Option Provided"); 71 | } 72 | if (line.hasOption(HELP_1) || line.hasOption(HELP_2)) { 73 | printHelp(options); 74 | return; 75 | } 76 | if (!line.hasOption(OBR_FILE)) { 77 | throw new ParseException("OBR Index File is missing"); 78 | } 79 | if (!line.hasOption(BUNDLE_FILE)) { 80 | throw new ParseException("Bundle List File is missing"); 81 | } 82 | if (line.hasOption(SHOW_EDGE)) { 83 | showEdgeLabel = true; 84 | } 85 | if (line.hasOption(IS_DEBUG)) { 86 | isDebug = true; 87 | } 88 | if (line.hasOption(CYCLE)) { 89 | cycle = true; 90 | } 91 | if (line.hasOption(NAMESPACE)) { 92 | final Optional optType = Enums.getIfPresent(Namespace.class, line.getOptionValue(NAMESPACE)); 93 | if (!optType.isPresent()) { 94 | throw new ParseException("Namespace Invalid"); 95 | } 96 | namespace = optType.get(); 97 | if (namespace == CUSTOM) { 98 | if (!line.hasOption(NAMESPACE_CUSTOM)) { 99 | throw new ParseException("Custom namespace option must be set if ns is set to CUSTOM"); 100 | } 101 | customNamespace = line.getOptionValue(NAMESPACE_CUSTOM); 102 | } 103 | } 104 | obrIndexFile = line.getOptionValue(OBR_FILE); 105 | bundleListFile = line.getOptionValue(BUNDLE_FILE); 106 | } catch (final ParseException exp) { 107 | logger.info(exp.getMessage()); 108 | printHelp(options); 109 | System.exit(-1); 110 | } 111 | 112 | final File obrIndex = IO.getFile(obrIndexFile); 113 | if (!obrIndex.exists()) { 114 | logger.info("No OBR Index Found"); 115 | System.exit(-1); 116 | } 117 | 118 | final File bundlesFile = IO.getFile(bundleListFile); 119 | if (!bundlesFile.exists()) { 120 | logger.info("No Bundle List Found"); 121 | System.exit(-1); 122 | } 123 | 124 | final CliConfiguration config = new CliConfiguration(); 125 | config.isDebug = isDebug; 126 | config.bundles = bundlesFile; 127 | config.obrIndex = obrIndex; 128 | config.checkCycle = cycle; 129 | config.namespace = namespace; 130 | config.showEdgeLabel = showEdgeLabel; 131 | config.customNamespace = customNamespace; 132 | 133 | if (isDebug) { 134 | logger.setLevel(DEBUG); 135 | } 136 | 137 | logger.debug("CLI Configuration => {} ", config); 138 | 139 | final GraphConfigurer configurer = new GraphConfigurer(config); 140 | configurer.init(); 141 | } 142 | 143 | private static void addOptions(final Options options) { 144 | options.addOption(HELP_1, false, "Show Help"); 145 | options.addOption(HELP_2, false, "Show Help"); 146 | options.addOption(OBR_FILE, true, "OBR Index File Location"); 147 | options.addOption(BUNDLE_FILE, true, "Bundle List File Location"); 148 | options.addOption(SHOW_EDGE, false, "Show Edge Labels"); 149 | options.addOption(IS_DEBUG, false, "Turn on Debug Mode"); 150 | options.addOption(CYCLE, false, "Check for Cycle Existence"); 151 | final String description = "Namespace Type to Plot " + Lists.newArrayList(Namespace.values()) 152 | + " (Default ALL)"; 153 | options.addOption(NAMESPACE, true, description); 154 | options.addOption(NAMESPACE_CUSTOM, true, "Custom Namespace (Needs to be set if ns option is set to CUSTOM"); 155 | } 156 | 157 | private static void printHelp(final Options options) { 158 | final HelpFormatter formatter = new HelpFormatter(); 159 | formatter.printHelp("Dependency Graph in OSGi - Help", options); 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/cli/CliConfiguration.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi.cli; 11 | 12 | import java.io.File; 13 | 14 | import aQute.bnd.util.dto.DTO; 15 | 16 | public final class CliConfiguration extends DTO { 17 | 18 | public File obrIndex; 19 | public File bundles; 20 | public Namespace namespace; 21 | public String customNamespace; 22 | public boolean isDebug; 23 | public boolean checkCycle; 24 | public boolean showEdgeLabel; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/cli/CliOptions.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi.cli; 11 | 12 | public final class CliOptions { 13 | 14 | private CliOptions() { 15 | throw new IllegalAccessError("Cannot instantiate"); 16 | } 17 | 18 | public static final String HELP_1 = "?"; 19 | public static final String HELP_2 = "help"; 20 | public static final String OBR_FILE = "obr"; 21 | public static final String BUNDLE_FILE = "bundles"; 22 | public static final String SHOW_EDGE = "edge"; 23 | public static final String IS_DEBUG = "debug"; 24 | public static final String CYCLE = "cycle"; 25 | public static final String NAMESPACE = "ns"; 26 | public static final String NAMESPACE_CUSTOM = "ns_custom"; 27 | } 28 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/cli/Namespace.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi.cli; 11 | 12 | public enum Namespace { 13 | ALL("ALL"), 14 | PACKAGE("osgi.wiring.package"), 15 | SERVICE("osgi.service"), 16 | IDENTITY("osgi.identity"), 17 | EE("osgi.ee"), 18 | NATIVE("osgi.native"), 19 | CONTENT("osgi.content"), 20 | IMPLEMENTATION("osgi.implementation"), 21 | CONTRACT("osgi.contract"), 22 | BUNDLE("osgi.wiring.bundle"), 23 | HOST("osgi.wiring.host"), 24 | CUSTOM("CUSTOM"); 25 | 26 | String ns; 27 | 28 | Namespace(final String ns) { 29 | this.ns = ns; 30 | } 31 | 32 | public String ns() { 33 | return ns; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /com.amitinside.dependency.graph.osgi/src/main/java/com/amitinside/dependency/graph/osgi/util/Helper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018 Amit Kumar Mondal 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License 2.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-2.0 8 | * 9 | *******************************************************************************/ 10 | package com.amitinside.dependency.graph.osgi.util; 11 | 12 | public final class Helper { 13 | 14 | private Helper() { 15 | throw new IllegalAccessError("Cannot instantiate"); 16 | } 17 | 18 | /** 19 | * Matches wildcard pattern with support for '?' and '*'. 20 | * '?' Matches any single character. 21 | * '*' Matches any sequence of characters (including the empty sequence). 22 | * The matching should cover the entire input string (not partial). 23 | * The function prototype should be: 24 | * bool isMatch(const char *s, const char *p) 25 | * Some examples: 26 | * isMatch("aa","a") → false 27 | * isMatch("aa","aa") → true 28 | * isMatch("aaa","aa") → false 29 | * isMatch("aa", "*") → true 30 | * isMatch("aa", "a*") → true 31 | * isMatch("ab", "?*") → true 32 | * isMatch("aab", "c*a*b") → false 33 | * 34 | * @param source source string to match 35 | * @param pattern pattern to match 36 | */ 37 | public static boolean isMatch(final String source, final String pattern) { 38 | final int lenS = source.length(); 39 | final int lenP = pattern.length(); 40 | if (lenS == 0 && lenP == 0) { 41 | return true; 42 | } 43 | int i = 0; 44 | int j = 0; 45 | // save the last matched index 46 | int startS = -1; 47 | int startP = -1; 48 | while (i < lenS) { 49 | if (j < lenP && (source.charAt(i) == pattern.charAt(j) || pattern.charAt(j) == '?')) { 50 | i++; 51 | j++; 52 | } else if (j < lenP && pattern.charAt(j) == '*') { 53 | while (j < lenP && pattern.charAt(j) == '*') { 54 | j++; 55 | } 56 | if (j == lenP) { 57 | return true; 58 | } 59 | startP = j; 60 | startS = i; 61 | } else if ((j >= lenP || source.charAt(i) != pattern.charAt(j)) && startP > -1) { 62 | startS++; 63 | j = startP; 64 | i = startS; 65 | } else { 66 | return false; 67 | } 68 | } 69 | while (j < lenP) { 70 | if (pattern.charAt(j) != '*') { 71 | return false; 72 | } 73 | j++; 74 | } 75 | return true; 76 | } 77 | } --------------------------------------------------------------------------------