Added all important commandline options. Updated documentation.
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / structure / ClassGraph.java
index 1747614..ce22d26 100755 (executable)
@@ -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<String> 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;
     }