4 <title>JavaInspect - Utility to visualize java software</title>
5 <!-- 2021-01-10 P 00:37 -->
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/3/darkly/bootstrap.min.css" rel="stylesheet">
11 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
12 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/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>
200 <div id="outline-container-sec-1" class="outline-2">
201 <h2 id="sec-1"><span class="section-number-2">1</span> General</h2>
202 <div class="outline-text-2" id="text-1">
204 <li>This program is free software: you can redistribute it and/or modify
205 it under the terms of the <a href="https://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public License</a> as
206 published by the Free Software Foundation, either version 3 of the
207 License, or (at your option) any later version.
212 <li>Svjatoslav Agejenko
214 <li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a>
216 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a>
218 <li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a>
225 <li>GitHub fork for the project:
226 <a href="https://github.com/abargnesi/javainspect">https://github.com/abargnesi/javainspect</a>
235 <div id="outline-container-sec-1-1" class="outline-3">
236 <h3 id="sec-1-1"><span class="section-number-3">1.1</span> Source code</h3>
237 <div class="outline-text-3" id="text-1-1">
239 <li><a href="https://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=snapshot;h=HEAD;sf=tgz">Download latest snapshot in TAR GZ format</a>
242 <li><a href="https://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=summary">Browse Git repository online</a>
245 <li>Clone Git repository using command:
246 <pre class="example">
247 git clone https://www2.svjatoslav.eu/git/javainspect.git
256 <div id="outline-container-sec-2" class="outline-2">
257 <h2 id="sec-2"><span class="section-number-2">2</span> Goal and operating principle</h2>
258 <div class="outline-text-2" id="text-2">
260 Goal: simplify/speed up understanding the computer program code by
261 automatically visualizing its structure.
265 <a href="https://www3.svjatoslav.eu/projects/sixth-3d/graphs/">See example produced graphs</a> for <a href="https://www3.svjatoslav.eu/projects/sixth-3d/">Sixth 3D - 3D engine project</a>.
269 JavaInspect can be used as a <a href="#sec-4-1">standalone commandline utility</a> as well as
270 <a href="#sec-4-2">java library</a>. JavaInspect uses primarily Java built-in reflection to
271 discover and visualize any part of Java program.
275 JavaInspect currently has no GUI, configuration files, embedded
276 scripting support, direct Maven or Ant integration. See <a href="#sec-4">usage</a> to learn
277 how to instuct Javainspect what to do.
281 After discovering application structure and optionally filtering out
282 unimportant parts, JavaInspect produces GraphViz dot file that
283 describes data to be visualized. Then launches <a href="https://graphviz.org/">GraphViz</a> to generate
284 bitmap graph in PNG or SVG format.
291 <li>JavaInspect is developed and tested so far only on GNU/Linux.
293 <li>See: <a href="https://github.com/pahen/madge">Madge - similar tool for JavaScript</a>
299 <div id="outline-container-sec-3" class="outline-2">
300 <h2 id="sec-3"><span class="section-number-2">3</span> Example graphs</h2>
301 <div class="outline-text-2" id="text-3">
303 <li>A very simple example:
307 <p><img src="example.png" class="img-responsive" alt="example.png">
317 <p><img src="legend.png" class="img-responsive" alt="legend.png">
325 <li><a href="https://www3.svjatoslav.eu/projects/sixth-3d/graphs/">See example produced graphs</a> for <a href="https://www3.svjatoslav.eu/projects/sixth-3d/">Sixth 3D - 3D engine project</a>.
331 <div id="outline-container-sec-4" class="outline-2">
332 <h2 id="sec-4"><a id="ID-2ad2889e-6c95-4662-b3f4-2c341fc74522" name="ID-2ad2889e-6c95-4662-b3f4-2c341fc74522"></a><span class="section-number-2">4</span> Usage</h2>
333 <div class="outline-text-2" id="text-4">
335 JavaInspect can be controlled in 2 different ways:
338 <li><a href="#sec-4-1">as standalone commandline utility</a>
340 <li><a href="#sec-4-2">as embedded Java library via Java API</a>
345 <div id="outline-container-sec-4-1" class="outline-3">
346 <h3 id="sec-4-1"><a id="ID-acf1896a-74b4-4914-acf6-a77075e07f25" name="ID-acf1896a-74b4-4914-acf6-a77075e07f25"></a><span class="section-number-3">4.1</span> usage as commandline utility</h3>
347 <div class="outline-text-3" id="text-4-1">
349 To enable commandline support, (study and) execute script:
351 <pre class="example">
352 commandline launcher/install
357 Warning: It was tested only on Debian Stretch linux.
361 Available commandline arguments:
364 -j (existing files)…<br >
365     JAR file(s) to render.<br >
367 -n (mandatory, string)<br >
368     Graph name.<br >
371     Show debug info.<br >
374     Keep dot file.<br >
377     Hide orphaned classes.<br >
379 -w (one to many strings)…<br >
380     Whitelist glob(s).<br >
382 -b (one to many strings)…<br >
383     Blacklist glob(s).<br >
385 -d (existingdirectory)<br >
386     Target directory. Default is current directory.<br >
388 -t (options: png, svg)<br >
389     Target image type. Default is: svg.<br >
393 <div id="outline-container-sec-4-2" class="outline-3">
394 <h3 id="sec-4-2"><a id="ID-bbeeffc8-3767-440d-8d93-ec9124dd60ee" name="ID-bbeeffc8-3767-440d-8d93-ec9124dd60ee"></a><span class="section-number-3">4.2</span> usage via Java API</h3>
395 <div class="outline-text-3" id="text-4-2">
397 Requires that classes to be visualised are available in the classpath.
401 To get JavaInspect into same classpath with your projecs I so far came
406 <li>Add JavaInspect library in your project as a dependency.
409 <li>Create new Java project for the purpose visualizing your other
410 projects and include JavaInspect and your projecs binary artifacts
411 (Jar's) into new project classpath. Built binary Jar's (with no
412 source code) are sufficient because JavaInspect operates via
418 Simple Java based control/configuration code needs to be written for
419 each project. I usually put such code into directories devoted for
420 JUnit tests. Because it needs not to be compiled/embedded into final
421 product or project artifact I'm just willing to visualize.
425 Control code in general does the following:
428 <li>Create graph object.
430 <li>Java reflection/classloaders does not provide mechanism for
431 discovering all classes under given package. Therefore you need to
432 declare at least some classes to be added to the graph by manually
433 adding individual classes to the graph. For every class added to
434 the graph, GraphViz will recursively inspect it and add all
435 referecned classes to the graph as well.
437 <li>Graphs easilly get very big and complex so optionally we filter
438 important code using classname <a href="https://en.wikipedia.org/wiki/Glob_(programming)">glob</a> patterns based blacklist and/or
441 <li>Optionally we can tune some rendering parameters like:
443 <li>Possibility to remove orphaned classes (classes with no
444 references) from the graph.
446 <li>Specify target directory for generated visualization
447 files. (Default is current directory)
449 <li>Keep intermediate GraphViz dot file for later inspection.
459 <div id="outline-container-sec-4-2-1" class="outline-4">
460 <h4 id="sec-4-2-1"><span class="section-number-4">4.2.1</span> example 1: individually picked objects</h4>
461 <div class="outline-text-4" id="text-4-2-1">
463 This example demonstrates generating of class graph from hand picked
464 classes and visualizing GraphViz itself.
467 <div class="org-src-container">
469 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
470 <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>();
472 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Add some random object to the graph. GraphViz will detect Class from</span>
473 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">the object.</span>
476 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Also add some random class to the graph.</span>
477 graph.add(Utils.<span style="color: #F92672;">class</span>);
479 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Keep intermediary GraphViz DOT file for reference.</span>
480 graph.setKeepDotFile(<span style="color: #FF80F4;">true</span>);
482 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect.png" to the user Desktop</span>
483 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">directory</span>
484 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
490 Note: if desired, more compact version of the above:
492 <div class="org-src-container">
494 <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>)
495 .setKeepDotFile(<span style="color: #FF80F4;">true</span>).generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
504 <li>Generated DOT file: <a href="JavaInspect.dot">JavaInspect.dot</a>
506 <li>Generated PNG image: <a href="JavaInspect.png">JavaInspect.png</a>
512 <div id="outline-container-sec-4-2-2" class="outline-4">
513 <h4 id="sec-4-2-2"><span class="section-number-4">4.2.2</span> example 2: GraphViz embedded in another project</h4>
514 <div class="outline-text-4" id="text-4-2-2">
516 <li>Download project Sixth <a href="https://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz">code snapshot</a>.
518 <li>Inspect and run <b>DataGraph.java</b>.
524 <div id="outline-container-sec-4-2-3" class="outline-4">
525 <h4 id="sec-4-2-3"><span class="section-number-4">4.2.3</span> Embedding JavaInspect in your Maven project</h4>
526 <div class="outline-text-4" id="text-4-2-3">
528 Declare JavaInspect as dependency:
530 <div class="org-src-container">
532 <pre class="src src-xml"><<span style="color: #A6E22E;">dependencies</span>>
534 <<span style="color: #A6E22E;">dependency</span>>
535 <<span style="color: #A6E22E;">groupId</span>>eu.svjatoslav</<span style="color: #A6E22E;">groupId</span>>
536 <<span style="color: #A6E22E;">artifactId</span>>javainspect</<span style="color: #A6E22E;">artifactId</span>>
537 <<span style="color: #A6E22E;">version</span>>1.7</<span style="color: #A6E22E;">version</span>>
538 </<span style="color: #A6E22E;">dependency</span>>
540 </<span style="color: #A6E22E;">dependencies</span>>
546 Add Maven repository to retrieve artifact from:
548 <div class="org-src-container">
550 <pre class="src src-xml"><<span style="color: #A6E22E;">repositories</span>>
552 <<span style="color: #A6E22E;">repository</span>>
553 <<span style="color: #A6E22E;">id</span>>svjatoslav.eu</<span style="color: #A6E22E;">id</span>>
554 <<span style="color: #A6E22E;">name</span>>Svjatoslav repository</<span style="color: #A6E22E;">name</span>>
555 <<span style="color: #A6E22E;">url</span>>http://www2.svjatoslav.eu/maven/</<span style="color: #A6E22E;">url</span>>
556 </<span style="color: #A6E22E;">repository</span>>
558 </<span style="color: #A6E22E;">repositories</span>>
566 <div id="outline-container-sec-5" class="outline-2">
567 <h2 id="sec-5"><span class="section-number-2">5</span> Requirements</h2>
568 <div class="outline-text-2" id="text-5">
570 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
574 On Ubuntu/Debian use:
576 <div class="org-src-container">
578 <pre class="src src-sh">sudo apt-get install graphviz
583 <div id="outline-container-sec-6" class="outline-2">
584 <h2 id="sec-6"><span class="section-number-2">6</span> TO DO</h2>
585 <div class="outline-text-2" id="text-6">
587 Note: Because this is side project (and I have many of them) I can
588 only contribute few hours per year at average. Any help is welcome. A
589 LOT of cool ideas could be implemented. For intstance:
593 <li>BUG: Should not hide references if there are too many of them to
594 classes if referring classes are not visible anyway because of
595 blacklist/whitelist rules. Basically reference counting should
596 exclude not visible classes.
599 <li>BUG: Orphaned class removal does not work always. There are many
600 bugs and corner cases to find and fix still.
603 <li>BUG: Code is not very readable. Document and refactor for better
607 <li>FEATURE: Create installable DEB package.
609 <li>Submit it to some Debian developer for integration or become
610 Debian package maintainer.
615 <li>FEATURE: Make it modular. That is: central part, an application
616 model could be standalone and serializable.
619 <li>There could be multiple ways to acquire model:
621 <li>By introspecting application via Java reflections (current mode
624 <li>By parsing java source. (unfinished)
629 <li>There could be ways to manipulate model:
631 <li>Store/load/compare.
633 <li>Trim uninteresting parts.
635 <li>Highlight important parts.
640 <li>There could be multiple ways to render model:
642 <li>PNG/SVG (currently implemented)
646 <li>Interactive 3D visualization (TODO)
653 <li>FEATURE: Implement (or integrate existing java parser
654 <a href="https://javaparser.org/">https://javaparser.org/</a>) to be able to produce code visualizations
655 based on source code (in addition to current reflection based
659 <li>FEATURE: Integarte with <a href="http://plantuml.com/class-diagram">PlantUML</a>.
662 <li>FEATURE: Add dark theme for generated graphs.
665 <li>FEATURE: Sort Class fields by alphabet.
668 <li>FEATURE: Visualize also concrete field values so it could be used as
669 ultra cool runtime logging/debugging framework.
672 <li>FEATURE: Possibility to visualize structure and data from JVM
676 <li>FEATURE: Possibility to attach to remote process to visualize
677 data/structure using JVM debug port and mechanism.
680 <li>FEATURE: Possibility to attach to JVM using JVM agent.
683 <li>FEATURE: Possibility to inspect graphs in 3D using <a href="https://www3.svjatoslav.eu/projects/sixth-3d/">Sixth 3D engine</a>.
686 <li>FEATURE: Possibility to select classes/fields/values to be
687 visualized in some graph query language. For greater flexibility in
688 comparison to currently supported glob syntax.
691 <li>FEATURE: Add option to control JavaInspect via JSON or XML config
692 file. For example different graphs for given project could be
693 defined once in plain text config, possibly with the aid of some
694 interactive utility. Then defined graphs could be updated as part of
695 project build or release process.
698 <li>FEATURE: Configurable maven plugin to generate graphs as part of the
699 project build/release process.
704 <div id="outline-container-sec-7" class="outline-2">
705 <h2 id="sec-7"><span class="section-number-2">7</span> See also</h2>
706 <div class="outline-text-2" id="text-7">
708 Similar or alternative solutions:
711 <li><a href="http://www.class-visualizer.net/">http://www.class-visualizer.net/</a>
716 </div><div class="col-md-3"><nav id="table-of-contents">
717 <div id="text-table-of-contents" class="bs-docs-sidebar">
719 <li><a href="#sec-1">1. General</a>
721 <li><a href="#sec-1-1">1.1. Source code</a></li>
724 <li><a href="#sec-2">2. Goal and operating principle</a></li>
725 <li><a href="#sec-3">3. Example graphs</a></li>
726 <li><a href="#sec-4">4. Usage</a>
728 <li><a href="#sec-4-1">4.1. usage as commandline utility</a></li>
729 <li><a href="#sec-4-2">4.2. usage via Java API</a></li>
732 <li><a href="#sec-5">5. Requirements</a></li>
733 <li><a href="#sec-6">6. TO DO</a></li>
734 <li><a href="#sec-7">7. See also</a></li>
739 <footer id="postamble" class="">
740 <div><p class="author">Author: Svjatoslav Agejenko</p>
741 <p class="date">Created: 2021-01-10 P 00:37</p>
742 <p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 26.1 (<a href="http://orgmode.org">Org-mode</a> 9.1.9)</p>