X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FClassGraph.java;h=a4d90150e24153409f4c0b2beca7806b9f31f603;hp=c6b6cbf32474ecab21f95aa5f8ebc3d0bf1de820;hb=4a2fa09cacf11397bf00407edc2947c23967afeb;hpb=9720b6ec40d9b10e5a2df8fad848b82f36451c1b 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 c6b6cbf..a4d9015 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import static eu.svjatoslav.inspector.java.methods.JavaFile.UTF_8; +import static java.io.File.separator; public class ClassGraph { @@ -35,11 +36,13 @@ public class ClassGraph { private final List whitelistClassPatterns = new ArrayList(); - private String targetDirectory = CommonPathResolver.getDesktopDirectory() - .getAbsolutePath() + "/"; + private String targetDirectoryPath = CommonPathResolver.getDesktopDirectory() + .getAbsolutePath() + separator; private boolean keepDotFile; + TargetImageType targetImageType = TargetImageType.SVG; + public ClassGraph() { } @@ -84,6 +87,10 @@ public class ClassGraph { blacklistClassPatterns.add(pattern); } + public void setTargetImageType(TargetImageType targetImageType) { + this.targetImageType = targetImageType; + } + /** * @param resultFileName file name for the generated graph. File extension will be * added automatically. Existing file with the same name will be @@ -92,10 +99,8 @@ public class ClassGraph { public void generateGraph(final String resultFileName) { - final String dotFilePath = targetDirectory + resultFileName + ".dot"; - final String imageFilePath = targetDirectory + resultFileName + ".svg"; - - System.out.println("Dot file path:" + dotFilePath); + final String dotFilePath = targetDirectoryPath + resultFileName + ".dot"; + final String imageFilePath = targetDirectoryPath + resultFileName + "." + targetImageType.fileExtension; try { // write DOT file to disk @@ -106,16 +111,18 @@ public class ClassGraph { // execute GraphViz to visualize graph try { Runtime.getRuntime() - .exec(new String[]{"dot", "-Tsvg", dotFilePath, "-o", + .exec(new String[]{"dot", "-T" + targetImageType.fileExtension, dotFilePath, "-o", imageFilePath}).waitFor(); } catch (final InterruptedException ignored) { } if (!keepDotFile) // delete dot file - if (!new File(dotFilePath).delete()) throw new RuntimeException("Cannot delete file: " + dotFilePath); + if (!new File(dotFilePath).delete()) + throw new RuntimeException("Cannot delete file: " + dotFilePath); + } catch (final IOException e) { - System.err.println(e); + throw new RuntimeException("Unable to generate graph: " + e.getMessage(), e); } } @@ -196,11 +203,11 @@ public class ClassGraph { return this; } - public ClassGraph setTargetDirectory(String directoryPath) { - if (!directoryPath.endsWith("/")) - directoryPath += "/"; + public ClassGraph setTargetDirectoryPath(String directoryPath) { + if (!directoryPath.endsWith(separator)) + directoryPath += separator; - targetDirectory = directoryPath; + targetDirectoryPath = directoryPath; return this; }