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 that primarily uses Java reflection to
36 discover and visualize any part of Java program provided that
37 classes to be visualised are available in the classpath.
39 JavaInspect currently has no GUI, configuration files, embedded
40 scripting support, direct Maven or Ant integration. The only way to
41 instuct Javainspect what to do is by using its Java API.
43 To get JavaInspect into same classpath with your projecs I so far came
46 1. Add JavaInspect library in your project as a dependency.
47 2. Create new Java project for the purpose visualizing your other
48 projects and include JavaInspect and your projecs binary artifacts
49 (Jar's) into new project classpath. Built binary Jar's (with no
50 source code) are sufficient because JavaInspect operates via
53 After discovering application structure and optionally filtering out
54 unimportant parts, JavaInspect produces GraphViz dot file that
55 describes data to be visualized. Then launches GraphViz to generate
56 bitmap graph in PNG format. By default on your Desktop directory.
58 Note: GraphViz is developed and tested so far only on GNU/Linux.
61 + A very simple example:
63 [[file:example.png][file:example.resized.png]]
69 + 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]].
72 Currently the only way to control JavaInspect is by using Java
73 API. Simple Java based control/configuration code needs to be written
74 for each project. I usually put such code into directories devoted for
75 JUnit tests. Because it needs not to be compiled/embedded into final
76 product or project artifact I'm just willing to visualize.
78 Control code in general does the following:
79 1. Create graph object.
80 2. Java reflection/classloaders does not provide mechanism for
81 discovering all classes under given package. Therefore you need to
82 declare at least some classes to be added to the graph by:
83 + Manually adding individual classes to the graph.
84 + and/or: Let GraphViz recursively scan and parse specified
85 directories with Java source code files to discover class names.
86 + For every class added to the graph, GraphViz will recursively
87 inspect it and add all referecned classes to the graph as well.
88 3. Graphs easilly get very big and complex so optionally we filter
89 important code using classname wildcards patterns based blacklist
91 4. Optionally we can tune some rendering parameters like:
92 + Possibility to remove orphaned classes (classes with no
93 references) from the graph.
94 + Specify target directory for generated visualization
95 files. (Default is user desktop directory)
96 + Keep intermediate GraphViz dot file for later inspection.
100 ** example 1: individually picked objects
101 This example demonstrates generating of class graph from hand picked
102 classes and visualizing GraphViz itself.
107 final ClassGraph graph = new ClassGraph();
109 // Add some random object to the graph. GraphViz will detect Class from
113 // Also add some random class to the graph.
114 graph.add(Utils.class);
116 // Keep intermediary GraphViz DOT file for reference.
117 graph.setKeepDotFile(true);
119 // Produce bitmap image titled "JavaInspect.png" to the user Desktop
121 graph.generateGraph("JavaInspect");
125 Note: if desired, more compact version of the above:
127 new ClassGraph().add(randomObject, RandomClass.class)
128 .setKeepDotFile(true).generateGraph("JavaInspect");
133 - Generated DOT file: [[file:JavaInspect.dot][JavaInspect.dot]]
134 - Generated PNG image: [[file:JavaInspect.png][JavaInspect.png]]
136 ** example 2: scan java code, apply filters
139 final ClassGraph graph = new ClassGraph();
141 // Recursively scan current directory for Java source code and attempt
142 // to detect class names from there to be added to the graph.
143 graph.addProject(".");
145 // Blacklist example classes from being shown on the graph
146 graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
148 // do not show single classes with no relationships on the graph
149 graph.hideOrphanedClasses();
151 // Produce bitmap image titled "JavaInspect full project.png" to the
152 // user Desktop directory.
153 graph.generateGraph("JavaInspect full project");
156 - Generated PNG image: [[file:JavaInspect%20full%20project.png][JavaInspect full project.png]]
158 ** example 3: GraphViz embedded in another project
159 1. Download project Sixth [[http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz][code snapshot]].
160 2. Inspect and run *DataGraph.java*.
162 * Embedding JavaInspect in your Maven project
164 Declare JavaInspect as dependency:
169 <groupId>eu.svjatoslav</groupId>
170 <artifactId>javainspect</artifactId>
171 <version>1.6</version>
178 Add Maven repository to retrieve artifact from:
183 <id>svjatoslav.eu</id>
184 <name>Svjatoslav repository</name>
185 <url>http://www2.svjatoslav.eu/maven/</url>
192 [[http://www.graphviz.org/][GraphViz]] - shall be installed on the computer.
194 On Ubuntu/Debian use:
196 sudo apt-get install graphviz
199 - BUG: Should not hide references if there are too many of them to classes if
200 referring classes are not visible anyway because of blacklist/whitelist rules.
201 Basically reference counting should exclude not visible classes.
202 - FEATURE: replace internal java parser in package
203 eu.svjatoslav.inspector.java.methods with: https://javaparser.org/
204 - FEATURE: integarte with [[http://plantuml.com/class-diagram][PlantUML]].
205 - FEATURE: add dark theme
206 - FEATURE: sort Class fields by alphabet
207 - FEATURE: visualize also concrete field values so it could be used as
208 ultra cool runtime logging framework
209 - FEATURE: possibility to visualize structure and data from JVM
211 - FEATURE: possibility to attach to remote process to visualize
212 data/structure using JVM debug port and mechanism.
213 - FEATURE: possibility to attach to JVM using JVM agent
214 - FEATURE: possibility to script javainspect behavior
215 - FEATURE: possibility to select classes/fields/values to be
216 visualized in SQL like syntax
217 - FEATURE: configurable maven plugin to generate graphs as part of the
218 project build/release process