projects
/
javainspect.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Updated copyright info
[javainspect.git]
/
src
/
main
/
java
/
eu
/
svjatoslav
/
inspector
/
java
/
structure
/
ClassGraph.java
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
..
c31124c
100755
(executable)
--- 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
/*
* JavaInspect - Utility to visualize java software
- * Copyright (C) 2013-20
15
, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright (C) 2013-20
20
, 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
*
* 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
@@
-29,15
+29,13
@@
public class ClassGraph {
/**
* Maps class fully qualified names to class descriptors.
*/
/**
* Maps class fully qualified names to class descriptors.
*/
- private final Map<String, ClassDescriptor> fullyQualifiedNameToClassMap = new HashMap<
String, ClassDescriptor
>();
+ private final Map<String, ClassDescriptor> fullyQualifiedNameToClassMap = new HashMap<>();
- private final List<String> blacklistClassPatterns = new ArrayList<String>();
-
- private final List<String> whitelistClassPatterns = new ArrayList<String>();
-
- private String targetDirectory = CommonPathResolver.getDesktopDirectory()
- .getAbsolutePath() + "/";
+ private final List<String> blacklistClassGlobs = new ArrayList<>();
+ private final List<String> whitelistClassGlobs = new ArrayList<>();
+ TargetImageType targetImageType = TargetImageType.SVG;
+ private File targetDirectory = CommonPathResolver.getDesktopDirectory();
private boolean keepDotFile;
public ClassGraph() {
private boolean keepDotFile;
public ClassGraph() {
@@
-72,7
+70,7
@@
public class ClassGraph {
for (final Clazz clazz : projectScanner.getAllClasses())
try {
System.out.println("Class full name: " + clazz.getFullName());
for (final Clazz clazz : projectScanner.getAllClasses())
try {
System.out.println("Class full name: " + clazz.getFullName());
- final Class c =
this.getClass()
.forName(clazz.getFullName());
+ final Class c =
Class
.forName(clazz.getFullName());
addObject(c);
} catch (final Exception exception) {
System.out.println("cannot add class: "
addObject(c);
} catch (final Exception exception) {
System.out.println("cannot add class: "
@@
-80,8
+78,12
@@
public class 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;
}
/**
}
/**
@@
-92,36
+94,39
@@
public class ClassGraph {
public void generateGraph(final String resultFileName) {
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 File dotFile = new File(targetDirectory, resultFileName + ".dot");
+ final File imageFile = new File(targetDirectory, resultFileName + "." + targetImageType.fileExtension);
try {
// write DOT file to disk
try {
// write DOT file to disk
- final PrintWriter out = new PrintWriter(dotFile
Path
, UTF_8);
+ final PrintWriter out = new PrintWriter(dotFile, UTF_8);
out.write(getDot());
out.close();
// execute GraphViz to visualize graph
try {
Runtime.getRuntime()
out.write(getDot());
out.close();
// execute GraphViz to visualize graph
try {
Runtime.getRuntime()
- .exec(new String[]{"dot", "-Tsvg", 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
} 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) {
} catch (final IOException e) {
-
System.err.println(
e);
+
throw new RuntimeException("Unable to generate graph: " + e.getMessage(),
e);
}
}
private String getDot() {
}
}
private String getDot() {
- final StringBu
ffer result = new StringBuff
er();
+ final StringBu
ilder result = new StringBuild
er();
result.append("digraph Java {\n");
result.append("graph [rankdir=LR, overlap = false, concentrate=true];\n");
result.append("digraph Java {\n");
result.append("graph [rankdir=LR, overlap = false, concentrate=true];\n");
@@
-132,8
+137,7
@@
public class ClassGraph {
result.append("}\n");
result.append("}\n");
- final String resultStr = result.toString();
- return resultStr;
+ return result.toString();
}
/**
}
/**
@@
-176,12
+180,12
@@
public class ClassGraph {
}
protected boolean isClassShown(final String className) {
}
protected boolean isClassShown(final String className) {
- for (final String pattern : blacklistClass
Pattern
s)
+ for (final String pattern : blacklistClass
Glob
s)
if (WildCardMatcher.match(className, pattern))
return false;
if (WildCardMatcher.match(className, pattern))
return false;
- if (!whitelistClass
Pattern
s.isEmpty()) {
- for (final String pattern : whitelistClass
Pattern
s)
+ if (!whitelistClass
Glob
s.isEmpty()) {
+ for (final String pattern : whitelistClass
Glob
s)
if (WildCardMatcher.match(className, pattern))
return true;
return false;
if (WildCardMatcher.match(className, pattern))
return true;
return false;
@@
-196,18
+200,13
@@
public class ClassGraph {
return this;
}
return this;
}
- public ClassGraph setTargetDirectory(String directoryPath) {
- if (!directoryPath.endsWith("/"))
- directoryPath += "/";
-
- targetDirectory = directoryPath;
-
+ public ClassGraph setTargetDirectory(File targetDirectory) {
+ this.targetDirectory = targetDirectory;
return this;
}
return this;
}
- public ClassGraph whitelistClassPattern(final String pattern) {
- whitelistClassPatterns.add(pattern);
-
+ public ClassGraph whitelistClassGlob(final String glob) {
+ whitelistClassGlobs.add(glob);
return this;
}
return this;
}