Class ClassGraph
- java.lang.Object
-
- io.github.classgraph.ClassGraph
-
public class ClassGraph extends Object
Uber-fast, ultra-lightweight Java classpath and module path scanner. Scans classfiles in the classpath and/or module path by parsing the classfile binary format directly rather than by using reflection.Documentation: https://github.com/classgraph/classgraph/wiki
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceClassGraph.ClasspathElementFilterAdd a classpath element filter.static interfaceClassGraph.FailureHandlerA callback used to handle failure during an asynchronous scan.static interfaceClassGraph.ScanResultProcessorA callback used to process the result of a successful asynchronous scan.
-
Constructor Summary
Constructors Constructor Description ClassGraph()Construct a ClassGraph instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ClassGraphaddClassLoader(ClassLoader classLoader)Add a ClassLoader to the list of ClassLoaders to scan.ClassGraphaddModuleLayer(Object moduleLayer)Add a ModuleLayer to the list of ModuleLayers to scan.ClassGraphblacklistClasses(String... classNames)Specifically blacklist one or more specific classes, preventing them from being scanned even if they are in a whitelisted package.ClassGraphblacklistClasspathElementsContainingResourcePath(String... resourcePaths)Blacklist classpath elements based on resource paths.ClassGraphblacklistJars(String... jarLeafNames)Blacklist one or more jars, preventing them from being scanned.ClassGraphblacklistLibOrExtJars(String... jarLeafNames)Blacklist one or more jars in a JRE/JDK "lib/" or "ext/" directory, preventing them from being scanned.ClassGraphblacklistModules(String... moduleNames)Blacklist one or more modules, preventing them from being scanned.ClassGraphblacklistPackages(String... packageNames)Prevent the scanning of one or more specific packages and their sub-packages.ClassGraphblacklistPaths(String... paths)Prevent the scanning of one or more specific paths and their sub-directories / nested paths.ClassGraphdisableDirScanning()Disables the scanning of directories.ClassGraphdisableJarScanning()Disables the scanning of jarfiles.ClassGraphdisableModuleScanning()Disables the scanning of modules.ClassGraphdisableNestedJarScanning()Disables the scanning of nested jarfiles (jarfiles within jarfiles).ClassGraphdisableRuntimeInvisibleAnnotations()Causes only runtime visible annotations to be scanned (causes runtime invisible annotations to be ignored).ClassGraphenableAllInfo()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.ClassGraphenableAnnotationInfo()Enables the saving of annotation info (for class, field, method and method parameter annotations) during the scan.ClassGraphenableClassInfo()Enables the scanning of classfiles, producingClassInfoobjects in theScanResult.ClassGraphenableExternalClasses()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.ClassGraphenableFieldInfo()Enables the saving of field info during the scan.ClassGraphenableInterClassDependencies()Enables the determination of inter-class dependencies, which may be read by callingClassInfo.getClassDependencies(),ScanResult.getClassDependencyMap()orScanResult.getReverseClassDependencyMap().ClassGraphenableMethodInfo()Enables the saving of method info during the scan.ClassGraphenableRealtimeLogging()Enables logging by callingverbose(), and then sets the logger to "realtime logging mode", where log entries are written out immediately to stderr, rather than only after the scan has completed.ClassGraphenableRemoteJarScanning()Enable classpath elements to be fetched from remote http/https URLs to local temporary files and scanned.ClassGraphenableStaticFinalFieldConstantInitializerValues()Enables the saving of static final field constant initializer values.ClassGraphenableSystemJarsAndModules()Enables the scanning of system packages ("java.*","javax.*","javafx.*","jdk.*","oracle.*","sun.*") -- these are not scanned by default for speed.ClassGraphenableSystemPackages()Deprecated.UseenableSystemJarsAndModules()instead.ClassGraphfilterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter)Add a classpath element filter.StringgetClasspath()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()ReturnsModuleRefreferences for all the visible modules.static StringgetVersion()Get the version number of ClassGraph.ClassGraphignoreClassVisibility()Causes class visibility to be ignored, enabling private, package-private and protected classes to be scanned.ClassGraphignoreFieldVisibility()Causes field visibility to be ignored, enabling private, package-private and protected fields to be scanned.ClassGraphignoreMethodVisibility()Causes method visibility to be ignored, enabling private, package-private and protected methods to be scanned.ClassGraphignoreParentClassLoaders()Ignore parent classloaders (i.e.ClassGraphignoreParentModuleLayers()Ignore parent module layers (i.e.ClassGraphinitializeLoadedClasses()Causes classes loaded usingClassInfo.loadClass()to be are initialized after class loading (the default is to not initialize classes).ClassGraphoverrideClassLoaders(ClassLoader... overrideClassLoaders)Completely override (and ignore) system ClassLoaders and the java.class.path system property.ClassGraphoverrideClasspath(Iterable<?> overrideClasspathElements)Override the automatically-detected classpath with a custom path.ClassGraphoverrideClasspath(Object... overrideClasspathElements)Override the automatically-detected classpath with a custom path.ClassGraphoverrideClasspath(String overrideClasspath)Override the automatically-detected classpath with a custom path, with path elements separated by File.pathSeparatorChar.ClassGraphoverrideModuleLayers(Object... overrideModuleLayers)Completely override (and ignore) the visible ModuleLayers, and instead scan the requested ModuleLayers.ClassGraphremoveTemporaryFilesAfterScan()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.ScanResultscan()Scans the classpath, blocking until the scan is complete.ScanResultscan(int numThreads)Scans the classpath with the requested number of threads, blocking until the scan is complete.ScanResultscan(ExecutorService executorService, int numParallelTasks)Scans the classpath using the requestedExecutorServiceand the requested degree of parallelism, blocking until the scan is complete.Future<ScanResult>scanAsync(ExecutorService executorService, int numParallelTasks)Asynchronously scans the classpath for matching files, returning aFuture<ScanResult>.voidscanAsync(ExecutorService executorService, int numParallelTasks, ClassGraph.ScanResultProcessor scanResultProcessor, ClassGraph.FailureHandler failureHandler)Asynchronously scans the classpath, calling aClassGraph.ScanResultProcessorcallback on success or aClassGraph.FailureHandlercallback on failure.ClassGraphverbose()Switches on verbose logging to System.err.ClassGraphwhitelistClasses(String... classNames)Scan one or more specific classes, without scanning other classes in the same package unless the package is itself whitelisted.ClassGraphwhitelistClasspathElementsContainingResourcePath(String... resourcePaths)Whitelist classpath elements based on resource paths.ClassGraphwhitelistJars(String... jarLeafNames)Whitelist one or more jars.ClassGraphwhitelistLibOrExtJars(String... jarLeafNames)Whitelist one or more jars in a JRE/JDK "lib/" or "ext/" directory (these directories are not scanned unlessenableSystemPackages()is called, by association with the JRE/JDK).ClassGraphwhitelistModules(String... moduleNames)Whitelist one or more modules to scan.ClassGraphwhitelistPackages(String... packageNames)Scan one or more specific packages and their sub-packages.ClassGraphwhitelistPackagesNonRecursive(String... packageNames)Scan one or more specific packages, without recursively scanning sub-packages unless they are themselves whitelisted.ClassGraphwhitelistPaths(String... paths)Scan one or more specific paths, and their sub-directories or nested paths.ClassGraphwhitelistPathsNonRecursive(String... paths)Scan one or more specific paths, without recursively scanning sub-directories or nested paths unless they are themselves whitelisted.
-
-
-
Method Detail
-
getVersion
public static String getVersion()
Get the version number of ClassGraph.- Returns:
- the ClassGraph version, or "unknown" if it could not be determined.
-
verbose
public ClassGraph verbose()
Switches on verbose logging to System.err.- Returns:
- this (for method chaining).
-
enableAllInfo
public 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.Calls
enableClassInfo(),enableFieldInfo(),enableMethodInfo(),enableAnnotationInfo(),enableStaticFinalFieldConstantInitializerValues(),ignoreClassVisibility(),ignoreFieldVisibility(), andignoreMethodVisibility().- Returns:
- this (for method chaining).
-
enableClassInfo
public ClassGraph enableClassInfo()
Enables the scanning of classfiles, producingClassInfoobjects in theScanResult.- Returns:
- this (for method chaining).
-
ignoreClassVisibility
public ClassGraph ignoreClassVisibility()
Causes class visibility to be ignored, enabling private, package-private and protected classes to be scanned. By default, only public classes are scanned. (Automatically callsenableClassInfo().)- Returns:
- this (for method chaining).
-
enableMethodInfo
public ClassGraph enableMethodInfo()
Enables the saving of method info during the scan. This information can be obtained usingClassInfo.getMethodInfo()etc. By default, method info is not scanned. (Automatically callsenableClassInfo().)- Returns:
- this (for method chaining).
-
ignoreMethodVisibility
public ClassGraph ignoreMethodVisibility()
Causes method visibility to be ignored, enabling private, package-private and protected methods to be scanned. By default, only public methods are scanned. (Automatically callsenableClassInfo()andenableMethodInfo().)- Returns:
- this (for method chaining).
-
enableFieldInfo
public ClassGraph enableFieldInfo()
Enables the saving of field info during the scan. This information can be obtained usingClassInfo.getFieldInfo(). By default, field info is not scanned. (Automatically callsenableClassInfo().)- Returns:
- this (for method chaining).
-
ignoreFieldVisibility
public ClassGraph ignoreFieldVisibility()
Causes field visibility to be ignored, enabling private, package-private and protected fields to be scanned. By default, only public fields are scanned. (Automatically callsenableClassInfo()andenableFieldInfo().)- Returns:
- this (for method chaining).
-
enableStaticFinalFieldConstantInitializerValues
public ClassGraph enableStaticFinalFieldConstantInitializerValues()
Enables the saving of static final field constant initializer values. By default, constant initializer values are not scanned. Automatically callsenableClassInfo()andenableFieldInfo().- Returns:
- this (for method chaining).
-
enableAnnotationInfo
public ClassGraph enableAnnotationInfo()
Enables the saving of annotation info (for class, field, method and method parameter annotations) during the scan. This information can be obtained usingClassInfo.getAnnotationInfo(),FieldInfo.getAnnotationInfo(), andMethodParameterInfo.getAnnotationInfo(). By default, annotation info is not scanned. (Automatically callsenableClassInfo().)- Returns:
- this (for method chaining).
-
enableInterClassDependencies
public ClassGraph enableInterClassDependencies()
Enables the determination of inter-class dependencies, which may be read by callingClassInfo.getClassDependencies(),ScanResult.getClassDependencyMap()orScanResult.getReverseClassDependencyMap(). (Automatically callsenableClassInfo(),enableFieldInfo(),enableMethodInfo(),enableAnnotationInfo(),ignoreClassVisibility(),ignoreFieldVisibility()andignoreMethodVisibility().)
-
disableRuntimeInvisibleAnnotations
public ClassGraph disableRuntimeInvisibleAnnotations()
Causes only runtime visible annotations to be scanned (causes runtime invisible annotations to be ignored). (Automatically callsenableClassInfo().)- Returns:
- this (for method chaining).
-
disableJarScanning
public ClassGraph disableJarScanning()
Disables the scanning of jarfiles.- Returns:
- this (for method chaining).
-
disableNestedJarScanning
public ClassGraph disableNestedJarScanning()
Disables the scanning of nested jarfiles (jarfiles within jarfiles).- Returns:
- this (for method chaining).
-
disableDirScanning
public ClassGraph disableDirScanning()
Disables the scanning of directories.- Returns:
- this (for method chaining).
-
disableModuleScanning
public ClassGraph disableModuleScanning()
Disables the scanning of modules.- Returns:
- this (for method chaining).
-
enableExternalClasses
public 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. (Automatically callsenableClassInfo().)- Returns:
- this (for method chaining).
-
initializeLoadedClasses
public ClassGraph initializeLoadedClasses()
Causes classes loaded usingClassInfo.loadClass()to be are initialized after class loading (the default is to not initialize classes).- Returns:
- this (for method chaining).
-
removeTemporaryFilesAfterScan
public 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. The default is for temporary files to be removed by theScanResultfinalizer, or on JVM exit.- Returns:
- this (for method chaining).
-
overrideClasspath
public ClassGraph overrideClasspath(String overrideClasspath)
Override the automatically-detected classpath with a custom path, with path elements separated by File.pathSeparatorChar. Causes system ClassLoaders and the java.class.path system property to be ignored. Also causes modules not to be scanned.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.
- Parameters:
overrideClasspath- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.- Returns:
- this (for method chaining).
-
overrideClasspath
public ClassGraph overrideClasspath(Iterable<?> overrideClasspathElements)
Override the automatically-detected classpath with a custom path. Causes system ClassLoaders and the java.class.path system property to be ignored. Also causes modules not to be scanned.Works for Iterables of any type whose toString() method resolves to a classpath element string, e.g. String, File or Path.
- Parameters:
overrideClasspathElements- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.- Returns:
- this (for method chaining).
-
overrideClasspath
public ClassGraph overrideClasspath(Object... overrideClasspathElements)
Override the automatically-detected classpath with a custom path. Causes system ClassLoaders and the java.class.path system property to be ignored. Also causes modules not to be scanned.Works for arrays of any member type whose toString() method resolves to a classpath element string, e.g. String, File or Path.
- Parameters:
overrideClasspathElements- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.- Returns:
- this (for method chaining).
-
filterClasspathElements
public ClassGraph filterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter)
Add a classpath element filter. The provided ClasspathElementFilter should return true if the path string passed to it is a path you want to scan.- Parameters:
classpathElementFilter- The filter function to use. This function should return true if the classpath element path should be scanned, and false if not.- Returns:
- this (for method chaining).
-
addClassLoader
public ClassGraph addClassLoader(ClassLoader classLoader)
Add a ClassLoader to the list of ClassLoaders to scan.This call is ignored if
overrideClasspath(String)is also called, or if this method is called beforeoverrideClassLoaders(ClassLoader...).- Parameters:
classLoader- The additional ClassLoader to scan.- Returns:
- this (for method chaining).
-
overrideClassLoaders
public ClassGraph overrideClassLoaders(ClassLoader... overrideClassLoaders)
Completely override (and ignore) system ClassLoaders and the java.class.path system property. Also causes modules not to be scanned.This call is ignored if
overrideClasspath(String)is called.- Parameters:
overrideClassLoaders- The ClassLoaders to scan instead of the automatically-detected ClassLoaders.- Returns:
- this (for method chaining).
-
ignoreParentClassLoaders
public ClassGraph ignoreParentClassLoaders()
Ignore parent classloaders (i.e. only obtain paths to scan from classloaders that are not the parent of another classloader).- Returns:
- this (for method chaining).
-
addModuleLayer
public ClassGraph addModuleLayer(Object moduleLayer)
Add a ModuleLayer to the list of ModuleLayers to scan. Use this method if you define your own ModuleLayer, but the scanning code is not running within that custom ModuleLayer.This call is ignored if it is called before
overrideModuleLayers(Object...).- Parameters:
moduleLayer- The additional ModuleLayer to scan. (The parameter is of typeObjectfor backwards compatibility with JDK 7 and JDK 8, but the argument should be of type ModuleLayer.)- Returns:
- this (for method chaining).
-
overrideModuleLayers
public ClassGraph overrideModuleLayers(Object... overrideModuleLayers)
Completely override (and ignore) the visible ModuleLayers, and instead scan the requested ModuleLayers.This call is ignored if overrideClasspath() is called.
- Parameters:
overrideModuleLayers- The ModuleLayers to scan instead of the automatically-detected ModuleLayers. (The parameter is of typeObject[] for backwards compatibility with JDK 7 and JDK 8, but the argument should be of type ModuleLayer[].)- Returns:
- this (for method chaining).
-
ignoreParentModuleLayers
public ClassGraph ignoreParentModuleLayers()
Ignore parent module layers (i.e. only scan module layers that are not the parent of another module layer).- Returns:
- this (for method chaining).
-
whitelistPackages
public ClassGraph whitelistPackages(String... packageNames)
Scan one or more specific packages and their sub-packages.N.B. Automatically calls
enableClassInfo()-- callwhitelistPaths(String...)instead if you only need to scan resources.- Parameters:
packageNames- The fully-qualified names of packages to scan (using '.' as a separator). May include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
whitelistPaths
public ClassGraph whitelistPaths(String... paths)
Scan one or more specific paths, and their sub-directories or nested paths.- Parameters:
paths- The paths to scan, relative to the package root of the classpath element (with '/' as a separator). May include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
whitelistPackagesNonRecursive
public ClassGraph whitelistPackagesNonRecursive(String... packageNames)
Scan one or more specific packages, without recursively scanning sub-packages unless they are themselves whitelisted.N.B. Automatically calls
enableClassInfo()-- callwhitelistPathsNonRecursive(String...)instead if you only need to scan resources.This may be particularly useful for scanning the package root ("") without recursively scanning everything in the jar, dir or module.
- Parameters:
packageNames- The fully-qualified names of packages to scan (with '.' as a separator). May not include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
whitelistPathsNonRecursive
public ClassGraph whitelistPathsNonRecursive(String... paths)
Scan one or more specific paths, without recursively scanning sub-directories or nested paths unless they are themselves whitelisted.This may be particularly useful for scanning the package root ("") without recursively scanning everything in the jar, dir or module.
- Parameters:
paths- The paths to scan, relative to the package root of the classpath element (with '/' as a separator). May not include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
blacklistPackages
public ClassGraph blacklistPackages(String... packageNames)
Prevent the scanning of one or more specific packages and their sub-packages.N.B. Automatically calls
enableClassInfo()-- callblacklistPaths(String...)instead if you only need to scan resources.- Parameters:
packageNames- The fully-qualified names of packages to blacklist (with '.' as a separator). May include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
blacklistPaths
public ClassGraph blacklistPaths(String... paths)
Prevent the scanning of one or more specific paths and their sub-directories / nested paths.- Parameters:
paths- The paths to blacklist (with '/' as a separator). May include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
whitelistClasses
public ClassGraph whitelistClasses(String... classNames)
Scan one or more specific classes, without scanning other classes in the same package unless the package is itself whitelisted.N.B. Automatically calls
enableClassInfo().- Parameters:
classNames- The fully-qualified names of classes to scan (using '.' as a separator). May not include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
blacklistClasses
public ClassGraph blacklistClasses(String... classNames)
Specifically blacklist one or more specific classes, preventing them from being scanned even if they are in a whitelisted package.N.B. Automatically calls
enableClassInfo().- Parameters:
classNames- The fully-qualified names of classes to blacklist (using '.' as a separator). May not include a glob wildcard ('*').- Returns:
- this (for method chaining).
-
whitelistJars
public ClassGraph whitelistJars(String... jarLeafNames)
Whitelist one or more jars. This will cause only the whitelisted jars to be scanned.- Parameters:
jarLeafNames- The leafnames of the jars that should be scanned (e.g."mylib.jar"). May contain a wildcard glob ("mylib-*.jar").- Returns:
- this (for method chaining).
-
blacklistJars
public ClassGraph blacklistJars(String... jarLeafNames)
Blacklist one or more jars, preventing them from being scanned.- Parameters:
jarLeafNames- The leafnames of the jars that should be scanned (e.g."badlib.jar"). May contain a wildcard glob ("badlib-*.jar").- Returns:
- this (for method chaining).
-
whitelistLibOrExtJars
public ClassGraph whitelistLibOrExtJars(String... jarLeafNames)
Whitelist one or more jars in a JRE/JDK "lib/" or "ext/" directory (these directories are not scanned unlessenableSystemPackages()is called, by association with the JRE/JDK).- Parameters:
jarLeafNames- The leafnames of the lib/ext jar(s) that should be scanned (e.g."mylib.jar"). May contain a wildcard glob ('*'). Note that if you call this method with no parameters, all JRE/JDK "lib/" or "ext/" jars will be whitelisted.- Returns:
- this (for method chaining).
-
blacklistLibOrExtJars
public ClassGraph blacklistLibOrExtJars(String... jarLeafNames)
Blacklist one or more jars in a JRE/JDK "lib/" or "ext/" directory, preventing them from being scanned.- Parameters:
jarLeafNames- The leafnames of the lib/ext jar(s) that should not be scanned (e.g."jre/lib/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.- Returns:
- this (for method chaining).
-
whitelistModules
public ClassGraph whitelistModules(String... moduleNames)
Whitelist one or more modules to scan.- Parameters:
moduleNames- The names of the modules that should be scanned. May contain a wildcard glob ('*').- Returns:
- this (for method chaining).
-
blacklistModules
public ClassGraph blacklistModules(String... moduleNames)
Blacklist one or more modules, preventing them from being scanned.- Parameters:
moduleNames- The names of the modules that should not be scanned. May contain a wildcard glob ('*').- Returns:
- this (for method chaining).
-
whitelistClasspathElementsContainingResourcePath
public ClassGraph whitelistClasspathElementsContainingResourcePath(String... resourcePaths)
Whitelist classpath elements based on resource paths. Only classpath elements that contain resources with paths matching the whitelist will be scanned.- Parameters:
resourcePaths- The resource paths, any of which must be present in a classpath element for the classpath element to be scanned. May contain a wildcard glob ('*').- Returns:
- this (for method chaining).
-
blacklistClasspathElementsContainingResourcePath
public ClassGraph blacklistClasspathElementsContainingResourcePath(String... resourcePaths)
Blacklist classpath elements based on resource paths. Classpath elements that contain resources with paths matching the blacklist will not be scanned.- Parameters:
resourcePaths- The resource paths which cause a classpath not to be scanned if any are present in a classpath element for the classpath element. May contain a wildcard glob ('*').- Returns:
- this (for method chaining).
-
enableRemoteJarScanning
public ClassGraph enableRemoteJarScanning()
Enable classpath elements to be fetched from remote http/https URLs to local temporary files and scanned. This option is disabled by default, as this may present a security vulnerability, since classes from downloaded jars can be subsequently loaded usingClassInfo.loadClass(java.lang.Class<T>, boolean).- Returns:
- this (for method chaining).
-
enableSystemJarsAndModules
public ClassGraph enableSystemJarsAndModules()
Enables the scanning of system packages ("java.*","javax.*","javafx.*","jdk.*","oracle.*","sun.*") -- these are not scanned by default for speed.N.B. Automatically calls
enableClassInfo().- Returns:
- this (for method chaining).
-
enableSystemPackages
@Deprecated public ClassGraph enableSystemPackages()
Deprecated.UseenableSystemJarsAndModules()instead.UseenableSystemJarsAndModules()instead.- Returns:
- this (for method chaining).
-
enableRealtimeLogging
public ClassGraph enableRealtimeLogging()
Enables logging by callingverbose(), and then sets the logger to "realtime logging mode", where log entries are written out immediately to stderr, rather than only after the scan has completed. Can help to identify problems where scanning is stuck in a loop, or where one scanning step is taking much longer than it should, etc.- Returns:
- this (for method chaining).
-
scanAsync
public void scanAsync(ExecutorService executorService, int numParallelTasks, ClassGraph.ScanResultProcessor scanResultProcessor, ClassGraph.FailureHandler failureHandler)
Asynchronously scans the classpath, calling aClassGraph.ScanResultProcessorcallback on success or aClassGraph.FailureHandlercallback on failure.- Parameters:
executorService- A customExecutorServiceto 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- AClassGraph.ScanResultProcessorcallback to run on successful scan.failureHandler- AClassGraph.FailureHandlercallback to run on failed scan. This is passed anyThrowablethrown during the scan.
-
scanAsync
public Future<ScanResult> scanAsync(ExecutorService executorService, int numParallelTasks)
Asynchronously scans the classpath for matching files, returning aFuture<ScanResult>.- Parameters:
executorService- A customExecutorServiceto 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.- Returns:
- a
Future<ScanResult>, that when resolved using get() yields a newScanResultobject representing the result of the scan.
-
scan
public ScanResult scan(ExecutorService executorService, int numParallelTasks)
Scans the classpath using the requestedExecutorServiceand the requested degree of parallelism, blocking until the scan is complete.- Parameters:
executorService- A customExecutorServiceto use for scheduling worker tasks. ThisExecutorServiceshould start tasks in FIFO order to avoid a deadlock during scan, i.e. be sure to construct theExecutorServicewith aLinkedBlockingQueueas its task queue. (This is the default forExecutors.newFixedThreadPool(int).)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.- Returns:
- a
ScanResultobject representing the result of the scan. - Throws:
RuntimeException- if any of the worker threads throws an uncaught exception, or the scan was interrupted.
-
scan
public ScanResult scan(int numThreads)
Scans the classpath with the requested number of threads, blocking until the scan is complete.- Parameters:
numThreads- The number of worker threads to start up.- Returns:
- a
ScanResultobject representing the result of the scan. - Throws:
RuntimeException- if any of the worker threads throws an uncaught exception, or the scan was interrupted.
-
scan
public ScanResult scan()
Scans the classpath, blocking until the scan is complete.- Returns:
- a
ScanResultobject representing the result of the scan. - Throws:
RuntimeException- if any of the worker threads throws an uncaught exception, or the scan was interrupted.
-
getClasspathFiles
public List<File> getClasspathFiles()
Returns the list of all unique File objects representing directories or zip/jarfiles on the classpath, in classloader resolution order. Classpath elements that do not exist as a file or directory are not included in the returned list.- Returns:
- a
List<File>consisting of the unique directories and jarfiles on the classpath, in classpath resolution order.
-
getClasspath
public 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. Classpath elements that do not exist as a file or directory are not included in the returned list.- Returns:
- a classpath path string consisting of the unique directories and jarfiles on the classpath, in classpath resolution order.
-
getClasspathURLs
public List<URL> getClasspathURLs()
Returns the list of all unique URL objects representing directories, zip/jarfiles or modules on the classpath, in classloader resolution order. Classpath elements representing jarfiles or directories that do not exist are not included in the returned list.- Returns:
- a classpath path string consisting of the unique directories and jarfiles on the classpath, in classpath resolution order.
-
-