updated example code
[javainspect.git] / src / test / java / eu / svjatoslav / inspector / java / structure / example / RenderJavaInspect.java
1 /*
2  * JavaInspect - Utility to visualize java software
3  * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.inspector.java.structure.example;
11
12 import java.io.FileNotFoundException;
13
14 import eu.svjatoslav.inspector.java.structure.ClassGraph;
15 import eu.svjatoslav.inspector.java.structure.Utils;
16
17 public class RenderJavaInspect {
18
19         private static void fullProjectExample() {
20                 final ClassGraph graph = new ClassGraph();
21
22                 // Recursively scan current directory for Java source code and attempt
23                 // to detect class names from there to be added to the graph.
24                 graph.addProject(".");
25
26                 // Blacklist example classes from being shown on the graph
27                 graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
28
29                 // do not show single classes with no relationships on the graph
30                 graph.hideOrphanedClasses();
31
32                 // Produce bitmap image titled "JavaInspect full project.png" to the
33                 // user Desktop directory.
34                 graph.generateGraph("JavaInspect full project");
35         }
36
37         private static void handpickClassesExample() {
38                 /*
39                  * This example demonstrates generating of class graph from hand picked
40                  * classes and visualizing GraphViz itself.
41                  */
42
43                 // Create graph
44                 final ClassGraph graph = new ClassGraph();
45
46                 // Add some random object to the graph. GraphViz will detect Class from
47                 // the object.
48                 graph.add(graph);
49
50                 // Also add some random class to the graph.
51                 graph.add(Utils.class);
52
53                 // Keep intermediary GraphViz DOT file for reference.
54                 graph.setKeepDotFile(true);
55
56                 // Produce bitmap image titled "JavaInspect.png" to the user Desktop
57                 // directory
58                 graph.generateGraph("JavaInspect");
59         }
60
61         public static void main(final String[] args) throws FileNotFoundException {
62
63                 handpickClassesExample();
64
65                 fullProjectExample();
66
67         }
68 }