dfef6db750eca7a9e3eb2fe069b00d8f7aedb850
[javainspect.git] / doc / index.html
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
5 <head>
6 <!-- 2022-02-20 Sun 20:27 -->
7 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
8 <meta name="viewport" content="width=device-width, initial-scale=1" />
9 <title>JavaInspect - Utility to visualize java software</title>
10 <meta name="generator" content="Org mode" />
11 <meta name="author" content="Svjatoslav Agejenko" />
12 <style type="text/css">
13  <!--/*--><![CDATA[/*><!--*/
14   .title  { text-align: center;
15              margin-bottom: .2em; }
16   .subtitle { text-align: center;
17               font-size: medium;
18               font-weight: bold;
19               margin-top:0; }
20   .todo   { font-family: monospace; color: red; }
21   .done   { font-family: monospace; color: green; }
22   .priority { font-family: monospace; color: orange; }
23   .tag    { background-color: #eee; font-family: monospace;
24             padding: 2px; font-size: 80%; font-weight: normal; }
25   .timestamp { color: #bebebe; }
26   .timestamp-kwd { color: #5f9ea0; }
27   .org-right  { margin-left: auto; margin-right: 0px;  text-align: right; }
28   .org-left   { margin-left: 0px;  margin-right: auto; text-align: left; }
29   .org-center { margin-left: auto; margin-right: auto; text-align: center; }
30   .underline { text-decoration: underline; }
31   #postamble p, #preamble p { font-size: 90%; margin: .2em; }
32   p.verse { margin-left: 3%; }
33   pre {
34     border: 1px solid #ccc;
35     box-shadow: 3px 3px 3px #eee;
36     padding: 8pt;
37     font-family: monospace;
38     overflow: auto;
39     margin: 1.2em;
40   }
41   pre.src {
42     position: relative;
43     overflow: auto;
44     padding-top: 1.2em;
45   }
46   pre.src:before {
47     display: none;
48     position: absolute;
49     background-color: white;
50     top: -10px;
51     right: 10px;
52     padding: 3px;
53     border: 1px solid black;
54   }
55   pre.src:hover:before { display: inline; margin-top: 14px;}
56   /* Languages per Org manual */
57   pre.src-asymptote:before { content: 'Asymptote'; }
58   pre.src-awk:before { content: 'Awk'; }
59   pre.src-C:before { content: 'C'; }
60   /* pre.src-C++ doesn't work in CSS */
61   pre.src-clojure:before { content: 'Clojure'; }
62   pre.src-css:before { content: 'CSS'; }
63   pre.src-D:before { content: 'D'; }
64   pre.src-ditaa:before { content: 'ditaa'; }
65   pre.src-dot:before { content: 'Graphviz'; }
66   pre.src-calc:before { content: 'Emacs Calc'; }
67   pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
68   pre.src-fortran:before { content: 'Fortran'; }
69   pre.src-gnuplot:before { content: 'gnuplot'; }
70   pre.src-haskell:before { content: 'Haskell'; }
71   pre.src-hledger:before { content: 'hledger'; }
72   pre.src-java:before { content: 'Java'; }
73   pre.src-js:before { content: 'Javascript'; }
74   pre.src-latex:before { content: 'LaTeX'; }
75   pre.src-ledger:before { content: 'Ledger'; }
76   pre.src-lisp:before { content: 'Lisp'; }
77   pre.src-lilypond:before { content: 'Lilypond'; }
78   pre.src-lua:before { content: 'Lua'; }
79   pre.src-matlab:before { content: 'MATLAB'; }
80   pre.src-mscgen:before { content: 'Mscgen'; }
81   pre.src-ocaml:before { content: 'Objective Caml'; }
82   pre.src-octave:before { content: 'Octave'; }
83   pre.src-org:before { content: 'Org mode'; }
84   pre.src-oz:before { content: 'OZ'; }
85   pre.src-plantuml:before { content: 'Plantuml'; }
86   pre.src-processing:before { content: 'Processing.js'; }
87   pre.src-python:before { content: 'Python'; }
88   pre.src-R:before { content: 'R'; }
89   pre.src-ruby:before { content: 'Ruby'; }
90   pre.src-sass:before { content: 'Sass'; }
91   pre.src-scheme:before { content: 'Scheme'; }
92   pre.src-screen:before { content: 'Gnu Screen'; }
93   pre.src-sed:before { content: 'Sed'; }
94   pre.src-sh:before { content: 'shell'; }
95   pre.src-sql:before { content: 'SQL'; }
96   pre.src-sqlite:before { content: 'SQLite'; }
97   /* additional languages in org.el's org-babel-load-languages alist */
98   pre.src-forth:before { content: 'Forth'; }
99   pre.src-io:before { content: 'IO'; }
100   pre.src-J:before { content: 'J'; }
101   pre.src-makefile:before { content: 'Makefile'; }
102   pre.src-maxima:before { content: 'Maxima'; }
103   pre.src-perl:before { content: 'Perl'; }
104   pre.src-picolisp:before { content: 'Pico Lisp'; }
105   pre.src-scala:before { content: 'Scala'; }
106   pre.src-shell:before { content: 'Shell Script'; }
107   pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
108   /* additional language identifiers per "defun org-babel-execute"
109        in ob-*.el */
110   pre.src-cpp:before  { content: 'C++'; }
111   pre.src-abc:before  { content: 'ABC'; }
112   pre.src-coq:before  { content: 'Coq'; }
113   pre.src-groovy:before  { content: 'Groovy'; }
114   /* additional language identifiers from org-babel-shell-names in
115      ob-shell.el: ob-shell is the only babel language using a lambda to put
116      the execution function name together. */
117   pre.src-bash:before  { content: 'bash'; }
118   pre.src-csh:before  { content: 'csh'; }
119   pre.src-ash:before  { content: 'ash'; }
120   pre.src-dash:before  { content: 'dash'; }
121   pre.src-ksh:before  { content: 'ksh'; }
122   pre.src-mksh:before  { content: 'mksh'; }
123   pre.src-posh:before  { content: 'posh'; }
124   /* Additional Emacs modes also supported by the LaTeX listings package */
125   pre.src-ada:before { content: 'Ada'; }
126   pre.src-asm:before { content: 'Assembler'; }
127   pre.src-caml:before { content: 'Caml'; }
128   pre.src-delphi:before { content: 'Delphi'; }
129   pre.src-html:before { content: 'HTML'; }
130   pre.src-idl:before { content: 'IDL'; }
131   pre.src-mercury:before { content: 'Mercury'; }
132   pre.src-metapost:before { content: 'MetaPost'; }
133   pre.src-modula-2:before { content: 'Modula-2'; }
134   pre.src-pascal:before { content: 'Pascal'; }
135   pre.src-ps:before { content: 'PostScript'; }
136   pre.src-prolog:before { content: 'Prolog'; }
137   pre.src-simula:before { content: 'Simula'; }
138   pre.src-tcl:before { content: 'tcl'; }
139   pre.src-tex:before { content: 'TeX'; }
140   pre.src-plain-tex:before { content: 'Plain TeX'; }
141   pre.src-verilog:before { content: 'Verilog'; }
142   pre.src-vhdl:before { content: 'VHDL'; }
143   pre.src-xml:before { content: 'XML'; }
144   pre.src-nxml:before { content: 'XML'; }
145   /* add a generic configuration mode; LaTeX export needs an additional
146      (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
147   pre.src-conf:before { content: 'Configuration File'; }
148
149   table { border-collapse:collapse; }
150   caption.t-above { caption-side: top; }
151   caption.t-bottom { caption-side: bottom; }
152   td, th { vertical-align:top;  }
153   th.org-right  { text-align: center;  }
154   th.org-left   { text-align: center;   }
155   th.org-center { text-align: center; }
156   td.org-right  { text-align: right;  }
157   td.org-left   { text-align: left;   }
158   td.org-center { text-align: center; }
159   dt { font-weight: bold; }
160   .footpara { display: inline; }
161   .footdef  { margin-bottom: 1em; }
162   .figure { padding: 1em; }
163   .figure p { text-align: center; }
164   .equation-container {
165     display: table;
166     text-align: center;
167     width: 100%;
168   }
169   .equation {
170     vertical-align: middle;
171   }
172   .equation-label {
173     display: table-cell;
174     text-align: right;
175     vertical-align: middle;
176   }
177   .inlinetask {
178     padding: 10px;
179     border: 2px solid gray;
180     margin: 10px;
181     background: #ffffcc;
182   }
183   #org-div-home-and-up
184    { text-align: right; font-size: 70%; white-space: nowrap; }
185   textarea { overflow-x: auto; }
186   .linenr { font-size: smaller }
187   .code-highlighted { background-color: #ffff00; }
188   .org-info-js_info-navigation { border-style: none; }
189   #org-info-js_console-label
190     { font-size: 10px; font-weight: bold; white-space: nowrap; }
191   .org-info-js_search-highlight
192     { background-color: #ffff00; color: #000000; font-weight: bold; }
193   .org-svg { width: 90%; }
194   /*]]>*/-->
195 </style>
196 <link href="https://bootswatch.com/3/darkly/bootstrap.min.css" rel="stylesheet">
197 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
198 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
199 <style type="text/css">
200 footer {background-color: #111 !important;}
201 pre {background-color: #111; color: #ccc;}
202 </style>
203 <link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
204 <script type="text/javascript">
205 // @license magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt Public Domain
206 <!--/*--><![CDATA[/*><!--*/
207      function CodeHighlightOn(elem, id)
208      {
209        var target = document.getElementById(id);
210        if(null != target) {
211          elem.classList.add("code-highlighted");
212          target.classList.add("code-highlighted");
213        }
214      }
215      function CodeHighlightOff(elem, id)
216      {
217        var target = document.getElementById(id);
218        if(null != target) {
219          elem.classList.remove("code-highlighted");
220          target.classList.remove("code-highlighted");
221        }
222      }
223     /*]]>*///-->
224 // @license-end
225 </script>
226 </head>
227 <body>
228 <div id="content">
229 <h1 class="title">JavaInspect - Utility to visualize java software</h1>
230 <div id="table-of-contents">
231 <h2>Table of Contents</h2>
232 <div id="text-table-of-contents">
233 <ul>
234 <li><a href="#orga6751f6">1. General</a>
235 <ul>
236 <li><a href="#org926416f">1.1. Source code</a></li>
237 </ul>
238 </li>
239 <li><a href="#org65fe059">2. Goal and operating principle</a></li>
240 <li><a href="#org7fe659d">3. Example graphs</a></li>
241 <li><a href="#org163c1cb">4. Installation</a></li>
242 <li><a href="#orgaa497bf">5. Usage</a>
243 <ul>
244 <li><a href="#org68d4e58">5.1. Usage as commandline utility</a>
245 <ul>
246 <li><a href="#org4c2e5f8">5.1.1. Available commandline arguments</a></li>
247 <li><a href="#orgceb0cbf">5.1.2. Specifying classes to render</a></li>
248 </ul>
249 </li>
250 <li><a href="#org8037e80">5.2. Usage via Java API</a>
251 <ul>
252 <li><a href="#org56db96c">5.2.1. Example 1: individually picked objects</a></li>
253 <li><a href="#org419624a">5.2.2. Example 2: GraphViz embedded in another project</a></li>
254 <li><a href="#orgdf4f0b1">5.2.3. Embedding JavaInspect in your Maven project</a></li>
255 </ul>
256 </li>
257 </ul>
258 </li>
259 <li><a href="#org556c7e2">6. TO DO</a></li>
260 <li><a href="#orgf7baf29">7. See also</a></li>
261 </ul>
262 </div>
263 </div>
264
265 <div id="outline-container-orga6751f6" class="outline-2">
266 <h2 id="orga6751f6"><span class="section-number-2">1</span> General</h2>
267 <div class="outline-text-2" id="text-1">
268 <ul class="org-ul">
269 <li>This program is free software: you can redistribute it and/or modify
270 it under the terms of the <a href="https://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public License</a> as
271 published by the Free Software Foundation, either version 3 of the
272 License, or (at your option) any later version.</li>
273
274 <li>Program authors:
275 <ul class="org-ul">
276 <li>Svjatoslav Agejenko
277 <ul class="org-ul">
278 <li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a></li>
279 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a></li>
280 <li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a></li>
281 </ul></li>
282
283 <li>Tony Bargnesi
284 <ul class="org-ul">
285 <li>GitHub fork for the project:
286 <a href="https://github.com/abargnesi/javainspect">https://github.com/abargnesi/javainspect</a></li>
287 </ul></li>
288 </ul></li>
289 </ul>
290 </div>
291
292 <div id="outline-container-org926416f" class="outline-3">
293 <h3 id="org926416f"><span class="section-number-3">1.1</span> Source code</h3>
294 <div class="outline-text-3" id="text-1-1">
295 <ul class="org-ul">
296 <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></li>
297
298 <li><a href="https://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=summary">Browse Git repository online</a></li>
299
300 <li><p>
301 Clone Git repository using command:
302 </p>
303 <pre class="example">
304 git clone https://www2.svjatoslav.eu/git/javainspect.git
305 </pre></li>
306 </ul>
307 </div>
308 </div>
309 </div>
310
311 <div id="outline-container-org65fe059" class="outline-2">
312 <h2 id="org65fe059"><span class="section-number-2">2</span> Goal and operating principle</h2>
313 <div class="outline-text-2" id="text-2">
314 <p>
315 Goal: simplify/speed up understanding the computer program code by
316 automatically visualizing its structure.
317 </p>
318
319 <p>
320 <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>.
321 </p>
322
323 <p>
324 JavaInspect can be used as a <a href="#org68d4e58">standalone commandline utility</a> as well as
325 <a href="#org8037e80">java library</a>. JavaInspect uses primarily Java built-in reflection to
326 discover and visualize any part of Java program.
327 </p>
328
329 <p>
330 JavaInspect currently has no graphical user interface, configuration
331 files, embedded scripting support, direct Maven, Gradle or Ant
332 integration. See <a href="#orgaa497bf">usage</a> to learn how to instuct Javainspect what to do.
333 </p>
334
335 <p>
336 After discovering application structure and optionally filtering out
337 unimportant parts, JavaInspect produces GraphViz dot file that
338 describes data to be visualized. Then launches <a href="https://graphviz.org/">GraphViz</a> to generate
339 bitmap graph in PNG or SVG format.
340 </p>
341
342 <p>
343 Notes:
344 </p>
345 <ul class="org-ul">
346 <li>JavaInspect is developed and tested so far only on GNU/Linux.</li>
347 </ul>
348 </div>
349 </div>
350
351 <div id="outline-container-org7fe659d" class="outline-2">
352 <h2 id="org7fe659d"><span class="section-number-2">3</span> Example graphs</h2>
353 <div class="outline-text-2" id="text-3">
354 <ul class="org-ul">
355 <li><p>
356 A very simple example:
357 </p>
358
359
360 <div id="org5c02965" class="figure">
361 <p><a href="example.png"><img src="example-thumbnail.png" alt="example-thumbnail.png" /></a>
362 </p>
363 </div>
364
365 <p>
366 Graph legend:
367 </p>
368
369
370 <div id="org32c854a" class="figure">
371 <p><img src="legend.png" alt="legend.png" />
372 </p>
373 </div></li>
374 </ul>
375
376
377 <ul class="org-ul">
378 <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>.</li>
379 </ul>
380 </div>
381 </div>
382
383 <div id="outline-container-org163c1cb" class="outline-2">
384 <h2 id="org163c1cb"><span class="section-number-2">4</span> Installation</h2>
385 <div class="outline-text-2" id="text-4">
386 <p>
387 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
388 </p>
389
390 <p>
391 On Ubuntu/Debian GraphViz can be installed using:
392 </p>
393 <div class="org-src-container">
394 <pre class="src src-sh">sudo apt-get install graphviz
395 </pre>
396 </div>
397
398 <p>
399 To use JavaInspect via Java API, no further installation is
400 needed. JavaInspect will be embedded into your project as dependency.
401 This is described in <a href="#org8037e80">usage via Java API</a>. It will expect GraphViz to be
402 available in the system.
403 </p>
404
405 <p>
406 To use JavaInspect as a commandline tool, JavaInspect source
407 repository has to be cloned locally: See <a href="#org926416f">Source code</a>.
408 </p>
409
410 <p>
411 Then study and execute installation script:
412 </p>
413 <pre class="example">
414 commandline launcher/install
415 </pre>
416
417
418 <p>
419 After installation, new commandline tool should be available
420 </p>
421 <pre class="example">
422 javainspect
423 </pre>
424
425
426 <p>
427 Quick commandline usage help can be viewed by issuing
428 </p>
429 <pre class="example">
430 javainspect --help
431 </pre>
432 </div>
433 </div>
434
435 <div id="outline-container-orgaa497bf" class="outline-2">
436 <h2 id="orgaa497bf"><span class="section-number-2">5</span> Usage</h2>
437 <div class="outline-text-2" id="text-5">
438 <p>
439 JavaInspect can be controlled in 2 different ways:
440 </p>
441 <ul class="org-ul">
442 <li><a href="#org68d4e58">as standalone commandline utility</a></li>
443 <li><a href="#org8037e80">as embedded Java library via Java API</a></li>
444 </ul>
445 </div>
446
447 <div id="outline-container-org68d4e58" class="outline-3">
448 <h3 id="org68d4e58"><span class="section-number-3">5.1</span> Usage as commandline utility</h3>
449 <div class="outline-text-3" id="text-5-1">
450 </div>
451 <div id="outline-container-org4c2e5f8" class="outline-4">
452 <h4 id="org4c2e5f8"><span class="section-number-4">5.1.1</span> Available commandline arguments</h4>
453 <div class="outline-text-4" id="text-5-1-1">
454 <p class="verse">
455 -j (existing files)&#x2026;<br />
456 &#xa0;&#xa0;&#xa0;&#xa0;JAR file(s) to render.<br />
457 <br />
458 -c (existing directories)&#x2026;<br />
459 &#xa0;&#xa0;&#xa0;&#xa0;Classpath directories<br />
460 <br />
461 -n (string)<br />
462 &#xa0;&#xa0;&#xa0;&#xa0;Graph name. (default: "graph")<br />
463 <br />
464 &#x2013;debug<br />
465 &#xa0;&#xa0;&#xa0;&#xa0;Show debug info.<br />
466 <br />
467 -h, &#x2013;help<br />
468 &#xa0;&#xa0;&#xa0;&#xa0;Show commandline usage help.<br />
469 <br />
470 -k<br />
471 &#xa0;&#xa0;&#xa0;&#xa0;Keep dot file.<br />
472 <br />
473 -ho<br />
474 &#xa0;&#xa0;&#xa0;&#xa0;Hide orphaned classes.<br />
475 <br />
476 -w (one to many strings)&#x2026;<br />
477 &#xa0;&#xa0;&#xa0;&#xa0;Whitelist glob(s).<br />
478 <br />
479 -b (one to many strings)&#x2026;<br />
480 &#xa0;&#xa0;&#xa0;&#xa0;Blacklist glob(s).<br />
481 <br />
482 -r (one to many strings)&#x2026;<br />
483 &#xa0;&#xa0;&#xa0;&#xa0;root class(es).<br />
484 <br />
485 -d (existing directory)<br />
486 &#xa0;&#xa0;&#xa0;&#xa0;Target directory. Default is current directory.<br />
487 <br />
488 -t (options: png, svg)<br />
489 &#xa0;&#xa0;&#xa0;&#xa0;Target image type. Default is: svg.<br />
490 </p>
491 </div>
492 </div>
493 <div id="outline-container-orgceb0cbf" class="outline-4">
494 <h4 id="orgceb0cbf"><span class="section-number-4">5.1.2</span> Specifying classes to render</h4>
495 <div class="outline-text-4" id="text-5-1-2">
496 <p>
497 Normal Java application has immense complexity. In addition to code
498 that was directly written by particular project developers, lots of
499 functionality is typically added as frameworks or libraries to the
500 project. In addition there is significant Java standard library.
501 </p>
502
503 <p>
504 Because JavaInspect uses reflection, it does not easily distinguish
505 between those. In normal situation you would rather want to visualize
506 only code that was developed specifically for your project and leave
507 frameworks like Spring etc. out. If you visualize all classes that are
508 possibly reachable from you project, you will easily get huge and
509 incomprehensible graph.
510 </p>
511
512 <p>
513 JavaInspect can digest compiled Java classes in 2 modes:
514 </p>
515 <ol class="org-ol">
516 <li>Provide list of Jar files. Use <b>-j</b> option.</li>
517 <li>Provide list of filesystem directories that can be used as
518 classpath root. Use <b>-c</b> option.</li>
519 </ol>
520
521 <p>
522 Currently JavaInspect uses following algorithm to add classes to
523 rendered graph:
524 </p>
525
526 <ul class="org-ul">
527 <li>All classes that were found in Jar files are added to graph by default.</li>
528 <li>None of the classes that were found in filesystem directories are
529 added to the graph by default (unless explicitly referenced). (TODO:
530 for consistency it would be better to add them too by default)</li>
531 <li>If whitelist is specified (<b>-w</b> option) everything that is not
532 matched by whitelist pattern(s) will be removed from the graph.</li>
533 <li>If blacklist is specified (<b>-b</b> option) everything that is matched
534 by blacklist pattern(s) will be removed from the graph.</li>
535 <li>Root classes can be specified using <b>-r</b> option. Root classes will
536 be added to the graph. JavaInspect will then try to recursively
537 discover all classes that were referenced by root class and add
538 those also to the graph.</li>
539 </ul>
540 </div>
541 </div>
542 </div>
543
544 <div id="outline-container-org8037e80" class="outline-3">
545 <h3 id="org8037e80"><span class="section-number-3">5.2</span> Usage via Java API</h3>
546 <div class="outline-text-3" id="text-5-2">
547 <p>
548 Requires that classes to be visualised are available in the classpath.
549 </p>
550
551 <p>
552 To get JavaInspect into same classpath with your projecs I so far came
553 up with 2 solutions:
554 </p>
555
556 <ol class="org-ol">
557 <li>Add JavaInspect library in your project as a dependency.</li>
558
559 <li>Create new Java project for the purpose visualizing your other
560 projects and include JavaInspect and your projecs binary artifacts
561 (Jar's) into new project classpath. Built binary Jar's (with no
562 source code) are sufficient because JavaInspect operates via
563 reflection.</li>
564 </ol>
565
566 <p>
567 Simple Java based control/configuration code needs to be written for
568 each project. I usually put such code into directories devoted for
569 JUnit tests. Because it needs not to be compiled/embedded into final
570 product or project artifact I'm just willing to visualize.
571 </p>
572
573 <p>
574 Control code in general does the following:
575 </p>
576 <ol class="org-ol">
577 <li>Create graph object.</li>
578 <li>Java reflection/classloaders does not provide mechanism for
579 discovering all classes under given package. Therefore you need to
580 declare at least some classes to be added to the graph by manually
581 adding individual classes to the graph. For every class added to
582 the graph, GraphViz will recursively inspect it and add all
583 referecned classes to the graph as well.</li>
584 <li>Graphs easilly get very big and complex so optionally we filter
585 important code using classname <a href="https://en.wikipedia.org/wiki/Glob_(programming)">glob</a> patterns based blacklist and/or
586 whitelist.</li>
587 <li>Optionally we can tune some rendering parameters like:
588 <ul class="org-ul">
589 <li>Possibility to remove orphaned classes (classes with no
590 references) from the graph.</li>
591 <li>Specify target directory for generated visualization
592 files. (Default is current directory)</li>
593 <li>Keep intermediate GraphViz dot file for later inspection.</li>
594 </ul></li>
595 <li>Render graph.</li>
596 </ol>
597 </div>
598
599
600 <div id="outline-container-org56db96c" class="outline-4">
601 <h4 id="org56db96c"><span class="section-number-4">5.2.1</span> Example 1: individually picked objects</h4>
602 <div class="outline-text-4" id="text-5-2-1">
603 <p>
604 This example demonstrates generating of class graph from hand picked
605 classes and visualizing GraphViz itself.
606 </p>
607
608 <div class="org-src-container">
609 <pre class="src src-java">
610 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
611 <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>();
612
613 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Add some random object to the graph. GraphViz will detect Class from</span>
614 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">the object.</span>
615 graph.add(graph);
616
617 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Also add some random class to the graph.</span>
618 graph.add(Utils.<span style="color: #F92672;">class</span>);
619
620 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Keep intermediary GraphViz DOT file for reference.</span>
621 graph.setKeepDotFile(<span style="color: #FF80F4;">true</span>);
622
623 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect.png" to the user Desktop</span>
624 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">directory</span>
625 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
626
627 </pre>
628 </div>
629
630 <p>
631 Note: if desired, more compact version of the above:
632 </p>
633 <div class="org-src-container">
634 <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>)
635                 .setKeepDotFile(<span style="color: #FF80F4;">true</span>).generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
636 </pre>
637 </div>
638
639
640 <p>
641 Result:
642 </p>
643 <ul class="org-ul">
644 <li>Generated DOT file: <a href="JavaInspect.dot">JavaInspect.dot</a></li>
645 <li>Generated PNG image: <a href="JavaInspect.png">JavaInspect.png</a></li>
646 </ul>
647 </div>
648 </div>
649
650 <div id="outline-container-org419624a" class="outline-4">
651 <h4 id="org419624a"><span class="section-number-4">5.2.2</span> Example 2: GraphViz embedded in another project</h4>
652 <div class="outline-text-4" id="text-5-2-2">
653 <ol class="org-ol">
654 <li>Download project Sixth <a href="https://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz">code snapshot</a>.</li>
655 <li>Inspect and run <b>DataGraph.java</b>.</li>
656 </ol>
657 </div>
658 </div>
659
660 <div id="outline-container-orgdf4f0b1" class="outline-4">
661 <h4 id="orgdf4f0b1"><span class="section-number-4">5.2.3</span> Embedding JavaInspect in your Maven project</h4>
662 <div class="outline-text-4" id="text-5-2-3">
663 <p>
664 Declare JavaInspect as dependency:
665 </p>
666 <div class="org-src-container">
667 <pre class="src src-xml">&lt;<span style="color: #A6E22E;">dependencies</span>&gt;
668     ...
669     &lt;<span style="color: #A6E22E;">dependency</span>&gt;
670         &lt;<span style="color: #A6E22E;">groupId</span>&gt;eu.svjatoslav&lt;/<span style="color: #A6E22E;">groupId</span>&gt;
671         &lt;<span style="color: #A6E22E;">artifactId</span>&gt;javainspect&lt;/<span style="color: #A6E22E;">artifactId</span>&gt;
672         &lt;<span style="color: #A6E22E;">version</span>&gt;1.7&lt;/<span style="color: #A6E22E;">version</span>&gt;
673     &lt;/<span style="color: #A6E22E;">dependency</span>&gt;
674     ...
675 &lt;/<span style="color: #A6E22E;">dependencies</span>&gt;
676 </pre>
677 </div>
678
679
680 <p>
681 Add Maven repository to retrieve artifact from:
682 </p>
683 <div class="org-src-container">
684 <pre class="src src-xml">&lt;<span style="color: #A6E22E;">repositories</span>&gt;
685     ...
686     &lt;<span style="color: #A6E22E;">repository</span>&gt;
687         &lt;<span style="color: #A6E22E;">id</span>&gt;svjatoslav.eu&lt;/<span style="color: #A6E22E;">id</span>&gt;
688         &lt;<span style="color: #A6E22E;">name</span>&gt;Svjatoslav repository&lt;/<span style="color: #A6E22E;">name</span>&gt;
689         &lt;<span style="color: #A6E22E;">url</span>&gt;http://www2.svjatoslav.eu/maven/&lt;/<span style="color: #A6E22E;">url</span>&gt;
690     &lt;/<span style="color: #A6E22E;">repository</span>&gt;
691     ...
692 &lt;/<span style="color: #A6E22E;">repositories</span>&gt;
693 </pre>
694 </div>
695 </div>
696 </div>
697 </div>
698 </div>
699
700 <div id="outline-container-org556c7e2" class="outline-2">
701 <h2 id="org556c7e2"><span class="section-number-2">6</span> TO DO</h2>
702 <div class="outline-text-2" id="text-6">
703 <p>
704 Note: Because this is side project (and I have many of them) I can
705 only contribute few hours per year at average. Any help is welcome.  A
706 LOT of cool ideas could be implemented. For intstance:
707 </p>
708
709 <ul class="org-ul">
710 <li>BUG: Should not hide references if there are too many of them to
711 classes if referring classes are not visible anyway because of
712 blacklist/whitelist rules. Basically reference counting should
713 exclude not visible classes.</li>
714
715 <li>BUG: Orphaned class removal does not work always. There are many
716 bugs and corner cases to find and fix still.</li>
717
718 <li>BUG: Code is not very readable. Document and refactor for better
719 maintainability.</li>
720
721 <li>FEATURE: Create installable DEB package.
722 <ul class="org-ul">
723 <li>Submit it to some Debian developer for integration or become
724 Debian package maintainer.</li>
725 </ul></li>
726
727 <li>FEATURE: Make it modular. That is: central part, an application
728 model could be standalone and serializable.
729
730 <ul class="org-ul">
731 <li>There could be multiple ways to acquire model:
732 <ul class="org-ul">
733 <li>By introspecting application via Java reflections (current mode
734 of operation).</li>
735 <li>By parsing java source. (unfinished)</li>
736 </ul></li>
737
738 <li>There could be ways to manipulate model:
739 <ul class="org-ul">
740 <li>Store/load/compare.</li>
741 <li>Trim uninteresting parts.</li>
742 <li>Highlight important parts.</li>
743 </ul></li>
744
745 <li>There could be multiple ways to render model:
746 <ul class="org-ul">
747 <li>PNG/SVG (currently implemented)</li>
748 <li>PlantUML (TODO)</li>
749 <li>Interactive 3D visualization (TODO)</li>
750 </ul></li>
751 </ul></li>
752
753 <li>FEATURE: Implement (or integrate existing java parser
754 <a href="https://javaparser.org/">https://javaparser.org/</a>) to be able to produce code visualizations
755 based on source code (in addition to current reflection based
756 approach).</li>
757
758 <li>FEATURE: Integarte with <a href="http://plantuml.com/class-diagram">PlantUML</a>.</li>
759
760 <li>FEATURE: Add dark theme for generated graphs.</li>
761
762 <li>FEATURE: Sort Class fields by alphabet.</li>
763
764 <li>FEATURE: Visualize also concrete field values so it could be used as
765 ultra cool runtime logging/debugging framework.</li>
766
767 <li>FEATURE: Possibility to visualize structure and data from JVM
768 snapshot.</li>
769
770 <li>FEATURE: Possibility to attach to remote process to visualize
771 data/structure using JVM debug port and mechanism.</li>
772
773 <li>FEATURE: Possibility to attach to JVM using JVM agent.</li>
774
775 <li>FEATURE: Possibility to inspect graphs in 3D using <a href="https://www3.svjatoslav.eu/projects/sixth-3d/">Sixth 3D engine</a>.</li>
776
777 <li>FEATURE: Possibility to select classes/fields/values to be
778 visualized in some graph query language. For greater flexibility in
779 comparison to currently supported glob syntax.</li>
780
781 <li>FEATURE: Add option to control JavaInspect via JSON or XML config
782 file. For example different graphs for given project could be
783 defined once in plain text config, possibly with the aid of some
784 interactive utility. Then defined graphs could be updated as part of
785 project build or release process.</li>
786
787 <li>FEATURE: Configurable maven plugin to generate graphs as part of the
788 project build/release process.</li>
789 </ul>
790 </div>
791 </div>
792 <div id="outline-container-orgf7baf29" class="outline-2">
793 <h2 id="orgf7baf29"><span class="section-number-2">7</span> See also</h2>
794 <div class="outline-text-2" id="text-7">
795 <p>
796 Similar or alternative solutions:
797 </p>
798 <ul class="org-ul">
799 <li><a href="http://www.class-visualizer.net/">http://www.class-visualizer.net/</a></li>
800 <li><a href="https://github.com/pahen/madge">Madge - similar tool for JavaScript</a></li>
801 </ul>
802 </div>
803 </div>
804 </div>
805 <div id="postamble" class="status">
806 <p class="author">Author: Svjatoslav Agejenko</p>
807 <p class="date">Created: 2022-02-20 Sun 20:27</p>
808 <p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
809 </div>
810 </body>
811 </html>