f011ad86b9ade1cff8ed7a594eeae98dc03bd26b
[javainspect.git] / doc / index.html
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <title>JavaInspect - Utility to visualize java software</title>
5 <!-- 2017-11-29 Wed 23:51 -->
6 <meta charset="utf-8">
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;}
16 </style>
17 <style type="text/css">
18 /* org mode styles on top of twbs */
19
20 html {
21     position: relative;
22     min-height: 100%;
23 }
24
25 body {
26     font-size: 18px;
27     margin-bottom: 105px;
28 }
29
30 footer {
31     position: absolute;
32     bottom: 0;
33     width: 100%;
34     height: 101px;
35     background-color: #f5f5f5;
36 }
37
38 footer > div {
39     padding: 10px;
40 }
41
42 footer p {
43     margin: 0 0 5px;
44     text-align: center;
45     font-size: 16px;
46 }
47
48 #table-of-contents {
49     margin-top: 20px;
50     margin-bottom: 20px;
51 }
52
53 blockquote p {
54     font-size: 18px;
55 }
56
57 pre {
58     font-size: 16px;
59 }
60
61 .footpara {
62     display: inline-block;
63 }
64
65 figcaption {
66   font-size: 16px;
67   color: #666;
68   font-style: italic;
69   padding-bottom: 15px;
70 }
71
72 /* from twbs docs */
73
74 .bs-docs-sidebar.affix {
75     position: static;
76 }
77 @media (min-width: 768px) {
78     .bs-docs-sidebar {
79         padding-left: 20px;
80     }
81 }
82
83 /* All levels of nav */
84 .bs-docs-sidebar .nav > li > a {
85     display: block;
86     padding: 4px 20px;
87     font-size: 14px;
88     font-weight: 500;
89     color: #999;
90 }
91 .bs-docs-sidebar .nav > li > a:hover,
92 .bs-docs-sidebar .nav > li > a:focus {
93     padding-left: 19px;
94     color: #A1283B;
95     text-decoration: none;
96     background-color: transparent;
97     border-left: 1px solid #A1283B;
98 }
99 .bs-docs-sidebar .nav > .active > a,
100 .bs-docs-sidebar .nav > .active:hover > a,
101 .bs-docs-sidebar .nav > .active:focus > a {
102     padding-left: 18px;
103     font-weight: bold;
104     color: #A1283B;
105     background-color: transparent;
106     border-left: 2px solid #A1283B;
107 }
108
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;
113 }
114 .bs-docs-sidebar .nav .nav > li > a {
115     padding-top: 1px;
116     padding-bottom: 1px;
117     padding-left: 30px;
118     font-size: 12px;
119     font-weight: normal;
120 }
121 .bs-docs-sidebar .nav .nav > li > a:hover,
122 .bs-docs-sidebar .nav .nav > li > a:focus {
123     padding-left: 29px;
124 }
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 {
128     padding-left: 28px;
129     font-weight: 500;
130 }
131
132 /* Nav: third level (shown on .active) */
133 .bs-docs-sidebar .nav .nav .nav {
134     padding-bottom: 10px;
135 }
136 .bs-docs-sidebar .nav .nav .nav > li > a {
137     padding-top: 1px;
138     padding-bottom: 1px;
139     padding-left: 40px;
140     font-size: 12px;
141     font-weight: normal;
142 }
143 .bs-docs-sidebar .nav .nav .nav > li > a:hover,
144 .bs-docs-sidebar .nav .nav .nav > li > a:focus {
145     padding-left: 39px;
146 }
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 {
150     padding-left: 38px;
151     font-weight: 500;
152 }
153
154 /* Show and affix the side nav when space allows it */
155 @media (min-width: 992px) {
156     .bs-docs-sidebar .nav > .active > ul {
157         display: block;
158     }
159     /* Widen the fixed sidebar */
160     .bs-docs-sidebar.affix,
161     .bs-docs-sidebar.affix-bottom {
162         width: 213px;
163     }
164     .bs-docs-sidebar.affix {
165         position: fixed; /* Undo the static from mobile first approach */
166         top: 20px;
167     }
168     .bs-docs-sidebar.affix-bottom {
169         position: absolute; /* Undo the static from mobile first approach */
170     }
171     .bs-docs-sidebar.affix .bs-docs-sidenav,.bs-docs-sidebar.affix-bottom .bs-docs-sidenav {
172         margin-top: 0;
173         margin-bottom: 0
174     }
175 }
176 @media (min-width: 1200px) {
177     /* Widen the fixed sidebar again */
178     .bs-docs-sidebar.affix-bottom,
179     .bs-docs-sidebar.affix {
180         width: 263px;
181     }
182 }
183 </style>
184 <script type="text/javascript">
185 $(function() {
186     'use strict';
187
188     $('.bs-docs-sidebar li').first().addClass('active');
189
190     $(document.body).scrollspy({target: '.bs-docs-sidebar'});
191
192     $('.bs-docs-sidebar').affix();
193 });
194 </script>
195 </head>
196 <body>
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>
199 <hr >
200 <ul class="org-ul">
201 <li><a href="http://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=snapshot;h=HEAD;sf=tgz">download latest snapshot</a>
202 </li>
203
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.
207 </li>
208
209 <li>Program author:
210 <ul class="org-ul">
211 <li>Svjatoslav Agejenko
212 </li>
213 <li>Homepage: <a href="http://svjatoslav.eu">http://svjatoslav.eu</a>
214 </li>
215 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a>
216 </li>
217 </ul>
218 </li>
219
220 <li><a href="http://www.svjatoslav.eu/programs.jsp">other applications hosted at svjatoslav.eu</a>
221 </li>
222 </ul>
223
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">
227 <p>
228 Goal: simplify/speed up understanding the computer program code by
229 automatically visualizing its structure.
230 </p>
231
232 <p>
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.
236 </p>
237
238 <p>
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.
242 </p>
243
244 <p>
245 To get JavaInspect into same classpath with your projecs I so far came
246 up with 2 solutions:
247 </p>
248
249 <ol class="org-ol">
250 <li>Add JavaInspect library in your project as a dependency.
251 </li>
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
256 reflection.
257 </li>
258 </ol>
259
260 <p>
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.
265 </p>
266
267 <p>
268 Note: GraphViz is developed and tested so far only on GNU/Linux.
269 </p>
270 </div>
271 </div>
272
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">
276 <ul class="org-ul">
277 <li>A very simple example:
278
279
280 <figure>
281 <p><a href="example.png"><img src="example.resized.png" class="img-responsive" alt="example.resized.png"></a>
282 </p>
283 </figure>
284
285 <p>
286 Graph legend:
287 </p>
288
289
290 <figure>
291 <p><img src="legend.png" class="img-responsive" alt="legend.png">
292 </p>
293 </figure>
294 </li>
295
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>.
297 </li>
298 </ul>
299 </div>
300 </div>
301
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">
305 <p>
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.
311 </p>
312
313 <p>
314 Control code in general does the following:
315 </p>
316 <ol class="org-ol">
317 <li>Create graph object.
318 </li>
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:
322 <ul class="org-ul">
323 <li>Manually adding individual classes to the graph.
324 </li>
325 <li>and/or: Let GraphViz recursively scan and parse specified
326 directories with Java source code files to discover class names.
327 </li>
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.
330 </li>
331 </ul>
332 </li>
333 <li>Graphs easilly get very big and complex so optionally we filter
334 important code using classname wildcards patterns based blacklist
335 and/or whitelist.
336 </li>
337 <li>Optionally we can tune some rendering parameters like:
338 <ul class="org-ul">
339 <li>Possibility to remove orphaned classes (classes with no
340 references) from the graph.
341 </li>
342 <li>Specify target directory for generated visualization
343 files. (Default is user desktop directory)
344 </li>
345 <li>Keep intermediate GraphViz dot file for later inspection.
346 </li>
347 </ul>
348 </li>
349 <li>Render graph.
350 </li>
351 </ol>
352 </div>
353
354
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">
358 <p>
359 This example demonstrates generating of class graph from hand picked
360 classes and visualizing GraphViz itself.
361 </p>
362
363 <div class="org-src-container">
364
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>();
367
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>
370 graph.add(graph);
371
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>);
374
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>);
377
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>);
381 </pre>
382 </div>
383
384 <p>
385 Note: if desired, more compact version of the above:
386 </p>
387 <div class="org-src-container">
388
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>);
391 </pre>
392 </div>
393
394
395 <p>
396 Result:
397 </p>
398 <ul class="org-ul">
399 <li>Generated DOT file: <a href="JavaInspect.dot">JavaInspect.dot</a>
400 </li>
401 <li>Generated PNG image: <a href="JavaInspect.png">JavaInspect.png</a>
402 </li>
403 </ul>
404 </div>
405 </div>
406
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">
411
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>();
414
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>);
418
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>);
421
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();
424
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>);
428 </pre>
429 </div>
430 <p>
431 Result:
432 </p>
433 <ul class="org-ul">
434 <li>Generated PNG image: <a href="JavaInspect%20full%20project.png">JavaInspect full project.png</a>
435 </li>
436 </ul>
437 </div>
438 </div>
439
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">
443 <ol class="org-ol">
444 <li>Download project Sixth <a href="http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz">code snapshot</a>.
445 </li>
446 <li>Inspect and run *DataGraph.java*.
447 </li>
448 </ol>
449 </div>
450 </div>
451 </div>
452
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">
456 <p>
457 Declare JavaInspect as dependency:
458 </p>
459 <div class="org-src-container">
460
461 <pre class="src src-xml">&lt;<span style="color: #A6E22E;">dependencies</span>&gt;
462     ...
463     &lt;<span style="color: #A6E22E;">dependency</span>&gt;
464         &lt;<span style="color: #A6E22E;">groupId</span>&gt;eu.svjatoslav&lt;/<span style="color: #A6E22E;">groupId</span>&gt;
465         &lt;<span style="color: #A6E22E;">artifactId</span>&gt;javainspect&lt;/<span style="color: #A6E22E;">artifactId</span>&gt;
466         &lt;<span style="color: #A6E22E;">version</span>&gt;1.6&lt;/<span style="color: #A6E22E;">version</span>&gt;
467     &lt;/<span style="color: #A6E22E;">dependency</span>&gt;
468     ...
469 &lt;/<span style="color: #A6E22E;">dependencies</span>&gt;
470 </pre>
471 </div>
472
473
474 <p>
475 Add Maven repository to retrieve artifact from:
476 </p>
477 <div class="org-src-container">
478
479 <pre class="src src-xml">&lt;<span style="color: #A6E22E;">repositories</span>&gt;
480     ...
481     &lt;<span style="color: #A6E22E;">repository</span>&gt;
482         &lt;<span style="color: #A6E22E;">id</span>&gt;svjatoslav.eu&lt;/<span style="color: #A6E22E;">id</span>&gt;
483         &lt;<span style="color: #A6E22E;">name</span>&gt;Svjatoslav repository&lt;/<span style="color: #A6E22E;">name</span>&gt;
484         &lt;<span style="color: #A6E22E;">url</span>&gt;http://www2.svjatoslav.eu/maven/&lt;/<span style="color: #A6E22E;">url</span>&gt;
485     &lt;/<span style="color: #A6E22E;">repository</span>&gt;
486     ...
487 &lt;/<span style="color: #A6E22E;">repositories</span>&gt;
488 </pre>
489 </div>
490 </div>
491 </div>
492
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">
496 <p>
497 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
498 </p>
499
500 <p>
501 On Ubuntu/Debian use:
502 </p>
503 <div class="org-src-container">
504
505 <pre class="src src-sh">sudo apt-get install graphviz
506 </pre>
507 </div>
508 </div>
509 </div>
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">
513 <ul class="org-ul">
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.
517 </li>
518 <li>FEATURE: integarte with <a href="http://plantuml.com/class-diagram">PlantUML</a>.
519 </li>
520 <li>FEATURE: add dark theme
521 </li>
522 <li>FEATURE: sort Class fields by alphabet
523 </li>
524 <li>FEATURE: visualize also concrete field values so it could be used as
525 ultra cool runtime logging framework
526 </li>
527 <li>FEATURE: possibility to visualize structure and data from JVM
528 snapshot
529 </li>
530 <li>FEATURE: possibility to attach to remote process to visualize
531 data/structure using JVM debug port and mechanism.
532 </li>
533 <li>FEATURE: possibility to attach to JVM using JVM agent
534 </li>
535 <li>FEATURE: possibility to script javainspect behavior
536 </li>
537 <li>FEATURE: possibility to select classes/fields/values to be
538 visualized in SQL like syntax
539 </li>
540 <li>FEATURE: configurable maven plugin to generate graphs as part of the
541 project build/release process
542 </li>
543 </ul>
544 </div>
545 </div>
546 </div><div class="col-md-3"><nav id="table-of-contents">
547 <div id="text-table-of-contents" class="bs-docs-sidebar">
548 <ul class="nav">
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>
552 <ul class="nav">
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>
556 </ul>
557 </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>
561 </ul>
562 </div>
563 </nav>
564 </div></div></div>
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>
569 </div>
570 </footer>
571 </body>
572 </html>