private NullParameter showDebug;
public StringParameters whitelistGlob;
public StringParameters blacklistGlob;
+ public StringParameters rootClasses;
public TargetImageTypeParameter targetImageType;
public NullParameter keepDotFile;
public DirectoryParameter targetDirectory;
new StringParameters("Blacklist glob(s)."))
.addAliases("-b");
+ rootClasses = parser.add(
+ new StringParameters("root class(es)."))
+ .addAliases("-r");
+
+
targetDirectory = parser.add(new DirectoryParameter("Target directory. " +
"Default is current directory.").mustExist())
.addAliases("-d");
classGraph.setKeepDotFile(configuration.keepDotFile.getValue());
- for (File jarFile : jarFiles)
- addJarToGraph(jarFile, classLoader, classGraph, configuration);
-
+ if (configuration.rootClasses.isSpecified()){
+ // add only selected root classes
+ for (String rootClass : configuration.rootClasses.getValue())
+ attemptClassAdditionByName(classLoader, classGraph, configuration, rootClass);
+
+ } else {
+ // add all classes in the jar files to graph
+ for (File jarFile : jarFiles)
+ addJarToGraph(jarFile, classLoader, classGraph, configuration);
+ }
configuration.blacklistGlob.getValue().forEach(classGraph::blacklistClassGlob);
configuration.whitelistGlob.getValue().forEach(classGraph::whitelistClassGlob);
File jarFile, URLClassLoader classLoader, ClassGraph classGraph, CommandlineConfiguration configuration)
throws IOException, ClassNotFoundException {
- for (String className : getClassNamesFromJar(jarFile)) {
+ for (String className : getClassNamesFromJar(jarFile))
+ attemptClassAdditionByName(classLoader, classGraph, configuration, className);
+ }
+
+ private static void attemptClassAdditionByName(URLClassLoader classLoader, ClassGraph classGraph, CommandlineConfiguration configuration, String className) throws ClassNotFoundException {
+ if (configuration.isDebug())
+ System.out.println("Adding class to graph: " + className);
+ try {
+ classGraph.add(loadClassByName(classLoader, className));
+ } catch (NoClassDefFoundError e){
if (configuration.isDebug())
- System.out.println("Adding class to graph: " + className);
- try {
- classGraph.add(loadClassByName(classLoader, className));
- } catch (NoClassDefFoundError e){
- if (configuration.isDebug())
- System.out.println("Class definition was not found.");
- // Sometimes referenced classes are not found in the same Jar.
- // Let's ignore this and proceed with the classes that we have.
- }
+ System.out.println("Class definition was not found.");
+ // Sometimes referenced classes are not found in the same Jar.
+ // Let's ignore this and proceed with the classes that we have.
}
}