-JavaInspect utility can be used in 2 different ways:
-+ [[id:acf1896a-74b4-4914-acf6-a77075e07f25][As standalone commandline utility]]
-+ [[id:bbeeffc8-3767-440d-8d93-ec9124dd60ee][As embedded Java library via Java API]]
-
-** Usage via Java API
-:PROPERTIES:
-:ID: bbeeffc8-3767-440d-8d93-ec9124dd60ee
-:CUSTOM_ID: usage-via-java-api
-:END:
-Requires that classes to be visualised are available in the classpath.
-
-To get JavaInspect into same classpath with your projecs I so far came
-up with 2 solutions:
-
-1. Add JavaInspect library in your project as a dependency.
-
-2. Create new Java project for the purpose visualizing your other
- projects and include JavaInspect and your projecs binary artifacts
- (Jar's) into new project classpath. Built binary Jar's (with no
- source code) are sufficient because JavaInspect operates via
- reflection.
-
-Simple Java based control/configuration code needs to be written for
-each project. I usually put such code into directories devoted for
-JUnit tests. Because it needs not to be compiled/embedded into final
-product or project artifact I'm just willing to visualize.
-
-Control code in general does the following:
-1. Create graph object.
-2. Java reflection/classloaders does not provide mechanism for
- discovering all classes under given package. Therefore you need to
- declare at least some classes to be added to the graph by manually
- adding individual classes to the graph. For every class added to
- the graph, GraphViz will recursively inspect it and add all
- referecned classes to the graph as well.
-3. Graphs easilly get very big and complex so optionally we filter
- important code using classname [[https://en.wikipedia.org/wiki/Glob_(programming)][glob]] patterns based blacklist and/or
- whitelist.
-4. Optionally we can tune some rendering parameters like:
- + Possibility to remove orphaned classes (classes with no
- references) from the graph.
- + Specify target directory for generated visualization
- files. (Default is current directory)
- + Keep intermediate GraphViz dot file for later inspection.
-5. Render graph.
-
-
-*** Example 1: individually picked objects
-:PROPERTIES:
-:CUSTOM_ID: example-1-individually-picked-objects
-:END:
-This example demonstrates generating of class graph from hand picked
-classes and visualizing GraphViz itself.
-
-#+BEGIN_SRC java
-
-// Create graph
-final ClassGraph graph = new ClassGraph();
-
-// Add some random object to the graph. GraphViz will detect Class from
-// the object.
-graph.add(graph);
-
-// Also add some random class to the graph.
-graph.add(Utils.class);
-
-// Keep intermediary GraphViz DOT file for reference.
-graph.setKeepDotFile(true);
-
-// Produce bitmap image titled "JavaInspect.png" to the user Desktop
-// directory
-graph.generateGraph("JavaInspect");
-
-#+END_SRC
-
-Note: if desired, more compact version of the above:
-#+BEGIN_SRC java
-new ClassGraph().add(randomObject, RandomClass.class)
- .setKeepDotFile(true).generateGraph("JavaInspect");
-#+END_SRC
-
-
-Result:
- - Generated DOT file: [[file:JavaInspect.dot][JavaInspect.dot]]
- - Generated PNG image: [[file:JavaInspect.png][JavaInspect.png]]
-
-*** Example 2: GraphViz embedded in another project
-:PROPERTIES:
-:CUSTOM_ID: example-2-graphviz-embedded-in-another-project
-:END:
-1. Download project Sixth [[https://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz][code snapshot]].
-2. Inspect and run *DataGraph.java*.
-
-*** Embedding JavaInspect in your Maven project
-:PROPERTIES:
-:CUSTOM_ID: embedding-javainspect-in-your-maven-project
-:END:
-
-Declare JavaInspect as dependency:
-#+BEGIN_SRC xml
-<dependencies>
- ...
- <dependency>
- <groupId>eu.svjatoslav</groupId>
- <artifactId>javainspect</artifactId>
- <version>1.7</version>
- </dependency>
- ...
-</dependencies>
-#+END_SRC
-
-
-Add Maven repository to retrieve artifact from:
-#+BEGIN_SRC xml
-<repositories>
- ...
- <repository>
- <id>svjatoslav.eu</id>
- <name>Svjatoslav repository</name>
- <url>https://www3.svjatoslav.eu/maven/</url>
- </repository>
- ...
-</repositories>
-#+END_SRC