/*
* JavaInspect - Utility to visualize java software
- * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright (C) 2013-2017, 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
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 Map<String, ClassDescriptor> fullyQualifiedNameToClassMap = new HashMap<String, ClassDescriptor>();
- private final List<String> blacklistClassPatterns = new ArrayList<String>();
+ private final List<String> blacklistClassGlobs = new ArrayList<String>();
- private final List<String> whitelistClassPatterns = new ArrayList<String>();
+ private final List<String> whitelistClassGlobs = new ArrayList<>();
- private String targetDirectory = CommonPathResolver.getDesktopDirectory()
- .getAbsolutePath() + "/";
+ private String targetDirectoryPath = CommonPathResolver.getDesktopDirectory()
+ .getAbsolutePath() + separator;
private boolean keepDotFile;
+ TargetImageType targetImageType = TargetImageType.SVG;
+
public ClassGraph() {
}
}
}
- public void blacklistClassPattern(final String pattern) {
- blacklistClassPatterns.add(pattern);
+ public void blacklistClassGlob(final String glob) {
+ blacklistClassGlobs.add(glob);
+ }
+
+ public void setTargetImageType(TargetImageType targetImageType) {
+ this.targetImageType = targetImageType;
}
/**
public void generateGraph(final String resultFileName) {
- final String dotFilePath = targetDirectory + resultFileName + ".dot";
- final String imageFilePath = targetDirectory + resultFileName + ".png";
-
- 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
// execute GraphViz to visualize graph
try {
Runtime.getRuntime()
- .exec(new String[]{"dot", "-Tpng", 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);
}
}
}
protected boolean isClassShown(final String className) {
- for (final String pattern : blacklistClassPatterns)
+ for (final String pattern : blacklistClassGlobs)
if (WildCardMatcher.match(className, pattern))
return false;
- if (!whitelistClassPatterns.isEmpty()) {
- for (final String pattern : whitelistClassPatterns)
+ if (!whitelistClassGlobs.isEmpty()) {
+ for (final String pattern : whitelistClassGlobs)
if (WildCardMatcher.match(className, pattern))
return true;
return false;
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;
}
- public ClassGraph whitelistClassPattern(final String pattern) {
- whitelistClassPatterns.add(pattern);
-
+ public ClassGraph whitelistClassGlob(final String glob) {
+ whitelistClassGlobs.add(glob);
return this;
}