public String getGraphId() {
final String result = "class_"
+ fullyQualifiedName.replace('.', '_').replace(";", "")
- .replace("[L", "").replace('$', '_');
+ .replace("[L", "").replace('$', '_');
return result;
}
if (Utils.isSystemPackage(fullyQualifiedName))
return false;
- if (!getClassGraph().getFilter().isClassShown(fullyQualifiedName))
+ if (!getClassGraph().isClassShown(fullyQualifiedName))
return false;
if (isArray)
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import eu.svjatoslav.commons.file.CommonPathResolver;
+import eu.svjatoslav.commons.string.WildCardMatcher;
import eu.svjatoslav.inspector.java.methods.Clazz;
import eu.svjatoslav.inspector.java.methods.ProjectScanner;
*/
private final Map<String, ClassDescriptor> fullyQualifiedNameToClassMap = new HashMap<String, ClassDescriptor>();
- private final Filter filter = new Filter();
+ private final List<String> blacklistClassPatterns = new ArrayList<String>();
+
+ private final List<String> whitelistClassPatterns = new ArrayList<String>();
public ClassGraph() {
}
}
}
+ public void blacklistClassPattern(final String pattern) {
+ blacklistClassPatterns.add(pattern);
+ }
+
/**
* @param resultFileName
* file name for the generated graph. Existing file with the same
// execute GraphViz to visualize graph
try {
Runtime.getRuntime()
- .exec(new String[] { "dot", "-Tpng", dotFilePath, "-o",
- imageFilePath }).waitFor();
+ .exec(new String[] { "dot", "-Tpng", dotFilePath, "-o",
+ imageFilePath }).waitFor();
} catch (final InterruptedException e) {
} finally {
}
return resultStr;
}
- public Filter getFilter() {
- return filter;
- }
-
/**
* @param clazz
* class that shall be added to graph
}
+ public boolean isClassShown(final String className) {
+ for (final String pattern : blacklistClassPatterns)
+ if (WildCardMatcher.match(className, pattern))
+ return false;
+
+ if (!whitelistClassPatterns.isEmpty()) {
+ for (final String pattern : whitelistClassPatterns)
+ if (WildCardMatcher.match(className, pattern))
+ return true;
+ return false;
+ }
+
+ return true;
+ }
+
+ public void whitelistClassPattern(final String pattern) {
+ whitelistClassPatterns.add(pattern);
+ }
+
}
+++ /dev/null
-/*
- * JavaInspect - Utility to visualize java software
- * Copyright (C) 2013-2015, 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
- * or later as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.inspector.java.structure;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import eu.svjatoslav.commons.string.WildCardMatcher;
-
-public class Filter {
-
- /**
- * This class implements filter of classes that will be included or excluded
- * from resulting graph.
- *
- * Filtering is done by lists of whitelist and blacklist patterns using
- * wildcards.
- *
- * Filtering logic is such that if at least single whitelist entry is
- * defined then every class that is not whitelisted is automatically
- * excluded from graph.
- *
- * Otherwise every class in included in graph that is not blacklisted.
- */
-
- private final List<String> blacklistClassPatterns = new ArrayList<String>();
-
- private final List<String> whitelistClassPatterns = new ArrayList<String>();
-
- public void blacklistClassPattern(final String pattern) {
- blacklistClassPatterns.add(pattern);
- }
-
- public boolean isClassShown(final String className) {
- for (final String pattern : blacklistClassPatterns)
- if (WildCardMatcher.match(className, pattern))
- return false;
-
- if (!whitelistClassPatterns.isEmpty()) {
- for (final String pattern : whitelistClassPatterns)
- if (WildCardMatcher.match(className, pattern))
- return true;
- return false;
- }
-
- return true;
- }
-
- public void whitelistClassPattern(final String pattern) {
- whitelistClassPatterns.add(pattern);
- }
-
-}
graph.addProject(".");
// Blacklist example classes from being shown on the graph
- graph.getFilter().blacklistClassPattern(
- "eu.svjatoslav.inspector.java.structure.example.*");
+ graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
// do not show single classes with no relationships on the graph
graph.hideOrphanedClasses();