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
16 - GitHub fork for the project:
17 https://github.com/abargnesi/javainspect
19 - [[http://www.svjatoslav.eu/programs.jsp][other applications hosted at svjatoslav.eu]]
21 * (document settings) :noexport:
22 ** use dark style for TWBS-HTML exporter
23 #+HTML_HEAD: <link href="https://bootswatch.com/4/darkly/bootstrap.min.css" rel="stylesheet">
24 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
25 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>"
26 #+HTML_HEAD: <style type="text/css">
27 #+HTML_HEAD: footer {background-color: #111 !important;}
28 #+HTML_HEAD: pre {background-color: #111; color: #ccc;}
32 Goal: simplify/speed up understanding the computer program code by
33 automatically visualizing its structure.
35 JavaInspect is a Java library/commandline utility that primarily uses
36 Java reflection to discover and visualize any part of Java program.
38 JavaInspect currently has no GUI, configuration files, embedded
39 scripting support, direct Maven or Ant integration. See [[id:2ad2889e-6c95-4662-b3f4-2c341fc74522][usage]] to learn
40 how to instuct Javainspect what to do.
42 After discovering application structure and optionally filtering out
43 unimportant parts, JavaInspect produces GraphViz dot file that
44 describes data to be visualized. Then launches GraphViz to generate
45 bitmap graph in PNG or SVG format.
47 By default on your Desktop directory when operated in library mode or
48 current working directory when operated as standalone commandline
51 Note: GraphViz is developed and tested so far only on GNU/Linux.
54 + A very simple example:
56 [[file:example.png][file:example.resized.png]]
62 + Example visualization of [[http://www2.svjatoslav.eu/gitbrowse/sixth-3d/doc/][Sixth 3D]] project: [[http://www2.svjatoslav.eu/gitbrowse/sixth-3d/doc/codeGraph/][architecture graphs]].
66 :ID: 2ad2889e-6c95-4662-b3f4-2c341fc74522
68 JavaInspect can be controlled in 2 different ways:
69 + [[id:acf1896a-74b4-4914-acf6-a77075e07f25][as standalone commandline utility]]
70 + [[id:bbeeffc8-3767-440d-8d93-ec9124dd60ee][as embedded Java library via Java API]]
72 ** usage as commandline utility
74 :ID: acf1896a-74b4-4914-acf6-a77075e07f25
76 To enable commandline support, (study and) execute script:
77 : commandline launcher/install
79 Warning: It was tested only on Debian Stretch linux.
81 Available commandline arguments:
83 -j (existing files)...
84 JAR file(s) to render.
86 -n (mandatory, string)
96 Hide orphaned classes.
98 -w (one to many strings)...
101 -b (one to many strings)...
104 -d (existingdirectory)
105 Target directory. Default is current directory.
107 -t (options: png, svg)
108 Target image type. Default is: svg.
110 ** usage via Java API
112 :ID: bbeeffc8-3767-440d-8d93-ec9124dd60ee
114 Requires that classes to be visualised are available in the classpath.
116 To get JavaInspect into same classpath with your projecs I so far came
119 1. Add JavaInspect library in your project as a dependency.
121 2. Create new Java project for the purpose visualizing your other
122 projects and include JavaInspect and your projecs binary artifacts
123 (Jar's) into new project classpath. Built binary Jar's (with no
124 source code) are sufficient because JavaInspect operates via
127 Simple Java based control/configuration code needs to be written for
128 each project. I usually put such code into directories devoted for
129 JUnit tests. Because it needs not to be compiled/embedded into final
130 product or project artifact I'm just willing to visualize.
132 Control code in general does the following:
133 1. Create graph object.
134 2. Java reflection/classloaders does not provide mechanism for
135 discovering all classes under given package. Therefore you need to
136 declare at least some classes to be added to the graph by:
137 + Manually adding individual classes to the graph.
138 + and/or: Let GraphViz recursively scan and parse specified
139 directories with Java source code files to discover class names.
140 + For every class added to the graph, GraphViz will recursively
141 inspect it and add all referecned classes to the graph as well.
142 3. Graphs easilly get very big and complex so optionally we filter
143 important code using classname wildcards patterns based blacklist
145 4. Optionally we can tune some rendering parameters like:
146 + Possibility to remove orphaned classes (classes with no
147 references) from the graph.
148 + Specify target directory for generated visualization
149 files. (Default is user desktop directory)
150 + Keep intermediate GraphViz dot file for later inspection.
154 *** example 1: individually picked objects
155 This example demonstrates generating of class graph from hand picked
156 classes and visualizing GraphViz itself.
161 final ClassGraph graph = new ClassGraph();
163 // Add some random object to the graph. GraphViz will detect Class from
167 // Also add some random class to the graph.
168 graph.add(Utils.class);
170 // Keep intermediary GraphViz DOT file for reference.
171 graph.setKeepDotFile(true);
173 // Produce bitmap image titled "JavaInspect.png" to the user Desktop
175 graph.generateGraph("JavaInspect");
179 Note: if desired, more compact version of the above:
181 new ClassGraph().add(randomObject, RandomClass.class)
182 .setKeepDotFile(true).generateGraph("JavaInspect");
187 - Generated DOT file: [[file:JavaInspect.dot][JavaInspect.dot]]
188 - Generated PNG image: [[file:JavaInspect.png][JavaInspect.png]]
190 *** example 2: scan java code, apply filters
193 final ClassGraph graph = new ClassGraph();
195 // Recursively scan current directory for Java source code and attempt
196 // to detect class names from there to be added to the graph.
197 graph.addProject(".");
199 // Blacklist example classes from being shown on the graph
200 graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
202 // do not show single classes with no relationships on the graph
203 graph.hideOrphanedClasses();
205 // Produce bitmap image titled "JavaInspect full project.png" to the
206 // user Desktop directory.
207 graph.generateGraph("JavaInspect full project");
210 - Generated PNG image: [[file:JavaInspect%20full%20project.png][JavaInspect full project.png]]
212 *** example 3: GraphViz embedded in another project
213 1. Download project Sixth [[http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz][code snapshot]].
214 2. Inspect and run *DataGraph.java*.
216 *** Embedding JavaInspect in your Maven project
218 Declare JavaInspect as dependency:
223 <groupId>eu.svjatoslav</groupId>
224 <artifactId>javainspect</artifactId>
225 <version>1.6</version>
232 Add Maven repository to retrieve artifact from:
237 <id>svjatoslav.eu</id>
238 <name>Svjatoslav repository</name>
239 <url>http://www2.svjatoslav.eu/maven/</url>
246 [[http://www.graphviz.org/][GraphViz]] - shall be installed on the computer.
248 On Ubuntu/Debian use:
250 sudo apt-get install graphviz
253 Note: Because this is side project (and I have many of them) I can
254 only contribute few hours per year at average. Any help is welcome. A
255 LOT of cool ideas could be implemented. For intstance:
257 - BUG: Should not hide references if there are too many of them to
258 classes if referring classes are not visible anyway because of
259 blacklist/whitelist rules. Basically reference counting should
260 exclude not visible classes.
262 - BUG: Orphaned class removal does not work always. There are many
263 bugs and corner cases to find and fix still.
265 - BUG: Code is not very readable. Document and refactor for better
268 - FEATURE: Create installable DEB package.
269 - Submit it to some Debian developer for integration or become
270 Debian package maintainer.
272 - FEATURE: Make it modular. That is: central part, an application
273 model could be standalone and serializable.
275 - There could be multiple ways to acquire model:
276 - By introspecting application via Java reflections (current mode
278 - By parsing java source. (unfinished)
280 - There could be ways to manipulate model:
281 - Store/load/compare.
282 - Trim uninteresting parts.
283 - Highlight important parts.
285 - There could be multiple ways to render model:
286 - PNG/SVG (currently implemented)
288 - Interactive 3D visualization (TODO)
290 - FEATURE: Replace internal java parser in package
291 eu.svjatoslav.inspector.java.methods with: https://javaparser.org/
293 - FEATURE: Integarte with [[http://plantuml.com/class-diagram][PlantUML]].
295 - FEATURE: Add dark theme for generated graphs.
297 - FEATURE: Sort Class fields by alphabet.
299 - FEATURE: Visualize also concrete field values so it could be used as
300 ultra cool runtime logging/debugging framework.
302 - FEATURE: Possibility to visualize structure and data from JVM
305 - FEATURE: Possibility to attach to remote process to visualize
306 data/structure using JVM debug port and mechanism.
308 - FEATURE: Possibility to attach to JVM using JVM agent.
310 - FEATURE: Possibility to inspect graphs in 3D using [[http://www2.svjatoslav.eu/gitbrowse/sixth-3d/doc/index.html][Sixth 3D engine]].
312 - FEATURE: Possibility to select classes/fields/values to be
313 visualized in some graph query language. For greater flexibility in
314 comparison to currently supported glob syntax.
316 - FEATURE: Add option to control JavaInspect via JSON or XML config
317 file. For example different graphs for given project could be
318 defined once in plain text config, possibly with the aid of some
319 interactive utility. Then defined graphs could be updated as part of
320 project build or release process.
322 - FEATURE: Configurable maven plugin to generate graphs as part of the
323 project build/release process.