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 [[http://www3.svjatoslav.eu/projects/sixth-3d/graphs/][See example produced graphs]] for [[http://www3.svjatoslav.eu/projects/sixth-3d/][Sixth 3D - 3D engine project]].
37 JavaInspect can be used as a [[id:acf1896a-74b4-4914-acf6-a77075e07f25][standalone commandline utility]] as well as
38 [[id:bbeeffc8-3767-440d-8d93-ec9124dd60ee][java library]]. JavaInspect uses primarily Java built-in reflection to
39 discover and visualize any part of Java program.
41 JavaInspect currently has no GUI, configuration files, embedded
42 scripting support, direct Maven or Ant integration. See [[id:2ad2889e-6c95-4662-b3f4-2c341fc74522][usage]] to learn
43 how to instuct Javainspect what to do.
45 After discovering application structure and optionally filtering out
46 unimportant parts, JavaInspect produces GraphViz dot file that
47 describes data to be visualized. Then launches GraphViz to generate
48 bitmap graph in PNG or SVG format.
50 By default on your Desktop directory when operated in library mode or
51 current working directory when operated as standalone commandline
55 + JavaInspect is developed and tested so far only on GNU/Linux.
56 + See: [[https://github.com/pahen/madge][Madge - similar tool for JavaScript]]
59 + A very simple example:
61 [[file:example.png][file:example.resized.png]]
67 + [[http://www3.svjatoslav.eu/projects/sixth-3d/graphs/][See example produced graphs]] for [[http://www3.svjatoslav.eu/projects/sixth-3d/][Sixth 3D - 3D engine project]].
71 :ID: 2ad2889e-6c95-4662-b3f4-2c341fc74522
73 JavaInspect can be controlled in 2 different ways:
74 + [[id:acf1896a-74b4-4914-acf6-a77075e07f25][as standalone commandline utility]]
75 + [[id:bbeeffc8-3767-440d-8d93-ec9124dd60ee][as embedded Java library via Java API]]
77 ** usage as commandline utility
79 :ID: acf1896a-74b4-4914-acf6-a77075e07f25
81 To enable commandline support, (study and) execute script:
82 : commandline launcher/install
84 Warning: It was tested only on Debian Stretch linux.
86 Available commandline arguments:
88 -j (existing files)...
89 JAR file(s) to render.
91 -n (mandatory, string)
101 Hide orphaned classes.
103 -w (one to many strings)...
106 -b (one to many strings)...
109 -d (existingdirectory)
110 Target directory. Default is current directory.
112 -t (options: png, svg)
113 Target image type. Default is: svg.
115 ** usage via Java API
117 :ID: bbeeffc8-3767-440d-8d93-ec9124dd60ee
119 Requires that classes to be visualised are available in the classpath.
121 To get JavaInspect into same classpath with your projecs I so far came
124 1. Add JavaInspect library in your project as a dependency.
126 2. Create new Java project for the purpose visualizing your other
127 projects and include JavaInspect and your projecs binary artifacts
128 (Jar's) into new project classpath. Built binary Jar's (with no
129 source code) are sufficient because JavaInspect operates via
132 Simple Java based control/configuration code needs to be written for
133 each project. I usually put such code into directories devoted for
134 JUnit tests. Because it needs not to be compiled/embedded into final
135 product or project artifact I'm just willing to visualize.
137 Control code in general does the following:
138 1. Create graph object.
139 2. Java reflection/classloaders does not provide mechanism for
140 discovering all classes under given package. Therefore you need to
141 declare at least some classes to be added to the graph by:
142 + Manually adding individual classes to the graph.
143 + and/or: Let GraphViz recursively scan and parse specified
144 directories with Java source code files to discover class names.
145 + For every class added to the graph, GraphViz will recursively
146 inspect it and add all referecned classes to the graph as well.
147 3. Graphs easilly get very big and complex so optionally we filter
148 important code using classname wildcards patterns based blacklist
150 4. Optionally we can tune some rendering parameters like:
151 + Possibility to remove orphaned classes (classes with no
152 references) from the graph.
153 + Specify target directory for generated visualization
154 files. (Default is user desktop directory)
155 + Keep intermediate GraphViz dot file for later inspection.
159 *** example 1: individually picked objects
160 This example demonstrates generating of class graph from hand picked
161 classes and visualizing GraphViz itself.
166 final ClassGraph graph = new ClassGraph();
168 // Add some random object to the graph. GraphViz will detect Class from
172 // Also add some random class to the graph.
173 graph.add(Utils.class);
175 // Keep intermediary GraphViz DOT file for reference.
176 graph.setKeepDotFile(true);
178 // Produce bitmap image titled "JavaInspect.png" to the user Desktop
180 graph.generateGraph("JavaInspect");
184 Note: if desired, more compact version of the above:
186 new ClassGraph().add(randomObject, RandomClass.class)
187 .setKeepDotFile(true).generateGraph("JavaInspect");
192 - Generated DOT file: [[file:JavaInspect.dot][JavaInspect.dot]]
193 - Generated PNG image: [[file:JavaInspect.png][JavaInspect.png]]
195 *** example 2: scan java code, apply filters
198 final ClassGraph graph = new ClassGraph();
200 // Recursively scan current directory for Java source code and attempt
201 // to detect class names from there to be added to the graph.
202 graph.addProject(".");
204 // Blacklist example classes from being shown on the graph
205 graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
207 // do not show single classes with no relationships on the graph
208 graph.hideOrphanedClasses();
210 // Produce bitmap image titled "JavaInspect full project.png" to the
211 // user Desktop directory.
212 graph.generateGraph("JavaInspect full project");
215 - Generated PNG image: [[file:JavaInspect%20full%20project.png][JavaInspect full project.png]]
217 *** example 3: GraphViz embedded in another project
218 1. Download project Sixth [[http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz][code snapshot]].
219 2. Inspect and run *DataGraph.java*.
221 *** Embedding JavaInspect in your Maven project
223 Declare JavaInspect as dependency:
228 <groupId>eu.svjatoslav</groupId>
229 <artifactId>javainspect</artifactId>
230 <version>1.6</version>
237 Add Maven repository to retrieve artifact from:
242 <id>svjatoslav.eu</id>
243 <name>Svjatoslav repository</name>
244 <url>http://www2.svjatoslav.eu/maven/</url>
251 [[http://www.graphviz.org/][GraphViz]] - shall be installed on the computer.
253 On Ubuntu/Debian use:
255 sudo apt-get install graphviz
258 Note: Because this is side project (and I have many of them) I can
259 only contribute few hours per year at average. Any help is welcome. A
260 LOT of cool ideas could be implemented. For intstance:
262 - BUG: Should not hide references if there are too many of them to
263 classes if referring classes are not visible anyway because of
264 blacklist/whitelist rules. Basically reference counting should
265 exclude not visible classes.
267 - BUG: Orphaned class removal does not work always. There are many
268 bugs and corner cases to find and fix still.
270 - BUG: Code is not very readable. Document and refactor for better
273 - FEATURE: Create installable DEB package.
274 - Submit it to some Debian developer for integration or become
275 Debian package maintainer.
277 - FEATURE: Make it modular. That is: central part, an application
278 model could be standalone and serializable.
280 - There could be multiple ways to acquire model:
281 - By introspecting application via Java reflections (current mode
283 - By parsing java source. (unfinished)
285 - There could be ways to manipulate model:
286 - Store/load/compare.
287 - Trim uninteresting parts.
288 - Highlight important parts.
290 - There could be multiple ways to render model:
291 - PNG/SVG (currently implemented)
293 - Interactive 3D visualization (TODO)
295 - FEATURE: Replace internal java parser in package
296 eu.svjatoslav.inspector.java.methods with: https://javaparser.org/
298 - FEATURE: Integarte with [[http://plantuml.com/class-diagram][PlantUML]].
300 - FEATURE: Add dark theme for generated graphs.
302 - FEATURE: Sort Class fields by alphabet.
304 - FEATURE: Visualize also concrete field values so it could be used as
305 ultra cool runtime logging/debugging framework.
307 - FEATURE: Possibility to visualize structure and data from JVM
310 - FEATURE: Possibility to attach to remote process to visualize
311 data/structure using JVM debug port and mechanism.
313 - FEATURE: Possibility to attach to JVM using JVM agent.
315 - FEATURE: Possibility to inspect graphs in 3D using [[http://www2.svjatoslav.eu/gitbrowse/sixth-3d/doc/index.html][Sixth 3D engine]].
317 - FEATURE: Possibility to select classes/fields/values to be
318 visualized in some graph query language. For greater flexibility in
319 comparison to currently supported glob syntax.
321 - FEATURE: Add option to control JavaInspect via JSON or XML config
322 file. For example different graphs for given project could be
323 defined once in plain text config, possibly with the aid of some
324 interactive utility. Then defined graphs could be updated as part of
325 project build or release process.
327 - FEATURE: Configurable maven plugin to generate graphs as part of the
328 project build/release process.