minor documentation update
[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 <title>JavaInspect - Utility to visualize java software</title>
7 <!-- 2015-03-07 Sat 00:10 -->
8 <meta  http-equiv="Content-Type" content="text/html;charset=utf-8" />
9 <meta  name="generator" content="Org-mode" />
10 <meta  name="author" content="Svjatoslav Agejenko" />
11 <style type="text/css">
12  <!--/*--><![CDATA[/*><!--*/
13   .title  { text-align: center; }
14   .todo   { font-family: monospace; color: red; }
15   .done   { color: green; }
16   .tag    { background-color: #eee; font-family: monospace;
17             padding: 2px; font-size: 80%; font-weight: normal; }
18   .timestamp { color: #bebebe; }
19   .timestamp-kwd { color: #5f9ea0; }
20   .right  { margin-left: auto; margin-right: 0px;  text-align: right; }
21   .left   { margin-left: 0px;  margin-right: auto; text-align: left; }
22   .center { margin-left: auto; margin-right: auto; text-align: center; }
23   .underline { text-decoration: underline; }
24   #postamble p, #preamble p { font-size: 90%; margin: .2em; }
25   p.verse { margin-left: 3%; }
26   pre {
27     border: 1px solid #ccc;
28     box-shadow: 3px 3px 3px #eee;
29     padding: 8pt;
30     font-family: monospace;
31     overflow: auto;
32     margin: 1.2em;
33   }
34   pre.src {
35     position: relative;
36     overflow: visible;
37     padding-top: 1.2em;
38   }
39   pre.src:before {
40     display: none;
41     position: absolute;
42     background-color: white;
43     top: -10px;
44     right: 10px;
45     padding: 3px;
46     border: 1px solid black;
47   }
48   pre.src:hover:before { display: inline;}
49   pre.src-sh:before    { content: 'sh'; }
50   pre.src-bash:before  { content: 'sh'; }
51   pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
52   pre.src-R:before     { content: 'R'; }
53   pre.src-perl:before  { content: 'Perl'; }
54   pre.src-java:before  { content: 'Java'; }
55   pre.src-sql:before   { content: 'SQL'; }
56
57   table { border-collapse:collapse; }
58   caption.t-above { caption-side: top; }
59   caption.t-bottom { caption-side: bottom; }
60   td, th { vertical-align:top;  }
61   th.right  { text-align: center;  }
62   th.left   { text-align: center;   }
63   th.center { text-align: center; }
64   td.right  { text-align: right;  }
65   td.left   { text-align: left;   }
66   td.center { text-align: center; }
67   dt { font-weight: bold; }
68   .footpara:nth-child(2) { display: inline; }
69   .footpara { display: block; }
70   .footdef  { margin-bottom: 1em; }
71   .figure { padding: 1em; }
72   .figure p { text-align: center; }
73   .inlinetask {
74     padding: 10px;
75     border: 2px solid gray;
76     margin: 10px;
77     background: #ffffcc;
78   }
79   #org-div-home-and-up
80    { text-align: right; font-size: 70%; white-space: nowrap; }
81   textarea { overflow-x: auto; }
82   .linenr { font-size: smaller }
83   .code-highlighted { background-color: #ffff00; }
84   .org-info-js_info-navigation { border-style: none; }
85   #org-info-js_console-label
86     { font-size: 10px; font-weight: bold; white-space: nowrap; }
87   .org-info-js_search-highlight
88     { background-color: #ffff00; color: #000000; font-weight: bold; }
89   /*]]>*/-->
90 </style>
91 <link rel="stylesheet" type="text/css" href="http://thomasf.github.io/solarized-css/solarized-dark.min.css" />
92 <script type="text/javascript">
93 /*
94 @licstart  The following is the entire license notice for the
95 JavaScript code in this tag.
96
97 Copyright (C) 2012-2013 Free Software Foundation, Inc.
98
99 The JavaScript code in this tag is free software: you can
100 redistribute it and/or modify it under the terms of the GNU
101 General Public License (GNU GPL) as published by the Free Software
102 Foundation, either version 3 of the License, or (at your option)
103 any later version.  The code is distributed WITHOUT ANY WARRANTY;
104 without even the implied warranty of MERCHANTABILITY or FITNESS
105 FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
106
107 As additional permission under GNU GPL version 3 section 7, you
108 may distribute non-source (e.g., minimized or compacted) forms of
109 that code without the copy of the GNU GPL normally required by
110 section 4, provided you include this license notice and a URL
111 through which recipients can access the Corresponding Source.
112
113
114 @licend  The above is the entire license notice
115 for the JavaScript code in this tag.
116 */
117 <!--/*--><![CDATA[/*><!--*/
118  function CodeHighlightOn(elem, id)
119  {
120    var target = document.getElementById(id);
121    if(null != target) {
122      elem.cacheClassElem = elem.className;
123      elem.cacheClassTarget = target.className;
124      target.className = "code-highlighted";
125      elem.className   = "code-highlighted";
126    }
127  }
128  function CodeHighlightOff(elem, id)
129  {
130    var target = document.getElementById(id);
131    if(elem.cacheClassElem)
132      elem.className = elem.cacheClassElem;
133    if(elem.cacheClassTarget)
134      target.className = elem.cacheClassTarget;
135  }
136 /*]]>*///-->
137 </script>
138 </head>
139 <body>
140 <div id="content">
141 <h1 class="title">JavaInspect - Utility to visualize java software</h1>
142 <div id="table-of-contents">
143 <h2>Table of Contents</h2>
144 <div id="text-table-of-contents">
145 <ul>
146 <li><a href="#sec-1">1. General</a></li>
147 <li><a href="#sec-2">2. Example graphs</a></li>
148 <li><a href="#sec-3">3. Usage</a>
149 <ul>
150 <li><a href="#sec-3-1">3.1. example 1: individually picked objects</a></li>
151 <li><a href="#sec-3-2">3.2. example 2: scan java code, apply filters</a></li>
152 <li><a href="#sec-3-3">3.3. example 3: GraphViz embedded in another project</a></li>
153 </ul>
154 </li>
155 <li><a href="#sec-4">4. Embedding JavaInspect in your Maven project</a></li>
156 <li><a href="#sec-5">5. Requirements</a></li>
157 <li><a href="#sec-6">6. <span class="todo TODO">TODO</span> </a></li>
158 </ul>
159 </div>
160 </div>
161 <hr  />
162 <ul class="org-ul">
163 <li><a href="http://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=snapshot;h=HEAD;sf=tgz">download latest snapshot</a>
164 </li>
165
166 <li>This program is free software; you can redistribute it and/or modify
167 it under the terms of version 3 of the <a href="https://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public
168 License</a> or later as published by the Free Software Foundation.
169 </li>
170
171 <li>Program author:
172 <ul class="org-ul">
173 <li>Svjatoslav Agejenko
174 </li>
175 <li>Homepage: <a href="http://svjatoslav.eu">http://svjatoslav.eu</a>
176 </li>
177 <li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a>
178 </li>
179 </ul>
180 </li>
181
182 <li><a href="http://svjatoslav.eu/programs.jsp">other applications hosted at svjatoslav.eu</a>
183 </li>
184 </ul>
185
186 <div id="outline-container-sec-1" class="outline-2">
187 <h2 id="sec-1"><span class="section-number-2">1</span> General</h2>
188 <div class="outline-text-2" id="text-1">
189 <p>
190 Goal: simplify/speed up understanding the computer program code by
191 automatically visualizing its structure.
192 </p>
193
194 <p>
195 JavaInspect is a Java library that primarily uses Java reflection to
196 discover and visualize any part of Java program provided that
197 classes to be visualised are available in the classpath.
198 </p>
199
200 <p>
201 JavaInspect currently has no GUI, configuration files, embedded
202 scripting support, direct Maven or Ant integration. The only way to
203 instuct Javainspect what to do is by using its Java API.
204 </p>
205
206 <p>
207 To get JavaInspect into same classpath with your projecs I so far came
208 up with 2 solutions:
209 </p>
210
211 <ol class="org-ol">
212 <li>Add JavaInspect library in your project as a dependency.
213 </li>
214 <li>Create new Java project for the purpose visualizing your other
215 projects and include JavaInspect and your projecs binary artifacts
216 (Jar's) into new project classpath. Built binary Jar's (with no
217 source code) are sufficient because JavaInspect operates via
218 reflection.
219 </li>
220 </ol>
221
222 <p>
223 After discovering application structure and optionally filtering out
224 unimportant parts, JavaInspect produces GraphViz dot file that
225 describes data to be visualized. Then launches GraphViz to generate
226 bitmap graph in PNG format. By default on your Desktop directory.
227 </p>
228
229 <p>
230 Note: GraphViz is developed and tested so far only on GNU Linux.
231 </p>
232 </div>
233 </div>
234
235 <div id="outline-container-sec-2" class="outline-2">
236 <h2 id="sec-2"><span class="section-number-2">2</span> Example graphs</h2>
237 <div class="outline-text-2" id="text-2">
238 <ul class="org-ul">
239 <li>A very simple example:
240
241
242 <div class="figure">
243 <p><a href="example.png"><img src="example.resized.png" alt="example.resized.png" /></a>
244 </p>
245 </div>
246
247 <p>
248 Graph legend:
249 </p>
250
251
252 <div class="figure">
253 <p><img src="legend.png" alt="legend.png" />
254 </p>
255 </div>
256 </li>
257
258 <li>Example visualization of <a href="http://www2.svjatoslav.eu/gitbrowse/sixth/doc/">Sixth</a> project: <a href="http://www2.svjatoslav.eu/projects/sixth/codegraphs/">architecture graphs</a>.
259 </li>
260 </ul>
261 </div>
262 </div>
263
264 <div id="outline-container-sec-3" class="outline-2">
265 <h2 id="sec-3"><span class="section-number-2">3</span> Usage</h2>
266 <div class="outline-text-2" id="text-3">
267 <p>
268 Currently the only way to control JavaInspect is by using Java
269 API. Simple Java based control/configuration code needs to be written
270 for each project. I usually put such code into directories devoted for
271 JUnit tests. Because it needs not to be compiled/embedded into final
272 product or project artifact I'm just willing to visualize.
273 </p>
274
275 <p>
276 Control code in general does the following:
277 </p>
278 <ol class="org-ol">
279 <li>Create graph object.
280 </li>
281 <li>Java reflection/classloaders does not provide mechanism for
282 discovering all classes under given package. Therefore you need to
283 declare at least some classes to be added to the graph by:
284 <ul class="org-ul">
285 <li>Manually adding individual classes to the graph.
286 </li>
287 <li>and/or: Let GraphViz recursively scan and parse specified
288 directories with Java source code files to discover class names.
289 </li>
290 <li>For every class added to the graph, GraphViz will recursively
291 inspect it and add all referecned classes to the graph as well.
292 </li>
293 </ul>
294 </li>
295 <li>Graphs easilly get very big and complex so optionally we filter
296 important code using classname wildcards patterns based blacklist
297 and/or whitelist.
298 </li>
299 <li>Optionally we can tune some rendering parameters like:
300 <ul class="org-ul">
301 <li>Possibility to remove orphaned classes (classes with no
302 references) from the graph.
303 </li>
304 <li>Specify target directory for generated visualization
305 files. (Default is user desktop directory)
306 </li>
307 <li>Keep intermediate GraphViz dot file for later inspection.
308 </li>
309 </ul>
310 </li>
311 <li>Render graph.
312 </li>
313 </ol>
314 </div>
315
316
317 <div id="outline-container-sec-3-1" class="outline-3">
318 <h3 id="sec-3-1"><span class="section-number-3">3.1</span> example 1: individually picked objects</h3>
319 <div class="outline-text-3" id="text-3-1">
320 <p>
321 This example demonstrates generating of class graph from hand picked
322 classes and visualizing GraphViz itself.
323 </p>
324
325 <div class="org-src-container">
326
327 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
328 <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>();
329
330 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Add some random object to the graph. GraphViz will detect Class from</span>
331 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">the object.</span>
332 graph.add(graph);
333
334 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Also add some random class to the graph.</span>
335 graph.add(Utils.<span style="color: #F92672;">class</span>);
336
337 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Keep intermediary GraphViz DOT file for reference.</span>
338 graph.setKeepDotFile(<span style="color: #FF80F4;">true</span>);
339
340 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect.png" to the user Desktop</span>
341 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">directory</span>
342 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
343 </pre>
344 </div>
345
346 <p>
347 Note: if desired, more compact version of the above:
348 </p>
349 <div class="org-src-container">
350
351 <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>)
352                 .setKeepDotFile(<span style="color: #FF80F4;">true</span>).generateGraph(<span style="color: #EEDC82;">"JavaInspect"</span>);
353 </pre>
354 </div>
355
356
357 <p>
358 Result:
359 </p>
360 <ul class="org-ul">
361 <li>Generated DOT file: <a href="JavaInspect.dot">JavaInspect.dot</a>
362 </li>
363 <li>Generated PNG image: <a href="JavaInspect.png">JavaInspect.png</a>
364 </li>
365 </ul>
366 </div>
367 </div>
368
369 <div id="outline-container-sec-3-2" class="outline-3">
370 <h3 id="sec-3-2"><span class="section-number-3">3.2</span> example 2: scan java code, apply filters</h3>
371 <div class="outline-text-3" id="text-3-2">
372 <div class="org-src-container">
373
374 <pre class="src src-java"><span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Create graph</span>
375 <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>();
376
377 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Recursively scan current directory for Java source code and attempt</span>
378 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">to detect class names from there to be added to the graph.</span>
379 graph.addProject(<span style="color: #EEDC82;">"."</span>);
380
381 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Blacklist example classes from being shown on the graph</span>
382 graph.blacklistClassPattern(<span style="color: #EEDC82;">"eu.svjatoslav.inspector.java.structure.example.*"</span>);
383
384 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">do not show single classes with no relationships on the graph</span>
385 graph.hideOrphanedClasses();
386
387 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">Produce bitmap image titled "JavaInspect full project.png" to the</span>
388 <span style="color: #8C8C8C;">// </span><span style="color: #8C8C8C;">user Desktop directory.</span>
389 graph.generateGraph(<span style="color: #EEDC82;">"JavaInspect full project"</span>);
390 </pre>
391 </div>
392 <p>
393 Result:
394 </p>
395 <ul class="org-ul">
396 <li>Generated PNG image: <a href="JavaInspect%20full%20project.png">JavaInspect full project.png</a>
397 </li>
398 </ul>
399 </div>
400 </div>
401
402 <div id="outline-container-sec-3-3" class="outline-3">
403 <h3 id="sec-3-3"><span class="section-number-3">3.3</span> example 3: GraphViz embedded in another project</h3>
404 <div class="outline-text-3" id="text-3-3">
405 <ol class="org-ol">
406 <li>Download project Sixth <a href="http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=snapshot;h=HEAD;sf=tgz">code snapshot</a>.
407 </li>
408 <li>Inspect and run <b>DataGraph.java</b>.
409 </li>
410 </ol>
411 </div>
412 </div>
413 </div>
414
415 <div id="outline-container-sec-4" class="outline-2">
416 <h2 id="sec-4"><span class="section-number-2">4</span> Embedding JavaInspect in your Maven project</h2>
417 <div class="outline-text-2" id="text-4">
418 <p>
419 Declare JavaInspect as dependency:
420 </p>
421 <div class="org-src-container">
422
423 <pre class="src src-xml">&lt;<span style="color: #A6E22E;">dependencies</span>&gt;
424     ...
425     &lt;<span style="color: #A6E22E;">dependency</span>&gt;
426         &lt;<span style="color: #A6E22E;">groupId</span>&gt;eu.svjatoslav&lt;/<span style="color: #A6E22E;">groupId</span>&gt;
427         &lt;<span style="color: #A6E22E;">artifactId</span>&gt;javainspect&lt;/<span style="color: #A6E22E;">artifactId</span>&gt;
428         &lt;<span style="color: #A6E22E;">version</span>&gt;1.5-SNAPSHOT&lt;/<span style="color: #A6E22E;">version</span>&gt;
429     &lt;/<span style="color: #A6E22E;">dependency</span>&gt;
430     ...
431 &lt;/<span style="color: #A6E22E;">dependencies</span>&gt;
432 </pre>
433 </div>
434
435
436 <p>
437 Add Maven repository to retrieve artifact from:
438 </p>
439 <div class="org-src-container">
440
441 <pre class="src src-xml">&lt;<span style="color: #A6E22E;">repositories</span>&gt;
442     ...
443     &lt;<span style="color: #A6E22E;">repository</span>&gt;
444         &lt;<span style="color: #A6E22E;">id</span>&gt;svjatoslav.eu&lt;/<span style="color: #A6E22E;">id</span>&gt;
445         &lt;<span style="color: #A6E22E;">name</span>&gt;Svjatoslav repository&lt;/<span style="color: #A6E22E;">name</span>&gt;
446         &lt;<span style="color: #A6E22E;">url</span>&gt;http://www2.svjatoslav.eu/maven/&lt;/<span style="color: #A6E22E;">url</span>&gt;
447     &lt;/<span style="color: #A6E22E;">repository</span>&gt;
448     ...
449 &lt;/<span style="color: #A6E22E;">repositories</span>&gt;
450 </pre>
451 </div>
452 </div>
453 </div>
454
455 <div id="outline-container-sec-5" class="outline-2">
456 <h2 id="sec-5"><span class="section-number-2">5</span> Requirements</h2>
457 <div class="outline-text-2" id="text-5">
458 <p>
459 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
460 </p>
461
462 <p>
463 On Ubuntu/Debian use:
464 </p>
465 <div class="org-src-container">
466
467 <pre class="src src-sh">sudo apt-get install graphviz
468 </pre>
469 </div>
470 </div>
471 </div>
472 <div id="outline-container-sec-6" class="outline-2">
473 <h2 id="sec-6"><span class="section-number-2">6</span> <span class="todo TODO">TODO</span> </h2>
474 <div class="outline-text-2" id="text-6">
475 <ul class="org-ul">
476 <li>BUG: Should not hide references if there are too many of them to
477 classes if referring classes are not visible anyway because of
478 blacklist/whitelist rules. Basically reference counting should
479 exclude not visible classes.
480 </li>
481 <li>FEATURE: add dark theme
482 </li>
483 <li>FEATURE: sort Class fields by alphabet
484 </li>
485 <li>FEATURE: visualize also concrete field values so it could be used as
486 ultra cool runtime logging framework
487 </li>
488 <li>FEATURE: possibility to visualize structure and data from JVM
489 snapshot
490 </li>
491 <li>FEATURE: possibility to attach to remote process to visualize
492 data/structure using JVM debug port and mechanism.
493 </li>
494 <li>FEATURE: possibility to attach to JVM using JVM agent
495 </li>
496 <li>FEATURE: possibility to script javainspect behavior
497 </li>
498 <li>FEATURE: possibility to select classes/fields/values to be
499 visualized in SQL like syntax
500 </li>
501 <li>FEATURE: configurable maven plugin to generate graphs as part of the
502 project build/release process
503 </li>
504 </ul>
505 </div>
506 </div>
507 </div>
508 <div id="postamble" class="status">
509 <p class="author">Author: Svjatoslav Agejenko</p>
510 <p class="date">Created: 2015-03-07 Sat 00:10</p>
511 <p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.4.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10)</p>
512 <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
513 </div>
514 </body>
515 </html>