import java.util.Map;
import static eu.svjatoslav.inspector.java.methods.JavaFile.UTF_8;
-import static java.io.File.separator;
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() {
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);
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;
}