X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FClassGraph.java;h=dc2b9ecbf076ad485cf40789ef8b8e0e16abd512;hb=fb953cf51bdc2bb20ba37c29ea22e26f283aa48e;hp=174761410b08cbd42ee7759a1c35836fb05022ae;hpb=f0253606ed92cc13aa4e49e28a44ee41cf3d3251;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 1747614..dc2b9ec 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java @@ -1,6 +1,6 @@ /* * JavaInspect - Utility to visualize java software - * Copyright (C) 2013-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Copyright (C) 2013-2019, 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 @@ -23,7 +23,6 @@ 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 { @@ -36,8 +35,7 @@ public class ClassGraph { private final List whitelistClassGlobs = new ArrayList<>(); TargetImageType targetImageType = TargetImageType.SVG; - private String targetDirectoryPath = CommonPathResolver.getDesktopDirectory() - .getAbsolutePath() + separator; + private File targetDirectory = CommonPathResolver.getDesktopDirectory(); private boolean keepDotFile; public ClassGraph() { @@ -96,27 +94,30 @@ public class ClassGraph { public void generateGraph(final String resultFileName) { - final String dotFilePath = targetDirectoryPath + resultFileName + ".dot"; - final String imageFilePath = targetDirectoryPath + resultFileName + "." + targetImageType.fileExtension; + final File dotFile = new File(targetDirectory, resultFileName + ".dot"); + final File imageFile = new File(targetDirectory, resultFileName + "." + targetImageType.fileExtension); try { // write DOT file to disk - final PrintWriter out = new PrintWriter(dotFilePath, UTF_8); + final PrintWriter out = new PrintWriter(dotFile, UTF_8); out.write(getDot()); out.close(); // execute GraphViz to visualize graph try { Runtime.getRuntime() - .exec(new String[]{"dot", "-T" + targetImageType.fileExtension, dotFilePath, "-o", - imageFilePath}).waitFor(); + .exec(new String[]{"dot", + "-T" + targetImageType.fileExtension, + dotFile.getAbsolutePath(), + "-o", + imageFile.getAbsolutePath()}).waitFor(); } catch (final InterruptedException ignored) { } if (!keepDotFile) // delete dot file - if (!new File(dotFilePath).delete()) - throw new RuntimeException("Cannot delete file: " + dotFilePath); + if (!dotFile.delete()) + throw new RuntimeException("Cannot delete file: " + dotFile.getAbsolutePath()); } catch (final IOException e) { throw new RuntimeException("Unable to generate graph: " + e.getMessage(), e); @@ -199,12 +200,8 @@ public class ClassGraph { return this; } - public ClassGraph setTargetDirectoryPath(String directoryPath) { - if (!directoryPath.endsWith(separator)) - directoryPath += separator; - - targetDirectoryPath = directoryPath; - + public ClassGraph setTargetDirectory(File targetDirectory) { + this.targetDirectory = targetDirectory; return this; }