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