X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FClassGraph.java;h=a2ce8a2110149b959e7bf2533fff8e2613e7d7c1;hb=a65f21f0464caf3a2ea567ec959bc2be78d1864c;hp=31ddbede42d3749cb8a8a538a958993017134e78;hpb=31e8e0b97c9f60f8820d708fa86c11d65f5445f3;p=javainspect.git diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java index 31ddbed..a2ce8a2 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software - * Copyright (C) 2013-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -30,7 +30,7 @@ public class ClassGraph { /** * Maps class fully qualified names to class descriptors. */ - Map nameToClassMap = new HashMap(); + private final Map fullyQualifiedNameToClassMap = new HashMap(); private Filter filter = new Filter(); @@ -66,8 +66,8 @@ public class ClassGraph { final String className = clazz.getName(); - if (nameToClassMap.containsKey(className)) - return nameToClassMap.get(className); + if (fullyQualifiedNameToClassMap.containsKey(className)) + return fullyQualifiedNameToClassMap.get(className); return new ClassDescriptor(clazz, this); } @@ -112,7 +112,7 @@ public class ClassGraph { * file name for the generated graph. File extension will be * added automatically. Existing file with the same name will be * overwritten. - * + * * @param keepDotFile * if set to true then intermediary GraphViz DOT * file will be kept. @@ -124,8 +124,31 @@ public class ClassGraph { final String desktopPath = CommonPathResolver.getDesktopDirectory() .getAbsolutePath() + "/"; - final String dotFilePath = desktopPath + resultFileName + ".dot"; - final String imageFilePath = desktopPath + resultFileName + ".png"; + generateGraph(desktopPath, resultFileName, keepDotFile); + } + + /** + * @param targetDirectory + * target directory name + * + * @param resultFileName + * file name for the generated graph. File extension will be + * added automatically. Existing file with the same name will be + * overwritten. + * + * @param keepDotFile + * if set to true then intermediary GraphViz DOT + * file will be kept. + */ + + public void generateGraph(String targetDirectory, + final String resultFileName, final boolean keepDotFile) { + + if (!targetDirectory.endsWith("/")) + targetDirectory += "/"; + + final String dotFilePath = targetDirectory + resultFileName + ".dot"; + final String imageFilePath = targetDirectory + resultFileName + ".png"; System.out.println("Dot file path:" + dotFilePath); @@ -152,6 +175,7 @@ public class ClassGraph { } catch (final IOException e) { System.err.println(e); } + } private String getDot() { @@ -160,7 +184,7 @@ public class ClassGraph { result.append("digraph Java {\n"); result.append("graph [rankdir=LR, overlap = false, concentrate=true];\n"); - for (final Map.Entry entry : nameToClassMap + for (final Map.Entry entry : fullyQualifiedNameToClassMap .entrySet()) result.append(entry.getValue().getDot()); @@ -179,11 +203,18 @@ public class ClassGraph { */ public void hideOrphanedClasses() { - for (final ClassDescriptor classDescriptor : nameToClassMap.values()) + for (final ClassDescriptor classDescriptor : fullyQualifiedNameToClassMap + .values()) classDescriptor.hideClassIfNoReferences(); } + public void registerClass(final String classFullyQualifiedName, + final ClassDescriptor classDescriptor) { + fullyQualifiedNameToClassMap.put(classFullyQualifiedName, + classDescriptor); + } + public void setFilter(final Filter filter) { this.filter = filter; }