1 #+TITLE: JavaInspect - Utility to visualize java software
4 - [[http://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=snapshot;h=HEAD;sf=tgz][download latest snapshot]]
6 - This program is free software; you can redistribute it and/or modify
7 it under the terms of version 3 of the [[https://www.gnu.org/licenses/lgpl.html][GNU Lesser General Public
8 License]] or later as published by the Free Software Foundation.
12 - Homepage: http://svjatoslav.eu
13 - Email: mailto://svjatoslav@svjatoslav.eu
15 - [[http://svjatoslav.eu/programs.jsp][other applications hosted at svjatoslav.eu]]
18 Goal: simplify/speed up understanding the computer program code by
19 automatically visualizing its structure.
21 JavaInspect is a Java library that primarily uses Java reflection to
22 discover and visualize any part of Java program provided that
23 classes to be visualised are available in the classpath.
25 JavaInspect currently has no GUI, configuration files, embedded
26 scripting support, direct Maven or Ant integration. The only way to
27 instuct Javainspect what to do is by using its Java API.
29 To get JavaInspect into same classpath with your projecs I so far came
32 1. Add JavaInspect library in your project as a dependency.
33 2. Create new Java project for the purpose visualizing your other
34 projects and include JavaInspect and your projecs binary artifacts
35 (Jar's) into new project classpath. Built binary Jar's (with no
36 source code) are sufficient because JavaInspect operates via
39 After discovering application structure and optionally filtering out
40 unimportant parts, JavaInspect produces GraphViz dot file that
41 describes data to be visualized. Then launches GraphViz to generate
42 bitmap graph in PNG format. By default on your Desktop directory.
44 Note: GraphViz is developed and tested so far only on GNU Linux.
47 + A very simple example:
49 [[file:example.png][file:example.resized.png]]
55 + Example visualization of [[http://www2.svjatoslav.eu/gitbrowse/sixth/doc/][Sixth]] project: [[http://www2.svjatoslav.eu/projects/sixth/codegraphs/][architecture graphs]].
58 Currently the only way to control JavaInspect is by using Java
59 API. Simple Java based control/configuration code needs to be written
60 for each project. I usually put such code into directories devoted for
61 JUnit tests. Because it needs not to be compiled/embedded into final
62 product or project artifact I'm just willing to visualize.
64 Control code in general does the following:
65 1. Create graph object.
66 2. Java reflection/classloaders does not provide mechanism for
67 discovering all classes under given package. Therefore you need to
68 declare at least some classes to be added to the graph by:
69 + Manually adding individual classes to the graph.
70 + and/or: Let GraphViz recursively scan and parse specified
71 directories with Java source code files to discover class names.
72 + For every class added to the graph, GraphViz will recursively
73 inspect it and add all referecned classes to the graph as well.
74 3. Graphs easilly get very big and complex so optionally we filter
75 important code using classname wildcards patterns based blacklist
77 4. Optionally we can tune some rendering parameters like:
78 + Possibility to remove orphaned classes (classes with no
79 references) from the graph.
80 + Specify target directory for generated visualization
81 files. (Default is user desktop directory)
82 + Keep intermediate GraphViz dot file for later inspection.
86 ** example 1: individually picked objects
87 This example demonstrates generating of class graph from hand picked
88 classes and visualizing GraphViz itself.
93 final ClassGraph graph = new ClassGraph();
95 // Add some random object to the graph. GraphViz will detect Class from
99 // Also add some random class to the graph.
100 graph.add(Utils.class);
102 // Keep intermediary GraphViz DOT file for reference.
103 graph.setKeepDotFile(true);
105 // Produce bitmap image titled "JavaInspect.png" to the user Desktop
107 graph.generateGraph("JavaInspect");
111 Note: if desired, more compact version of the above:
113 new ClassGraph().add(randomObject, RandomClass.class)
114 .setKeepDotFile(true).generateGraph("JavaInspect");
119 - Generated DOT file: [[file:JavaInspect.dot][JavaInspect.dot]]
120 - Generated PNG image: [[file:JavaInspect.png][JavaInspect.png]]
122 ** example 2: scan java code, apply filters
125 final ClassGraph graph = new ClassGraph();
127 // Recursively scan current directory for Java source code and attempt
128 // to detect class names from there to be added to the graph.
129 graph.addProject(".");
131 // Blacklist example classes from being shown on the graph
132 graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
134 // do not show single classes with no relationships on the graph
135 graph.hideOrphanedClasses();
137 // Produce bitmap image titled "JavaInspect full project.png" to the
138 // user Desktop directory.
139 graph.generateGraph("JavaInspect full project");
142 - Generated PNG image: [[file:JavaInspect%20full%20project.png][JavaInspect full project.png]]
144 ** example 3: GraphViz embedded in another project
145 1. Download project Sixth [[http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz][code snapshot]].
146 2. Inspect and run *DataGraph.java*.
148 * Embedding JavaInspect in your Maven project
150 Declare JavaInspect as dependency:
155 <groupId>eu.svjatoslav</groupId>
156 <artifactId>javainspect</artifactId>
157 <version>1.5-SNAPSHOT</version>
164 Add Maven repository to retrieve artifact from:
169 <id>svjatoslav.eu</id>
170 <name>Svjatoslav repository</name>
171 <url>http://www2.svjatoslav.eu/maven/</url>
178 [[http://www.graphviz.org/][GraphViz]] - shall be installed on the computer.
180 On Ubuntu/Debian use:
182 sudo apt-get install graphviz
185 - BUG: Should not hide references if there are too many of them to
186 classes if referring classes are not visible anyway because of
187 blacklist/whitelist rules. Basically reference counting should
188 exclude not visible classes.
189 - FEATURE: add dark theme
190 - FEATURE: sort Class fields by alphabet
191 - FEATURE: visualize also concrete field values so it could be used as
192 ultra cool runtime logging framework
193 - FEATURE: possibility to visualize structure and data from JVM
195 - FEATURE: possibility to attach to remote process to visualize
196 data/structure using JVM debug port and mechanism.
197 - FEATURE: possibility to attach to JVM using JVM agent
198 - FEATURE: possibility to script javainspect behavior
199 - FEATURE: possibility to select classes/fields/values to be
200 visualized in SQL like syntax
201 - FEATURE: configurable maven plugin to generate graphs as part of the
202 project build/release process