public class ClassGraph extends Object
Documentation: https://github.com/lukehutch/fast-classpath-scanner/wiki
Modifier and Type | Class | Description |
---|---|---|
static interface |
ClassGraph.ClasspathElementFilter |
Add a classpath element filter.
|
static interface |
ClassGraph.FailureHandler |
A callback used to handle failure during an asynchronous scan.
|
static interface |
ClassGraph.ScanResultProcessor |
A callback used to process the result of a successful asynchronous scan.
|
Constructor | Description |
---|---|
ClassGraph() |
Construct a ClassGraph instance.
|
Modifier and Type | Method | Description |
---|---|---|
ClassGraph |
addClassLoader(ClassLoader classLoader) |
Add a ClassLoader to the list of ClassLoaders to scan.
|
ClassGraph |
blacklistClasses(String... classNames) |
Specifically blacklist one or more specific classes, preventing them from being scanned even if they are in a
whitelisted package.
|
ClassGraph |
blacklistJars(String... jarLeafNames) |
Blacklist one or more jars, preventing them from being scanned.
|
ClassGraph |
blacklistLibOrExtJars(String... jarLeafNames) |
Blacklist one or more jars in a JRE/JDK "lib/" or "ext/" directory, preventing them from being scanned.
|
ClassGraph |
blacklistModules(String... moduleNames) |
Blacklist one or more modules, preventing them from being scanned.
|
ClassGraph |
blacklistPackages(String... packageNames) |
Prevent the scanning of one or more specific packages and their sub-packages.
|
ClassGraph |
blacklistPaths(String... paths) |
Prevent the scanning of one or more specific paths and their sub-directories / nested paths.
|
ClassGraph |
disableDirScanning() |
Disables the scanning of directories.
|
ClassGraph |
disableJarScanning() |
Disables the scanning of jarfiles.
|
ClassGraph |
disableModuleScanning() |
Disables the scanning of modules.
|
ClassGraph |
disableNestedJarScanning() |
Disables the scanning of nested jarfiles (jarfiles within jarfiles).
|
ClassGraph |
disableRuntimeInvisibleAnnotations() |
Causes only runtime visible annotations to be scanned (causes runtime invisible annotations to be ignored).
|
ClassGraph |
enableAllInfo() |
Enables the scanning of all classes, fields, methods, annotations, and static final field constant
initializer values, and ignores all visibility modifiers, so that both public and non-public classes, fields
and methods are all scanned.
|
ClassGraph |
enableAnnotationInfo() |
Enables the saving of annotation info (for class, field, method and method parameter annotations) during the
scan.
|
ClassGraph |
enableClassInfo() |
Enables the scanning of classfiles, producing
ClassInfo objects in the ScanResult . |
ClassGraph |
enableExternalClasses() |
Causes ClassGraph to return classes that are not in the whitelisted packages, but that are directly referred
to by classes within whitelisted packages as a superclass, implemented interface or annotation.
|
ClassGraph |
enableFieldInfo() |
Enables the saving of field info during the scan.
|
ClassGraph |
enableMethodInfo() |
Enables the saving of method info during the scan.
|
ClassGraph |
enableStaticFinalFieldConstantInitializerValues() |
Enables the saving of static final field constant initializer values.
|
ClassGraph |
enableSystemPackages() |
Enables the scanning of system packages (java.*, jdk.*, oracle.*, etc.) -- these are not scanned by default
for speed.
|
ClassGraph |
filterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter) |
Add a classpath element filter.
|
String |
getClasspath() |
Returns the list of all unique File objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order, in the form of a classpath path string.
|
List<File> |
getClasspathFiles() |
Returns the list of all unique File objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order.
|
List<URL> |
getClasspathURLs() |
Returns the list of all unique URL objects representing directories, zip/jarfiles or modules on the
classpath, in classloader resolution order.
|
List<ModuleRef> |
getModules() |
Returns
ModuleRef references for all the visible modules. |
static String |
getVersion() |
Get the version number of ClassGraph.
|
ClassGraph |
ignoreClassVisibility() |
Causes class visibility to be ignored, enabling private, package-private and protected classes to be scanned.
|
ClassGraph |
ignoreFieldVisibility() |
Causes field visibility to be ignored, enabling private, package-private and protected fields to be scanned.
|
ClassGraph |
ignoreMethodVisibility() |
Causes method visibility to be ignored, enabling private, package-private and protected methods to be
scanned.
|
ClassGraph |
ignoreParentClassLoaders() |
Ignore parent classloaders (i.e.
|
ClassGraph |
initializeLoadedClasses() |
Causes classes loaded using
ClassInfo.loadClass() to be are initialized after class loading (the
default is to not initialize classes). |
ClassGraph |
overrideClassLoaders(ClassLoader... overrideClassLoaders) |
Completely override (and ignore) system ClassLoaders and the java.class.path system property.
|
ClassGraph |
overrideClasspath(Iterable<?> overrideClasspathElements) |
Override the automatically-detected classpath with a custom path.
|
ClassGraph |
overrideClasspath(Object... overrideClasspathElements) |
Override the automatically-detected classpath with a custom path.
|
ClassGraph |
overrideClasspath(String overrideClasspath) |
Override the automatically-detected classpath with a custom path, with path elements separated by
File.pathSeparatorChar.
|
ClassGraph |
registerClassLoaderHandler(Class<? extends ClassLoaderHandler> classLoaderHandlerClass) |
Register an extra ClassLoaderHandler.
|
ClassGraph |
removeTemporaryFilesAfterScan() |
Remove temporary files, including nested jarfiles (jarfiles within jarfiles, which have to be extracted
during scanning in order to be read) from their temporary directory as soon as the scan has completed.
|
ScanResult |
scan() |
Scans the classpath for matching files, and calls any MatchProcessors if a match is identified.
|
ScanResult |
scan(int numThreads) |
Scans the classpath for matching files, and calls any MatchProcessors if a match is identified.
|
ScanResult |
scan(ExecutorService executorService,
int numParallelTasks) |
Scans the classpath for matching files, and calls any MatchProcessors if a match is identified.
|
Future<ScanResult> |
scanAsync(ExecutorService executorService,
int numParallelTasks) |
Asynchronously scans the classpath for matching files, and calls any MatchProcessors if a match is
identified.
|
void |
scanAsync(ExecutorService executorService,
int numParallelTasks,
ClassGraph.ScanResultProcessor scanResultProcessor,
ClassGraph.FailureHandler failureHandler) |
Asynchronously scans the classpath for matching files, and if runAsynchronously is true, also calls any
MatchProcessors if a match is identified.
|
ClassGraph |
stripZipSFXHeaders() |
Manually strip the self extracting executable header from zipfiles (i.e.
|
ClassGraph |
verbose() |
Switches on verbose logging to System.err.
|
ClassGraph |
whitelistClasses(String... classNames) |
Scan one or more specific classes, without scanning other classes in the same package unless the package is
itself whitelisted.
|
ClassGraph |
whitelistJars(String... jarLeafNames) |
Whitelist one or more jars.
|
ClassGraph |
whitelistLibOrExtJars(String... jarLeafNames) |
Whitelist one or more jars in a JRE/JDK "lib/" or "ext/" directory (these directories are not scanned unless
enableSystemPackages() is called, by association with the JRE/JDK). |
ClassGraph |
whitelistModules(String... moduleNames) |
Whitelist one or more modules to scan.
|
ClassGraph |
whitelistPackages(String... packageNames) |
Scan one or more specific packages and their sub-packages.
|
ClassGraph |
whitelistPackagesNonRecursive(String... packageNames) |
Scan one or more specific packages, without recursively scanning sub-packages unless they are themselves
whitelisted.
|
ClassGraph |
whitelistPaths(String... paths) |
Scan one or more specific paths, and their sub-directories or nested paths.
|
ClassGraph |
whitelistPathsNonRecursive(String... paths) |
Scan one or more specific paths, without recursively scanning sub-directories or nested paths unless they are
themselves whitelisted.
|
public static final String getVersion()
public ClassGraph verbose()
public ClassGraph enableAllInfo()
Calls enableClassInfo()
, enableFieldInfo()
, enableMethodInfo()
,
enableAnnotationInfo()
, enableStaticFinalFieldConstantInitializerValues()
,
ignoreClassVisibility()
, ignoreFieldVisibility()
, and ignoreMethodVisibility()
.
public ClassGraph enableClassInfo()
ClassInfo
objects in the ScanResult
.public ClassGraph ignoreClassVisibility()
enableClassInfo()
.)public ClassGraph enableMethodInfo()
ClassInfo.getMethodInfo()
etc. By default, method info is not scanned. (Automatically calls
enableClassInfo()
.)public ClassGraph ignoreMethodVisibility()
enableClassInfo()
and
enableMethodInfo()
.)public ClassGraph enableFieldInfo()
ClassInfo.getFieldInfo()
. By default, field info is not scanned. (Automatically calls
enableClassInfo()
.)public ClassGraph ignoreFieldVisibility()
enableClassInfo()
and
enableFieldInfo()
.)public ClassGraph enableStaticFinalFieldConstantInitializerValues()
enableClassInfo()
and enableFieldInfo()
.public ClassGraph enableAnnotationInfo()
ClassInfo.getAnnotationInfo()
,
FieldInfo.getAnnotationInfo()
, and MethodParameterInfo.getAnnotationInfo()
. By default,
annotation info is not scanned. (Automatically calls enableClassInfo()
.)public ClassGraph disableRuntimeInvisibleAnnotations()
enableClassInfo()
.)public ClassGraph disableJarScanning()
public ClassGraph disableNestedJarScanning()
public ClassGraph disableDirScanning()
public ClassGraph disableModuleScanning()
public ClassGraph enableExternalClasses()
enableClassInfo()
.)public ClassGraph initializeLoadedClasses()
ClassInfo.loadClass()
to be are initialized after class loading (the
default is to not initialize classes).public ClassGraph removeTemporaryFilesAfterScan()
ScanResult
finalizer, or on JVM exit.public ClassGraph stripZipSFXHeaders()
Should only be needed in rare cases, where you are dealing with jarfiles with prepended (ZipSFX) headers, where your JVM does not already automatically skip forward to the first "PK" marker (most JVMs should do this automatically, so this option should not be needed).
public ClassGraph registerClassLoaderHandler(Class<? extends ClassLoaderHandler> classLoaderHandlerClass)
https://github.com/lukehutch/fast-classpath-scanner/wiki/4.-Working-with-nonstandard-ClassLoaders
classLoaderHandlerClass
- The ClassLoaderHandler class to register.public ClassGraph overrideClasspath(String overrideClasspath)
If this method is called, nothing but the provided classpath will be scanned, i.e. this causes ClassLoaders to be ignored, as well as the java.class.path system property.
overrideClasspath
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public ClassGraph overrideClasspath(Iterable<?> overrideClasspathElements)
If this method is called, nothing but the provided classpath will be scanned, i.e. this causes ClassLoaders to be ignored, as well as the java.class.path system property.
overrideClasspathElements
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public ClassGraph overrideClasspath(Object... overrideClasspathElements)
overrideClasspathElements
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public ClassGraph filterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter)
classpathElementFilter
- The filter function to use. This function should return true if the classpath element path should
be scanned, and false if not.public ClassGraph addClassLoader(ClassLoader classLoader)
This call is ignored if overrideClasspath() is also called, or if this method is called before overrideClassLoaders().
This call is ignored if overrideClasspath() is called.
classLoader
- The additional ClassLoader to scan.public ClassGraph overrideClassLoaders(ClassLoader... overrideClassLoaders)
This call is ignored if overrideClasspath() is called.
overrideClassLoaders
- The ClassLoaders to scan instead of the automatically-detected ClassLoaders.public ClassGraph ignoreParentClassLoaders()
public ClassGraph whitelistPackages(String... packageNames)
enableClassInfo()
.)packageNames
- The fully-qualified names of packages to scan (using '.' as a separator). May include a glob
wildcard ('*').public ClassGraph whitelistPaths(String... paths)
paths
- The paths to scan, relative to the package root of the classpath element (with '/' as a
separator). May include a glob wildcard ('*').public ClassGraph whitelistPackagesNonRecursive(String... packageNames)
enableClassInfo()
.)
This may be particularly useful for scanning the package root ("") without recursively scanning everything in the jar, dir or module.
packageNames
- The fully-qualified names of packages to scan (with '.' as a separator).public ClassGraph whitelistPathsNonRecursive(String... paths)
This may be particularly useful for scanning the package root ("") without recursively scanning everything in the jar, dir or module.
paths
- The paths to scan, relative to the package root of the classpath element (with '/' as a
separator).public ClassGraph blacklistPackages(String... packageNames)
enableClassInfo()
.)packageNames
- The fully-qualified names of packages to blacklist (with '.' as a separator). May include a glob
wildcard ('*').public ClassGraph blacklistPaths(String... paths)
paths
- The paths to blacklist (with '/' as a separator). May include a glob wildcard ('*').public ClassGraph whitelistClasses(String... classNames)
enableClassInfo()
.)classNames
- The fully-qualified names of classes to scan (using '.' as a separator).public ClassGraph blacklistClasses(String... classNames)
enableClassInfo()
.)classNames
- The fully-qualified names of classes to blacklist (using '.' as a separator).public ClassGraph whitelistJars(String... jarLeafNames)
jarLeafNames
- The leafnames of the jars that should be scanned (e.g. "badlib.jar"). May contain a wildcard glob
('*').public ClassGraph blacklistJars(String... jarLeafNames)
jarLeafNames
- The leafnames of the jars that should not be scanned (e.g. "badlib.jar"). May contain a wildcard
glob ('*').public ClassGraph whitelistLibOrExtJars(String... jarLeafNames)
enableSystemPackages()
is called, by association with the JRE/JDK).jarLeafNames
- The leafnames of the lib/ext jar(s) that should be scanned (e.g. "mylib.jar"). May contain a
wildcard glob ('*'). If you call this method with no parameters, all JRE/JDK "lib/" or "ext/" jars
will be whitelisted.public ClassGraph blacklistLibOrExtJars(String... jarLeafNames)
jarLeafNames
- The leafnames of the lib/ext jar(s) that should not be scanned (e.g. "badlib.jar"). May contain a
wildcard glob ('*'). If you call this method with no parameters, all JRE/JDK "lib/" or "ext/" jars
will be blacklisted.public ClassGraph whitelistModules(String... moduleNames)
moduleNames
- The names of the modules that should not be scanned. May contain a wildcard glob ('*').public ClassGraph blacklistModules(String... moduleNames)
moduleNames
- The names of the modules that should not be scanned. May contain a wildcard glob ('*').public ClassGraph enableSystemPackages()
enableClassInfo()
.)public void scanAsync(ExecutorService executorService, int numParallelTasks, ClassGraph.ScanResultProcessor scanResultProcessor, ClassGraph.FailureHandler failureHandler)
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.scanResultProcessor
- A callback to run on successful scan. Passed the ScanResult after asynchronous scanning has
completed and MatchProcessors have been run. (If null, throws IllegalArgumentException.)failureHandler
- A callback to run on failed scan. Passed any Throwable thrown during the scan. (If null, throws
IllegalArgumentException.)public Future<ScanResult> scanAsync(ExecutorService executorService, int numParallelTasks)
Note on thread safety: MatchProcessors are all run on a separate thread from the thread that calls this method (although the MatchProcessors are all run on one thread). You will need to add your own synchronization logic if MatchProcessors interact with the main thread. See the following for more info:
https://github.com/lukehutch/fast-classpath-scanner/wiki/1.-Usage#multithreading-issues
executorService
- A custom ExecutorService to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.Future<ScanResult>
, that when resolved using get() yields a new ScanResult
object.
This ScanResult
object contains info about the class graph within whitelisted packages
encountered during the scan. Calling get() on this Future object throws InterruptedException if the
scanning is interrupted before it completes, or throws ExecutionException if something goes wrong
during scanning. If ExecutionException is thrown, and the cause is a MatchProcessorException, then
either classloading failed for some class, or a MatchProcessor threw an exception.public ScanResult scan(ExecutorService executorService, int numParallelTasks)
executorService
- A custom ExecutorService to use for scheduling worker tasks. This ExecutorService should start
tasks in FIFO order to avoid a deadlock during scan, i.e. be sure to construct the ExecutorService
with a LinkedBlockingQueue as its task queue. (This is the default for
Executors.newFixedThreadPool().)numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.ScanResult
object, containing info about the class graph within whitelisted packages
encountered during the scan.RuntimeException
- if any of the worker threads throws an uncaught exception. (Should not happen, this would
indicate a bug in ClassGraph.)public ScanResult scan(int numThreads)
numThreads
- The number of worker threads to start up.ScanResult
object, containing info about the class graph within whitelisted packages
encountered during the scan.RuntimeException
- if any of the worker threads throws an uncaught exception. (Should not happen, this would
indicate a bug in ClassGraph.)public ScanResult scan()
RuntimeException
- if any of the worker threads throws an uncaught exception. (Should not happen, this would
indicate a bug in ClassGraph.)public List<File> getClasspathFiles()
List<File>
consisting of the unique directories and jarfiles on the classpath, in classpath
resolution order.public String getClasspath()
public List<URL> getClasspathURLs()
Copyright © 2018. All rights reserved.