4 <title>JavaInspect - Utility to visualize java software</title>
5 <!-- 2017-11-29 Wed 23:51 -->
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>
220 <li><a href="http://www.svjatoslav.eu/programs.jsp">other applications hosted at svjatoslav.eu</a>
224 <div id="outline-container-sec-1" class="outline-2">
225 <h2 id="sec-1"><span class="section-number-2">1</span> General</h2>
226 <div class="outline-text-2" id="text-1">
228 Goal: simplify/speed up understanding the computer program code by
229 automatically visualizing its structure.
233 JavaInspect is a Java library that primarily uses Java reflection to
234 discover and visualize any part of Java program provided that
235 classes to be visualised are available in the classpath.
239 JavaInspect currently has no GUI, configuration files, embedded
240 scripting support, direct Maven or Ant integration. The only way to
241 instuct Javainspect what to do is by using its Java API.
245 To get JavaInspect into same classpath with your projecs I so far came
250 <li>Add JavaInspect library in your project as a dependency.
252 <li>Create new Java project for the purpose visualizing your other
253 projects and include JavaInspect and your projecs binary artifacts
254 (Jar's) into new project classpath. Built binary Jar's (with no
255 source code) are sufficient because JavaInspect operates via
261 After discovering application structure and optionally filtering out
262 unimportant parts, JavaInspect produces GraphViz dot file that
263 describes data to be visualized. Then launches GraphViz to generate
264 bitmap graph in PNG format. By default on your Desktop directory.
268 Note: GraphViz is developed and tested so far only on GNU/Linux.
273 <div id="outline-container-sec-2" class="outline-2">
274 <h2 id="sec-2"><span class="section-number-2">2</span> Example graphs</h2>
275 <div class="outline-text-2" id="text-2">
277 <li>A very simple example:
281 <p><a href="example.png"><img src="example.resized.png" class="img-responsive" alt="example.resized.png"></a>
291 <p><img src="legend.png" class="img-responsive" alt="legend.png">
296 <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>.
302 <div id="outline-container-sec-3" class="outline-2">
303 <h2 id="sec-3"><span class="section-number-2">3</span> Usage</h2>
304 <div class="outline-text-2" id="text-3">
306 Currently the only way to control JavaInspect is by using Java
307 API. Simple Java based control/configuration code needs to be written
308 for each project. I usually put such code into directories devoted for
309 JUnit tests. Because it needs not to be compiled/embedded into final
310 product or project artifact I'm just willing to visualize.
314 Control code in general does the following:
317 <li>Create graph object.
319 <li>Java reflection/classloaders does not provide mechanism for
320 discovering all classes under given package. Therefore you need to
321 declare at least some classes to be added to the graph by:
323 <li>Manually adding individual classes to the graph.
325 <li>and/or: Let GraphViz recursively scan and parse specified
326 directories with Java source code files to discover class names.
328 <li>For every class added to the graph, GraphViz will recursively
329 inspect it and add all referecned classes to the graph as well.
333 <li>Graphs easilly get very big and complex so optionally we filter
334 important code using classname wildcards patterns based blacklist
337 <li>Optionally we can tune some rendering parameters like:
339 <li>Possibility to remove orphaned classes (classes with no
340 references) from the graph.
342 <li>Specify target directory for generated visualization
343 files. (Default is user desktop directory)
345 <li>Keep intermediate GraphViz dot file for later inspection.
355 <div id="outline-container-sec-3-1" class="outline-3">
356 <h3 id="sec-3-1"><span class="section-number-3">3.1</span> example 1: individually picked objects</h3>
357 <div class="outline-text-3" id="text-3-1">
359 This example demonstrates generating of class graph from hand picked
360 classes and visualizing GraphViz itself.
363 <div class="org-src-container">
365 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
366 <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>();
368 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Add some random object to the graph. GraphViz will detect Class from</span>
369 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">the object.</span>
372 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Also add some random class to the graph.</span>
373 graph.add(Utils.<span style="color: #F92672;">class</span>);
375 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Keep intermediary GraphViz DOT file for reference.</span>
376 graph.setKeepDotFile(<span style="color: #FF80F4;">true</span>);
378 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect.png" to the user Desktop</span>
379 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">directory</span>
380 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
385 Note: if desired, more compact version of the above:
387 <div class="org-src-container">
389 <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>)
390 .setKeepDotFile(<span style="color: #FF80F4;">true</span>).generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
399 <li>Generated DOT file: <a href="JavaInspect.dot">JavaInspect.dot</a>
401 <li>Generated PNG image: <a href="JavaInspect.png">JavaInspect.png</a>
407 <div id="outline-container-sec-3-2" class="outline-3">
408 <h3 id="sec-3-2"><span class="section-number-3">3.2</span> example 2: scan java code, apply filters</h3>
409 <div class="outline-text-3" id="text-3-2">
410 <div class="org-src-container">
412 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
413 <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>();
415 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Recursively scan current directory for Java source code and attempt</span>
416 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">to detect class names from there to be added to the graph.</span>
417 graph.addProject(<span style="color: #EEDC82;">"."</span>);
419 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Blacklist example classes from being shown on the graph</span>
420 graph.blacklistClassPattern(<span style="color: #EEDC82;">"eu.svjatoslav.inspector.java.structure.example.*"</span>);
422 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">do not show single classes with no relationships on the graph</span>
423 graph.hideOrphanedClasses();
425 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect full project.png" to the</span>
426 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">user Desktop directory.</span>
427 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect full project"</span>);
434 <li>Generated PNG image: <a href="JavaInspect%20full%20project.png">JavaInspect full project.png</a>
440 <div id="outline-container-sec-3-3" class="outline-3">
441 <h3 id="sec-3-3"><span class="section-number-3">3.3</span> example 3: GraphViz embedded in another project</h3>
442 <div class="outline-text-3" id="text-3-3">
444 <li>Download project Sixth <a href="http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz">code snapshot</a>.
446 <li>Inspect and run *DataGraph.java*.
453 <div id="outline-container-sec-4" class="outline-2">
454 <h2 id="sec-4"><span class="section-number-2">4</span> Embedding JavaInspect in your Maven project</h2>
455 <div class="outline-text-2" id="text-4">
457 Declare JavaInspect as dependency:
459 <div class="org-src-container">
461 <pre class="src src-xml"><<span style="color: #A6E22E;">dependencies</span>>
463 <<span style="color: #A6E22E;">dependency</span>>
464 <<span style="color: #A6E22E;">groupId</span>>eu.svjatoslav</<span style="color: #A6E22E;">groupId</span>>
465 <<span style="color: #A6E22E;">artifactId</span>>javainspect</<span style="color: #A6E22E;">artifactId</span>>
466 <<span style="color: #A6E22E;">version</span>>1.6</<span style="color: #A6E22E;">version</span>>
467 </<span style="color: #A6E22E;">dependency</span>>
469 </<span style="color: #A6E22E;">dependencies</span>>
475 Add Maven repository to retrieve artifact from:
477 <div class="org-src-container">
479 <pre class="src src-xml"><<span style="color: #A6E22E;">repositories</span>>
481 <<span style="color: #A6E22E;">repository</span>>
482 <<span style="color: #A6E22E;">id</span>>svjatoslav.eu</<span style="color: #A6E22E;">id</span>>
483 <<span style="color: #A6E22E;">name</span>>Svjatoslav repository</<span style="color: #A6E22E;">name</span>>
484 <<span style="color: #A6E22E;">url</span>>http://www2.svjatoslav.eu/maven/</<span style="color: #A6E22E;">url</span>>
485 </<span style="color: #A6E22E;">repository</span>>
487 </<span style="color: #A6E22E;">repositories</span>>
493 <div id="outline-container-sec-5" class="outline-2">
494 <h2 id="sec-5"><span class="section-number-2">5</span> Requirements</h2>
495 <div class="outline-text-2" id="text-5">
497 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
501 On Ubuntu/Debian use:
503 <div class="org-src-container">
505 <pre class="src src-sh">sudo apt-get install graphviz
510 <div id="outline-container-sec-6" class="outline-2">
511 <h2 id="sec-6"><span class="section-number-2">6</span> TO DO</h2>
512 <div class="outline-text-2" id="text-6">
514 <li>BUG: Should not hide references if there are too many of them to classes if
515 referring classes are not visible anyway because of blacklist/whitelist rules.
516 Basically reference counting should exclude not visible classes.
518 <li>FEATURE: integarte with <a href="http://plantuml.com/class-diagram">PlantUML</a>.
520 <li>FEATURE: add dark theme
522 <li>FEATURE: sort Class fields by alphabet
524 <li>FEATURE: visualize also concrete field values so it could be used as
525 ultra cool runtime logging framework
527 <li>FEATURE: possibility to visualize structure and data from JVM
530 <li>FEATURE: possibility to attach to remote process to visualize
531 data/structure using JVM debug port and mechanism.
533 <li>FEATURE: possibility to attach to JVM using JVM agent
535 <li>FEATURE: possibility to script javainspect behavior
537 <li>FEATURE: possibility to select classes/fields/values to be
538 visualized in SQL like syntax
540 <li>FEATURE: configurable maven plugin to generate graphs as part of the
541 project build/release process
546 </div><div class="col-md-3"><nav id="table-of-contents">
547 <div id="text-table-of-contents" class="bs-docs-sidebar">
549 <li><a href="#sec-1">1. General</a></li>
550 <li><a href="#sec-2">2. Example graphs</a></li>
551 <li><a href="#sec-3">3. Usage</a>
553 <li><a href="#sec-3-1">3.1. example 1: individually picked objects</a></li>
554 <li><a href="#sec-3-2">3.2. example 2: scan java code, apply filters</a></li>
555 <li><a href="#sec-3-3">3.3. example 3: GraphViz embedded in another project</a></li>
558 <li><a href="#sec-4">4. Embedding JavaInspect in your Maven project</a></li>
559 <li><a href="#sec-5">5. Requirements</a></li>
560 <li><a href="#sec-6">6. TO DO</a></li>
565 <footer id="postamble" class="">
566 <div><p class="author">Author: Svjatoslav Agejenko</p>
567 <p class="date">Created: 2017-11-29 Wed 23:51</p>
568 <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>