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">
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;
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%; }
34 border: 1px solid #ccc;
35 box-shadow: 3px 3px 3px #eee;
37 font-family: monospace;
49 background-color: white;
53 border: 1px solid black;
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'; }
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; }
81 border: 2px solid gray;
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; }
97 <link rel="stylesheet" type="text/css" href="http://thomasf.github.io/solarized-css/solarized-dark.min.css" />
98 <script type="text/javascript">
100 @licstart The following is the entire license notice for the
101 JavaScript code in this tag.
103 Copyright (C) 2012-2013 Free Software Foundation, Inc.
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.
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.
120 @licend The above is the entire license notice
121 for the JavaScript code in this tag.
123 <!--/*--><![CDATA[/*><!--*/
124 function CodeHighlightOn(elem, id)
126 var target = document.getElementById(id);
128 elem.cacheClassElem = elem.className;
129 elem.cacheClassTarget = target.className;
130 target.className = "code-highlighted";
131 elem.className = "code-highlighted";
134 function CodeHighlightOff(elem, id)
136 var target = document.getElementById(id);
137 if(elem.cacheClassElem)
138 elem.className = elem.cacheClassElem;
139 if(elem.cacheClassTarget)
140 target.className = elem.cacheClassTarget;
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">
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>
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>
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>
169 <li><a href="http://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=snapshot;h=HEAD;sf=tgz">download latest snapshot</a></li>
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>
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>
182 <li><a href="http://svjatoslav.eu/programs.jsp">other applications hosted at svjatoslav.eu</a></li>
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">
189 Goal: simplify/speed up understanding the computer program code by
190 automatically visualizing its structure.
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.
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.
206 To get JavaInspect into same classpath with your projecs I so far came
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
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.
227 Note: GraphViz is developed and tested so far only on GNU Linux.
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">
237 A very simple example:
242 <p><a href="example.png"><img src="example.resized.png" alt="example.resized.png" /></a>
252 <p><img src="legend.png" alt="legend.png" />
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>
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">
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.
273 Control code in general does the following:
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:
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>
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:
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>
298 <li>Render graph.</li>
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">
307 This example demonstrates generating of class graph from hand picked
308 classes and visualizing GraphViz itself.
311 <div class="org-src-container">
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>;
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>;
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>;
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>;
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>;
333 Note: if desired, more compact version of the above:
335 <div class="org-src-container">
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>;
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>
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">
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>;
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>;
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>;
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>;
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>;
380 <li>Generated PNG image: <a href="JavaInspect%20full%20project.png">JavaInspect full project.png</a></li>
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">
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>
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">
400 Declare JavaInspect as dependency:
402 <div class="org-src-container">
404 <pre class="src src-xml"><<span style="color: #bc6ec5; font-weight: bold;">dependencies</span>>
406 <<span style="color: #bc6ec5; font-weight: bold;">dependency</span>>
407 <<span style="color: #bc6ec5; font-weight: bold;">groupId</span>>eu.svjatoslav</<span style="color: #bc6ec5; font-weight: bold;">groupId</span>>
408 <<span style="color: #bc6ec5; font-weight: bold;">artifactId</span>>javainspect</<span style="color: #bc6ec5; font-weight: bold;">artifactId</span>>
409 <<span style="color: #bc6ec5; font-weight: bold;">version</span>>1.5</<span style="color: #bc6ec5; font-weight: bold;">version</span>>
410 </<span style="color: #bc6ec5; font-weight: bold;">dependency</span>>
412 </<span style="color: #bc6ec5; font-weight: bold;">dependencies</span>>
418 Add Maven repository to retrieve artifact from:
420 <div class="org-src-container">
422 <pre class="src src-xml"><<span style="color: #bc6ec5; font-weight: bold;">repositories</span>>
424 <<span style="color: #bc6ec5; font-weight: bold;">repository</span>>
425 <<span style="color: #bc6ec5; font-weight: bold;">id</span>>svjatoslav.eu</<span style="color: #bc6ec5; font-weight: bold;">id</span>>
426 <<span style="color: #bc6ec5; font-weight: bold;">name</span>>Svjatoslav repository</<span style="color: #bc6ec5; font-weight: bold;">name</span>>
427 <<span style="color: #bc6ec5; font-weight: bold;">url</span>>http://www2.svjatoslav.eu/maven/</<span style="color: #bc6ec5; font-weight: bold;">url</span>>
428 </<span style="color: #bc6ec5; font-weight: bold;">repository</span>>
430 </<span style="color: #bc6ec5; font-weight: bold;">repositories</span>>
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">
440 <a href="http://www.graphviz.org/">GraphViz</a> - shall be installed on the computer.
444 On Ubuntu/Debian use:
446 <div class="org-src-container">
448 <pre class="src src-sh">sudo apt-get install graphviz
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">
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
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>
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>