4 <title>JavaInspect - Utility to visualize java software</title>
5 <!-- 2017-12-26 Tue 23:30 -->
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 JavaInspect is a Java library/commandline utility that primarily uses
244 Java reflection to discover and visualize any part of Java program.
248 JavaInspect currently has no GUI, configuration files, embedded
249 scripting support, direct Maven or Ant integration. See <a href="#sec-3">usage</a> to learn
250 how to instuct Javainspect what to do.
254 After discovering application structure and optionally filtering out
255 unimportant parts, JavaInspect produces GraphViz dot file that
256 describes data to be visualized. Then launches GraphViz to generate
257 bitmap graph in PNG or SVG format.
261 By default on your Desktop directory when operated in library mode or
262 current working directory when operated as standalone commandline
267 Note: GraphViz is developed and tested so far only on GNU/Linux.
272 <div id="outline-container-sec-2" class="outline-2">
273 <h2 id="sec-2"><span class="section-number-2">2</span> Example graphs</h2>
274 <div class="outline-text-2" id="text-2">
276 <li>A very simple example:
280 <p><a href="example.png"><img src="example.resized.png" class="img-responsive" alt="example.resized.png"></a>
290 <p><img src="legend.png" class="img-responsive" alt="legend.png">
295 <li>Example visualization of <a href="http://www2.svjatoslav.eu/gitbrowse/sixth-3d/doc/">Sixth 3D</a> project: <a href="http://www2.svjatoslav.eu/gitbrowse/sixth-3d/doc/codeGraph/">architecture graphs</a>.
301 <div id="outline-container-sec-3" class="outline-2">
302 <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>
303 <div class="outline-text-2" id="text-3">
305 JavaInspect can be controlled in 2 different ways:
308 <li><a href="#sec-3-1">as standalone commandline utility</a>
310 <li><a href="#sec-3-2">as embedded Java library via Java API</a>
315 <div id="outline-container-sec-3-1" class="outline-3">
316 <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>
317 <div class="outline-text-3" id="text-3-1">
319 To enable commandline support, (study and) execute script:
321 <pre class="example">
322 commandline launcher/install
326 Warning: It was tested only on Debian Stretch linux.
330 Available commandline arguments:
333 -j (existing files)…<br >
334     JAR file(s) to render.<br >
336 -n (mandatory, string)<br >
337     Graph name.<br >
340     Show debug info.<br >
343     Keep dot file.<br >
346     Hide orphaned classes.<br >
348 -w (one to many strings)…<br >
349     Whitelist glob(s).<br >
351 -b (one to many strings)…<br >
352     Blacklist glob(s).<br >
354 -d (existingdirectory)<br >
355     Target directory. Default is current directory.<br >
357 -t (options: png, svg)<br >
358     Target image type. Default is: svg.<br >
362 <div id="outline-container-sec-3-2" class="outline-3">
363 <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>
364 <div class="outline-text-3" id="text-3-2">
366 Requires that classes to be visualised are available in the classpath.
370 To get JavaInspect into same classpath with your projecs I so far came
375 <li>Add JavaInspect library in your project as a dependency.
378 <li>Create new Java project for the purpose visualizing your other
379 projects and include JavaInspect and your projecs binary artifacts
380 (Jar's) into new project classpath. Built binary Jar's (with no
381 source code) are sufficient because JavaInspect operates via
387 Simple Java based control/configuration code needs to be written for
388 each project. I usually put such code into directories devoted for
389 JUnit tests. Because it needs not to be compiled/embedded into final
390 product or project artifact I'm just willing to visualize.
394 Control code in general does the following:
397 <li>Create graph object.
399 <li>Java reflection/classloaders does not provide mechanism for
400 discovering all classes under given package. Therefore you need to
401 declare at least some classes to be added to the graph by:
403 <li>Manually adding individual classes to the graph.
405 <li>and/or: Let GraphViz recursively scan and parse specified
406 directories with Java source code files to discover class names.
408 <li>For every class added to the graph, GraphViz will recursively
409 inspect it and add all referecned classes to the graph as well.
413 <li>Graphs easilly get very big and complex so optionally we filter
414 important code using classname wildcards patterns based blacklist
417 <li>Optionally we can tune some rendering parameters like:
419 <li>Possibility to remove orphaned classes (classes with no
420 references) from the graph.
422 <li>Specify target directory for generated visualization
423 files. (Default is user desktop directory)
425 <li>Keep intermediate GraphViz dot file for later inspection.
435 <div id="outline-container-sec-3-2-1" class="outline-4">
436 <h4 id="sec-3-2-1"><span class="section-number-4">3.2.1</span> example 1: individually picked objects</h4>
437 <div class="outline-text-4" id="text-3-2-1">
439 This example demonstrates generating of class graph from hand picked
440 classes and visualizing GraphViz itself.
443 <div class="org-src-container">
445 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
446 <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>();
448 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Add some random object to the graph. GraphViz will detect Class from</span>
449 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">the object.</span>
452 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Also add some random class to the graph.</span>
453 graph.add(Utils.<span style="color: #F92672;">class</span>);
455 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Keep intermediary GraphViz DOT file for reference.</span>
456 graph.setKeepDotFile(<span style="color: #FF80F4;">true</span>);
458 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect.png" to the user Desktop</span>
459 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">directory</span>
460 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
465 Note: if desired, more compact version of the above:
467 <div class="org-src-container">
469 <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>)
470 .setKeepDotFile(<span style="color: #FF80F4;">true</span>).generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
479 <li>Generated DOT file: <a href="JavaInspect.dot">JavaInspect.dot</a>
481 <li>Generated PNG image: <a href="JavaInspect.png">JavaInspect.png</a>
487 <div id="outline-container-sec-3-2-2" class="outline-4">
488 <h4 id="sec-3-2-2"><span class="section-number-4">3.2.2</span> example 2: scan java code, apply filters</h4>
489 <div class="outline-text-4" id="text-3-2-2">
490 <div class="org-src-container">
492 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
493 <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>();
495 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Recursively scan current directory for Java source code and attempt</span>
496 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">to detect class names from there to be added to the graph.</span>
497 graph.addProject(<span style="color: #EEDC82;">"."</span>);
499 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Blacklist example classes from being shown on the graph</span>
500 graph.blacklistClassPattern(<span style="color: #EEDC82;">"eu.svjatoslav.inspector.java.structure.example.*"</span>);
502 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">do not show single classes with no relationships on the graph</span>
503 graph.hideOrphanedClasses();
505 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect full project.png" to the</span>
506 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">user Desktop directory.</span>
507 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect full project"</span>);
514 <li>Generated PNG image: <a href="JavaInspect%20full%20project.png">JavaInspect full project.png</a>
520 <div id="outline-container-sec-3-2-3" class="outline-4">
521 <h4 id="sec-3-2-3"><span class="section-number-4">3.2.3</span> example 3: GraphViz embedded in another project</h4>
522 <div class="outline-text-4" id="text-3-2-3">
524 <li>Download project Sixth <a href="http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz">code snapshot</a>.
526 <li>Inspect and run *DataGraph.java*.
532 <div id="outline-container-sec-3-2-4" class="outline-4">
533 <h4 id="sec-3-2-4"><span class="section-number-4">3.2.4</span> Embedding JavaInspect in your Maven project</h4>
534 <div class="outline-text-4" id="text-3-2-4">
536 Declare JavaInspect as dependency:
538 <div class="org-src-container">
540 <pre class="src src-xml"><<span style="color: #A6E22E;">dependencies</span>>
542 <<span style="color: #A6E22E;">dependency</span>>
543 <<span style="color: #A6E22E;">groupId</span>>eu.svjatoslav</<span style="color: #A6E22E;">groupId</span>>
544 <<span style="color: #A6E22E;">artifactId</span>>javainspect</<span style="color: #A6E22E;">artifactId</span>>
545 <<span style="color: #A6E22E;">version</span>>1.6</<span style="color: #A6E22E;">version</span>>
546 </<span style="color: #A6E22E;">dependency</span>>
548 </<span style="color: #A6E22E;">dependencies</span>>
554 Add Maven repository to retrieve artifact from:
556 <div class="org-src-container">
558 <pre class="src src-xml"><<span style="color: #A6E22E;">repositories</span>>
560 <<span style="color: #A6E22E;">repository</span>>
561 <<span style="color: #A6E22E;">id</span>>svjatoslav.eu</<span style="color: #A6E22E;">id</span>>
562 <<span style="color: #A6E22E;">name</span>>Svjatoslav repository</<span style="color: #A6E22E;">name</span>>
563 <<span style="color: #A6E22E;">url</span>>http://www2.svjatoslav.eu/maven/</<span style="color: #A6E22E;">url</span>>
564 </<span style="color: #A6E22E;">repository</span>>
566 </<span style="color: #A6E22E;">repositories</span>>
574 <div id="outline-container-sec-4" class="outline-2">
575 <h2 id="sec-4"><span class="section-number-2">4</span> Requirements</h2>
576 <div class="outline-text-2" id="text-4">
578 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
582 On Ubuntu/Debian use:
584 <div class="org-src-container">
586 <pre class="src src-sh">sudo apt-get install graphviz
591 <div id="outline-container-sec-5" class="outline-2">
592 <h2 id="sec-5"><span class="section-number-2">5</span> TO DO</h2>
593 <div class="outline-text-2" id="text-5">
595 Note: Because this is side project (and I have many of them) I can
596 only contribute few hours per year at average. Any help is welcome. A
597 LOT of cool ideas could be implemented. For intstance:
601 <li>BUG: Should not hide references if there are too many of them to
602 classes if referring classes are not visible anyway because of
603 blacklist/whitelist rules. Basically reference counting should
604 exclude not visible classes.
607 <li>BUG: Orphaned class removal does not work always. There are many
608 bugs and corner cases to find and fix still.
611 <li>BUG: Code is not very readable. Document and refactor for better
615 <li>FEATURE: Create installable DEB package.
617 <li>Submit it to some Debian developer for integration or become
618 Debian package maintainer.
623 <li>FEATURE: Make it modular. That is: central part, an application
624 model could be standalone and serializable.
627 <li>There could be multiple ways to acquire model:
629 <li>By introspecting application via Java reflections (current mode
632 <li>By parsing java source. (unfinished)
637 <li>There could be ways to manipulate model:
639 <li>Store/load/compare.
641 <li>Trim uninteresting parts.
643 <li>Highlight important parts.
648 <li>There could be multiple ways to render model:
650 <li>PNG/SVG (currently implemented)
654 <li>Interactive 3D visualization (TODO)
661 <li>FEATURE: Replace internal java parser in package
662 eu.svjatoslav.inspector.java.methods with: <a href="https://javaparser.org/">https://javaparser.org/</a>
665 <li>FEATURE: Integarte with <a href="http://plantuml.com/class-diagram">PlantUML</a>.
668 <li>FEATURE: Add dark theme for generated graphs.
671 <li>FEATURE: Sort Class fields by alphabet.
674 <li>FEATURE: Visualize also concrete field values so it could be used as
675 ultra cool runtime logging/debugging framework.
678 <li>FEATURE: Possibility to visualize structure and data from JVM
682 <li>FEATURE: Possibility to attach to remote process to visualize
683 data/structure using JVM debug port and mechanism.
686 <li>FEATURE: Possibility to attach to JVM using JVM agent.
689 <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>.
692 <li>FEATURE: Possibility to select classes/fields/values to be
693 visualized in some graph query language. For greater flexibility in
694 comparison to currently supported glob syntax.
697 <li>FEATURE: Add option to control JavaInspect via JSON or XML config
698 file. For example different graphs for given project could be
699 defined once in plain text config, possibly with the aid of some
700 interactive utility. Then defined graphs could be updated as part of
701 project build or release process.
704 <li>FEATURE: Configurable maven plugin to generate graphs as part of the
705 project build/release process.
710 </div><div class="col-md-3"><nav id="table-of-contents">
711 <div id="text-table-of-contents" class="bs-docs-sidebar">
713 <li><a href="#sec-1">1. General</a></li>
714 <li><a href="#sec-2">2. Example graphs</a></li>
715 <li><a href="#sec-3">3. Usage</a>
717 <li><a href="#sec-3-1">3.1. usage as commandline utility</a></li>
718 <li><a href="#sec-3-2">3.2. usage via Java API</a></li>
721 <li><a href="#sec-4">4. Requirements</a></li>
722 <li><a href="#sec-5">5. TO DO</a></li>
727 <footer id="postamble" class="">
728 <div><p class="author">Author: Svjatoslav Agejenko</p>
729 <p class="date">Created: 2017-12-26 Tue 23:30</p>
730 <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>