4 <title>JavaInspect - Utility to visualize java software</title>
5 <!-- 2018-01-04 Thu 00:23 -->
7 <meta name="viewport" content="width=device-width, initial-scale=1">
8 <meta name="generator" content="Org-mode">
9 <meta name="author" content="Svjatoslav Agejenko">
10 <link href="https://bootswatch.com/4/darkly/bootstrap.min.css" rel="stylesheet">
11 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
12 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>"
13 <style type="text/css">
14 footer {background-color: #111 !important;}
15 pre {background-color: #111; color: #ccc;}
17 <style type="text/css">
18 /* org mode styles on top of twbs */
35 background-color: #f5f5f5;
62 display: inline-block;
74 .bs-docs-sidebar.affix {
77 @media (min-width: 768px) {
83 /* All levels of nav */
84 .bs-docs-sidebar .nav > li > a {
91 .bs-docs-sidebar .nav > li > a:hover,
92 .bs-docs-sidebar .nav > li > a:focus {
95 text-decoration: none;
96 background-color: transparent;
97 border-left: 1px solid #A1283B;
99 .bs-docs-sidebar .nav > .active > a,
100 .bs-docs-sidebar .nav > .active:hover > a,
101 .bs-docs-sidebar .nav > .active:focus > a {
105 background-color: transparent;
106 border-left: 2px solid #A1283B;
109 /* Nav: second level (shown on .active) */
110 .bs-docs-sidebar .nav .nav {
111 display: none; /* Hide by default, but at >768px, show it */
112 padding-bottom: 10px;
114 .bs-docs-sidebar .nav .nav > li > a {
121 .bs-docs-sidebar .nav .nav > li > a:hover,
122 .bs-docs-sidebar .nav .nav > li > a:focus {
125 .bs-docs-sidebar .nav .nav > .active > a,
126 .bs-docs-sidebar .nav .nav > .active:hover > a,
127 .bs-docs-sidebar .nav .nav > .active:focus > a {
132 /* Nav: third level (shown on .active) */
133 .bs-docs-sidebar .nav .nav .nav {
134 padding-bottom: 10px;
136 .bs-docs-sidebar .nav .nav .nav > li > a {
143 .bs-docs-sidebar .nav .nav .nav > li > a:hover,
144 .bs-docs-sidebar .nav .nav .nav > li > a:focus {
147 .bs-docs-sidebar .nav .nav .nav > .active > a,
148 .bs-docs-sidebar .nav .nav .nav > .active:hover > a,
149 .bs-docs-sidebar .nav .nav .nav > .active:focus > a {
154 /* Show and affix the side nav when space allows it */
155 @media (min-width: 992px) {
156 .bs-docs-sidebar .nav > .active > ul {
159 /* Widen the fixed sidebar */
160 .bs-docs-sidebar.affix,
161 .bs-docs-sidebar.affix-bottom {
164 .bs-docs-sidebar.affix {
165 position: fixed; /* Undo the static from mobile first approach */
168 .bs-docs-sidebar.affix-bottom {
169 position: absolute; /* Undo the static from mobile first approach */
171 .bs-docs-sidebar.affix .bs-docs-sidenav,.bs-docs-sidebar.affix-bottom .bs-docs-sidenav {
176 @media (min-width: 1200px) {
177 /* Widen the fixed sidebar again */
178 .bs-docs-sidebar.affix-bottom,
179 .bs-docs-sidebar.affix {
184 <script type="text/javascript">
188 $('.bs-docs-sidebar li').first().addClass('active');
190 $(document.body).scrollspy({target: '.bs-docs-sidebar'});
192 $('.bs-docs-sidebar').affix();
197 <div id="content" class="container">
198 <div class="row"><div class="col-md-9"><h1 class="title">JavaInspect - Utility to visualize java software</h1>
201 <li><a href="http://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=snapshot;h=HEAD;sf=tgz">download latest snapshot</a>
204 <li>This program is free software; you can redistribute it and/or modify
205 it under the terms of version 3 of the <a href="https://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public
206 License</a> or later as published by the Free Software Foundation.
211 <li>Svjatoslav Agejenko
213 <li>Homepage: <a href="http://svjatoslav.eu">http://svjatoslav.eu</a>
215 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a>
222 <li>GitHub fork for the project:
223 <a href="https://github.com/abargnesi/javainspect">https://github.com/abargnesi/javainspect</a>
230 <li><a href="http://www.svjatoslav.eu/programs.jsp">other applications hosted at svjatoslav.eu</a>
234 <div id="outline-container-sec-1" class="outline-2">
235 <h2 id="sec-1"><span class="section-number-2">1</span> General</h2>
236 <div class="outline-text-2" id="text-1">
238 Goal: simplify/speed up understanding the computer program code by
239 automatically visualizing its structure.
243 <a href="http://www3.svjatoslav.eu/projects/sixth-3d/graphs/">See example produced graphs</a> for <a href="http://www3.svjatoslav.eu/projects/sixth-3d/">Sixth 3D - 3D engine project</a>.
247 JavaInspect can be used as a <a href="#sec-3-1">standalone commandline utility</a> as well as
248 <a href="#sec-3-2">java library</a>. JavaInspect uses primarily Java built-in reflection to
249 discover and visualize any part of Java program.
253 JavaInspect currently has no GUI, configuration files, embedded
254 scripting support, direct Maven or Ant integration. See <a href="#sec-3">usage</a> to learn
255 how to instuct Javainspect what to do.
259 After discovering application structure and optionally filtering out
260 unimportant parts, JavaInspect produces GraphViz dot file that
261 describes data to be visualized. Then launches GraphViz to generate
262 bitmap graph in PNG or SVG format.
266 By default on your Desktop directory when operated in library mode or
267 current working directory when operated as standalone commandline
272 Note: GraphViz is developed and tested so far only on GNU/Linux.
277 <div id="outline-container-sec-2" class="outline-2">
278 <h2 id="sec-2"><span class="section-number-2">2</span> Example graphs</h2>
279 <div class="outline-text-2" id="text-2">
281 <li>A very simple example:
285 <p><a href="example.png"><img src="example.resized.png" class="img-responsive" alt="example.resized.png"></a>
295 <p><img src="legend.png" class="img-responsive" alt="legend.png">
300 <li><a href="http://www3.svjatoslav.eu/projects/sixth-3d/graphs/">See example produced graphs</a> for <a href="http://www3.svjatoslav.eu/projects/sixth-3d/">Sixth 3D - 3D engine project</a>.
306 <div id="outline-container-sec-3" class="outline-2">
307 <h2 id="sec-3"><a id="ID-2ad2889e-6c95-4662-b3f4-2c341fc74522" name="ID-2ad2889e-6c95-4662-b3f4-2c341fc74522"></a><span class="section-number-2">3</span> Usage</h2>
308 <div class="outline-text-2" id="text-3">
310 JavaInspect can be controlled in 2 different ways:
313 <li><a href="#sec-3-1">as standalone commandline utility</a>
315 <li><a href="#sec-3-2">as embedded Java library via Java API</a>
320 <div id="outline-container-sec-3-1" class="outline-3">
321 <h3 id="sec-3-1"><a id="ID-acf1896a-74b4-4914-acf6-a77075e07f25" name="ID-acf1896a-74b4-4914-acf6-a77075e07f25"></a><span class="section-number-3">3.1</span> usage as commandline utility</h3>
322 <div class="outline-text-3" id="text-3-1">
324 To enable commandline support, (study and) execute script:
326 <pre class="example">
327 commandline launcher/install
331 Warning: It was tested only on Debian Stretch linux.
335 Available commandline arguments:
338 -j (existing files)…<br >
339     JAR file(s) to render.<br >
341 -n (mandatory, string)<br >
342     Graph name.<br >
345     Show debug info.<br >
348     Keep dot file.<br >
351     Hide orphaned classes.<br >
353 -w (one to many strings)…<br >
354     Whitelist glob(s).<br >
356 -b (one to many strings)…<br >
357     Blacklist glob(s).<br >
359 -d (existingdirectory)<br >
360     Target directory. Default is current directory.<br >
362 -t (options: png, svg)<br >
363     Target image type. Default is: svg.<br >
367 <div id="outline-container-sec-3-2" class="outline-3">
368 <h3 id="sec-3-2"><a id="ID-bbeeffc8-3767-440d-8d93-ec9124dd60ee" name="ID-bbeeffc8-3767-440d-8d93-ec9124dd60ee"></a><span class="section-number-3">3.2</span> usage via Java API</h3>
369 <div class="outline-text-3" id="text-3-2">
371 Requires that classes to be visualised are available in the classpath.
375 To get JavaInspect into same classpath with your projecs I so far came
380 <li>Add JavaInspect library in your project as a dependency.
383 <li>Create new Java project for the purpose visualizing your other
384 projects and include JavaInspect and your projecs binary artifacts
385 (Jar's) into new project classpath. Built binary Jar's (with no
386 source code) are sufficient because JavaInspect operates via
392 Simple Java based control/configuration code needs to be written for
393 each project. I usually put such code into directories devoted for
394 JUnit tests. Because it needs not to be compiled/embedded into final
395 product or project artifact I'm just willing to visualize.
399 Control code in general does the following:
402 <li>Create graph object.
404 <li>Java reflection/classloaders does not provide mechanism for
405 discovering all classes under given package. Therefore you need to
406 declare at least some classes to be added to the graph by:
408 <li>Manually adding individual classes to the graph.
410 <li>and/or: Let GraphViz recursively scan and parse specified
411 directories with Java source code files to discover class names.
413 <li>For every class added to the graph, GraphViz will recursively
414 inspect it and add all referecned classes to the graph as well.
418 <li>Graphs easilly get very big and complex so optionally we filter
419 important code using classname wildcards patterns based blacklist
422 <li>Optionally we can tune some rendering parameters like:
424 <li>Possibility to remove orphaned classes (classes with no
425 references) from the graph.
427 <li>Specify target directory for generated visualization
428 files. (Default is user desktop directory)
430 <li>Keep intermediate GraphViz dot file for later inspection.
440 <div id="outline-container-sec-3-2-1" class="outline-4">
441 <h4 id="sec-3-2-1"><span class="section-number-4">3.2.1</span> example 1: individually picked objects</h4>
442 <div class="outline-text-4" id="text-3-2-1">
444 This example demonstrates generating of class graph from hand picked
445 classes and visualizing GraphViz itself.
448 <div class="org-src-container">
450 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
451 <span style="color: #F92672;">final</span> <span style="color: #66D9EF;">ClassGraph</span> <span style="color: #FD971F;">graph</span> = <span style="color: #F92672;">new</span> <span style="color: #66D9EF;">ClassGraph</span>();
453 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Add some random object to the graph. GraphViz will detect Class from</span>
454 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">the object.</span>
457 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Also add some random class to the graph.</span>
458 graph.add(Utils.<span style="color: #F92672;">class</span>);
460 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Keep intermediary GraphViz DOT file for reference.</span>
461 graph.setKeepDotFile(<span style="color: #FF80F4;">true</span>);
463 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect.png" to the user Desktop</span>
464 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">directory</span>
465 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
470 Note: if desired, more compact version of the above:
472 <div class="org-src-container">
474 <pre class="src src-java"><span style="color: #F92672;">new</span> <span style="color: #66D9EF;">ClassGraph</span>().add(randomObject, RandomClass.<span style="color: #F92672;">class</span>)
475 .setKeepDotFile(<span style="color: #FF80F4;">true</span>).generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
484 <li>Generated DOT file: <a href="JavaInspect.dot">JavaInspect.dot</a>
486 <li>Generated PNG image: <a href="JavaInspect.png">JavaInspect.png</a>
492 <div id="outline-container-sec-3-2-2" class="outline-4">
493 <h4 id="sec-3-2-2"><span class="section-number-4">3.2.2</span> example 2: scan java code, apply filters</h4>
494 <div class="outline-text-4" id="text-3-2-2">
495 <div class="org-src-container">
497 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
498 <span style="color: #F92672;">final</span> <span style="color: #66D9EF;">ClassGraph</span> <span style="color: #FD971F;">graph</span> = <span style="color: #F92672;">new</span> <span style="color: #66D9EF;">ClassGraph</span>();
500 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Recursively scan current directory for Java source code and attempt</span>
501 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">to detect class names from there to be added to the graph.</span>
502 graph.addProject(<span style="color: #EEDC82;">"."</span>);
504 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Blacklist example classes from being shown on the graph</span>
505 graph.blacklistClassPattern(<span style="color: #EEDC82;">"eu.svjatoslav.inspector.java.structure.example.*"</span>);
507 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">do not show single classes with no relationships on the graph</span>
508 graph.hideOrphanedClasses();
510 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect full project.png" to the</span>
511 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">user Desktop directory.</span>
512 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect full project"</span>);
519 <li>Generated PNG image: <a href="JavaInspect%20full%20project.png">JavaInspect full project.png</a>
525 <div id="outline-container-sec-3-2-3" class="outline-4">
526 <h4 id="sec-3-2-3"><span class="section-number-4">3.2.3</span> example 3: GraphViz embedded in another project</h4>
527 <div class="outline-text-4" id="text-3-2-3">
529 <li>Download project Sixth <a href="http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz">code snapshot</a>.
531 <li>Inspect and run *DataGraph.java*.
537 <div id="outline-container-sec-3-2-4" class="outline-4">
538 <h4 id="sec-3-2-4"><span class="section-number-4">3.2.4</span> Embedding JavaInspect in your Maven project</h4>
539 <div class="outline-text-4" id="text-3-2-4">
541 Declare JavaInspect as dependency:
543 <div class="org-src-container">
545 <pre class="src src-xml"><<span style="color: #A6E22E;">dependencies</span>>
547 <<span style="color: #A6E22E;">dependency</span>>
548 <<span style="color: #A6E22E;">groupId</span>>eu.svjatoslav</<span style="color: #A6E22E;">groupId</span>>
549 <<span style="color: #A6E22E;">artifactId</span>>javainspect</<span style="color: #A6E22E;">artifactId</span>>
550 <<span style="color: #A6E22E;">version</span>>1.6</<span style="color: #A6E22E;">version</span>>
551 </<span style="color: #A6E22E;">dependency</span>>
553 </<span style="color: #A6E22E;">dependencies</span>>
559 Add Maven repository to retrieve artifact from:
561 <div class="org-src-container">
563 <pre class="src src-xml"><<span style="color: #A6E22E;">repositories</span>>
565 <<span style="color: #A6E22E;">repository</span>>
566 <<span style="color: #A6E22E;">id</span>>svjatoslav.eu</<span style="color: #A6E22E;">id</span>>
567 <<span style="color: #A6E22E;">name</span>>Svjatoslav repository</<span style="color: #A6E22E;">name</span>>
568 <<span style="color: #A6E22E;">url</span>>http://www2.svjatoslav.eu/maven/</<span style="color: #A6E22E;">url</span>>
569 </<span style="color: #A6E22E;">repository</span>>
571 </<span style="color: #A6E22E;">repositories</span>>
579 <div id="outline-container-sec-4" class="outline-2">
580 <h2 id="sec-4"><span class="section-number-2">4</span> Requirements</h2>
581 <div class="outline-text-2" id="text-4">
583 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
587 On Ubuntu/Debian use:
589 <div class="org-src-container">
591 <pre class="src src-sh">sudo apt-get install graphviz
596 <div id="outline-container-sec-5" class="outline-2">
597 <h2 id="sec-5"><span class="section-number-2">5</span> TO DO</h2>
598 <div class="outline-text-2" id="text-5">
600 Note: Because this is side project (and I have many of them) I can
601 only contribute few hours per year at average. Any help is welcome. A
602 LOT of cool ideas could be implemented. For intstance:
606 <li>BUG: Should not hide references if there are too many of them to
607 classes if referring classes are not visible anyway because of
608 blacklist/whitelist rules. Basically reference counting should
609 exclude not visible classes.
612 <li>BUG: Orphaned class removal does not work always. There are many
613 bugs and corner cases to find and fix still.
616 <li>BUG: Code is not very readable. Document and refactor for better
620 <li>FEATURE: Create installable DEB package.
622 <li>Submit it to some Debian developer for integration or become
623 Debian package maintainer.
628 <li>FEATURE: Make it modular. That is: central part, an application
629 model could be standalone and serializable.
632 <li>There could be multiple ways to acquire model:
634 <li>By introspecting application via Java reflections (current mode
637 <li>By parsing java source. (unfinished)
642 <li>There could be ways to manipulate model:
644 <li>Store/load/compare.
646 <li>Trim uninteresting parts.
648 <li>Highlight important parts.
653 <li>There could be multiple ways to render model:
655 <li>PNG/SVG (currently implemented)
659 <li>Interactive 3D visualization (TODO)
666 <li>FEATURE: Replace internal java parser in package
667 eu.svjatoslav.inspector.java.methods with: <a href="https://javaparser.org/">https://javaparser.org/</a>
670 <li>FEATURE: Integarte with <a href="http://plantuml.com/class-diagram">PlantUML</a>.
673 <li>FEATURE: Add dark theme for generated graphs.
676 <li>FEATURE: Sort Class fields by alphabet.
679 <li>FEATURE: Visualize also concrete field values so it could be used as
680 ultra cool runtime logging/debugging framework.
683 <li>FEATURE: Possibility to visualize structure and data from JVM
687 <li>FEATURE: Possibility to attach to remote process to visualize
688 data/structure using JVM debug port and mechanism.
691 <li>FEATURE: Possibility to attach to JVM using JVM agent.
694 <li>FEATURE: Possibility to inspect graphs in 3D using <a href="http://www2.svjatoslav.eu/gitbrowse/sixth-3d/doc/index.html">Sixth 3D engine</a>.
697 <li>FEATURE: Possibility to select classes/fields/values to be
698 visualized in some graph query language. For greater flexibility in
699 comparison to currently supported glob syntax.
702 <li>FEATURE: Add option to control JavaInspect via JSON or XML config
703 file. For example different graphs for given project could be
704 defined once in plain text config, possibly with the aid of some
705 interactive utility. Then defined graphs could be updated as part of
706 project build or release process.
709 <li>FEATURE: Configurable maven plugin to generate graphs as part of the
710 project build/release process.
715 </div><div class="col-md-3"><nav id="table-of-contents">
716 <div id="text-table-of-contents" class="bs-docs-sidebar">
718 <li><a href="#sec-1">1. General</a></li>
719 <li><a href="#sec-2">2. Example graphs</a></li>
720 <li><a href="#sec-3">3. Usage</a>
722 <li><a href="#sec-3-1">3.1. usage as commandline utility</a></li>
723 <li><a href="#sec-3-2">3.2. usage via Java API</a></li>
726 <li><a href="#sec-4">4. Requirements</a></li>
727 <li><a href="#sec-5">5. TO DO</a></li>
732 <footer id="postamble" class="">
733 <div><p class="author">Author: Svjatoslav Agejenko</p>
734 <p class="date">Created: 2018-01-04 Thu 00:23</p>
735 <p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.1.1 (<a href="http://orgmode.org">Org-mode</a> 8.2.10)</p>