Package io.github.classgraph
Class ScanSpec
- java.lang.Object
-
- io.github.classgraph.ScanSpec
-
public class ScanSpec extends Object
Parses the scanning specification that was passed to the ClassGraph constructor, and finds all ClassLoaders. Also defines core MatchProcessor matching logic.
-
-
Field Summary
Fields Modifier and Type Field Description List<ClassLoader>
addedClassLoaders
If non-null, specified manually-added classloaders that should be searched after the context classloader(s).boolean
blacklistSystemJarsOrModules
True if JRE system jarfiles (rt.jar etc.) should not be scanned.WhiteBlackList.WhiteBlackListWholeString
classfilePathWhiteBlackList
Classfile white/blacklist (path to classfiles, with separator '/', ending in ".class").WhiteBlackList.WhiteBlackListWholeString
classPackagePathWhiteBlackList
Path to white/blacklisted classes (with separator '/').WhiteBlackList.WhiteBlackListWholeString
classPackageWhiteBlackList
Package containing white/blacklisted classes (with separator '.').List<ClassGraph.ClasspathElementFilter>
classpathElementFilters
If non-null, a list of filter operations to apply to classpath elements.WhiteBlackList.WhiteBlackListWholeString
classWhiteBlackList
Class white/blacklist (fully-qualified class names, with separator '.').boolean
createClassLoaderForMatchingClasses
If this method is called, a newURLClassLoader
is created for all classes found on the classpath that match whitelist criteria.boolean
disableRuntimeInvisibleAnnotations
If true, don't scan runtime-invisible annotations (only scan annotations with RetentionPolicy.RUNTIME).boolean
enableAnnotationInfo
If true, enables the saving of annotation info (for class, field, method or method parameter annotations) during the scan.boolean
enableClassInfo
If true, scan classfile bytecodes, producingClassInfo
objects.boolean
enableExternalClasses
If true, allow external classes (classes outside of whitelisted packages) to be returned in the ScanResult, if they are directly referred to by a whitelisted class, as a superclass, implemented interface or annotation.boolean
enableFieldInfo
If true, enables the saving of field info during the scan.boolean
enableMethodInfo
If true, enables the saving of method info during the scan.boolean
enableStaticFinalFieldConstantInitializerValues
Enable the storing of constant initializer values for static final fields in ClassInfo objects.ArrayList<ClassLoaderHandlerRegistry.ClassLoaderHandlerRegistryEntry>
extraClassLoaderHandlers
Manually-registered ClassLoaderHandlers.boolean
ignoreClassVisibility
If true, ignore class visibility.boolean
ignoreFieldVisibility
If true, ignore field visibility.boolean
ignoreMethodVisibility
If true, ignore method visibility.boolean
ignoreParentClassLoaders
If true, do not fetch paths from parent classloaders.boolean
initializeLoadedClasses
If true, classes loaded with Class.forName() are initialized before passing class references to MatchProcessors.WhiteBlackList.WhiteBlackListLeafname
jarWhiteBlackList
Jar white/blacklist (leafname only, ending in ".jar").WhiteBlackList.WhiteBlackListLeafname
libOrExtJarWhiteBlackList
lib/ext jar white/blacklist (leafname only, ending in ".jar").WhiteBlackList.WhiteBlackListWholeString
moduleWhiteBlackList
Module white/blacklist (with separator '.').List<ClassLoader>
overrideClassLoaders
If non-null, all ClassLoaders have been overriden.String
overrideClasspath
If non-null, specifies a classpath to override the default one.WhiteBlackList.WhiteBlackListPrefix
packagePrefixWhiteBlackList
Package prefix white/blacklist, for recursive scanning (with separator '.', ending in '.').WhiteBlackList.WhiteBlackListWholeString
packageWhiteBlackList
Package white/blacklist (with separator '.').WhiteBlackList.WhiteBlackListPrefix
pathPrefixWhiteBlackList
Path prefix white/blacklist, for recursive scanning (with separator '/', ending in '/').WhiteBlackList.WhiteBlackListWholeString
pathWhiteBlackList
Path white/blacklist (with separator '/').boolean
removeTemporaryFilesAfterScan
If true, nested jarfiles (jarfiles within jarfiles) that are extracted during scanning are removed from their temporary directory (e.g.boolean
scanDirs
If true, scan directories.boolean
scanJars
If true, scan jarfiles.boolean
scanModules
If true, scan modules.boolean
stripSFXHeader
If true, manually strip the self extracting executable header from zipfiles (i.e.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addClassLoader(ClassLoader classLoader)
Add a ClassLoader to the list of ClassLoaders to scan.void
filterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter)
Add a classpath element filter.void
overrideClassLoaders(ClassLoader... overrideClassLoaders)
Completely override the list of ClassLoaders to scan.void
overrideClasspath(String overrideClasspath)
Override the automatically-detected classpath with a custom search path.void
registerClassLoaderHandler(Class<? extends ClassLoaderHandler> classLoaderHandler)
Register an extra ClassLoaderHandler.
-
-
-
Field Detail
-
packageWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString packageWhiteBlackList
Package white/blacklist (with separator '.').
-
packagePrefixWhiteBlackList
public WhiteBlackList.WhiteBlackListPrefix packagePrefixWhiteBlackList
Package prefix white/blacklist, for recursive scanning (with separator '.', ending in '.').
-
pathWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString pathWhiteBlackList
Path white/blacklist (with separator '/').
-
pathPrefixWhiteBlackList
public WhiteBlackList.WhiteBlackListPrefix pathPrefixWhiteBlackList
Path prefix white/blacklist, for recursive scanning (with separator '/', ending in '/').
-
classWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString classWhiteBlackList
Class white/blacklist (fully-qualified class names, with separator '.').
-
classfilePathWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString classfilePathWhiteBlackList
Classfile white/blacklist (path to classfiles, with separator '/', ending in ".class").
-
classPackageWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString classPackageWhiteBlackList
Package containing white/blacklisted classes (with separator '.').
-
classPackagePathWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString classPackagePathWhiteBlackList
Path to white/blacklisted classes (with separator '/').
-
moduleWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString moduleWhiteBlackList
Module white/blacklist (with separator '.').
-
jarWhiteBlackList
public WhiteBlackList.WhiteBlackListLeafname jarWhiteBlackList
Jar white/blacklist (leafname only, ending in ".jar").
-
libOrExtJarWhiteBlackList
public WhiteBlackList.WhiteBlackListLeafname libOrExtJarWhiteBlackList
lib/ext jar white/blacklist (leafname only, ending in ".jar").
-
scanJars
public boolean scanJars
If true, scan jarfiles.
-
scanDirs
public boolean scanDirs
If true, scan directories.
-
scanModules
public boolean scanModules
If true, scan modules.
-
enableClassInfo
public boolean enableClassInfo
If true, scan classfile bytecodes, producingClassInfo
objects.
-
enableFieldInfo
public boolean enableFieldInfo
If true, enables the saving of field info during the scan. This information can be obtained usingClassInfo.getFieldInfo()
. By default, field info is not scanned, for efficiency.
-
enableMethodInfo
public boolean enableMethodInfo
If true, enables the saving of method info during the scan. This information can be obtained usingClassInfo.getMethodInfo()
. By default, method info is not scanned, for efficiency.
-
enableAnnotationInfo
public boolean enableAnnotationInfo
If true, enables the saving of annotation info (for class, field, method or method parameter annotations) during the scan. This information can be obtained usingClassInfo.getAnnotationInfo()
etc. By default, annotation info is not scanned, for efficiency.
-
enableStaticFinalFieldConstantInitializerValues
public boolean enableStaticFinalFieldConstantInitializerValues
Enable the storing of constant initializer values for static final fields in ClassInfo objects.
-
enableExternalClasses
public boolean enableExternalClasses
If true, allow external classes (classes outside of whitelisted packages) to be returned in the ScanResult, if they are directly referred to by a whitelisted class, as a superclass, implemented interface or annotation. Disabled by default.
-
blacklistSystemJarsOrModules
public boolean blacklistSystemJarsOrModules
True if JRE system jarfiles (rt.jar etc.) should not be scanned. By default, these are not scanned. This can be overridden by including "!!" in the scan spec. Disabling this blacklisting will increase the time or memory required to scan the classpath.
-
ignoreClassVisibility
public boolean ignoreClassVisibility
If true, ignore class visibility. If false, classes must be public to be scanned.
-
ignoreFieldVisibility
public boolean ignoreFieldVisibility
If true, ignore field visibility. If false, fields must be public to be scanned.
-
ignoreMethodVisibility
public boolean ignoreMethodVisibility
If true, ignore method visibility. If false, methods must be public to be scanned.
-
disableRuntimeInvisibleAnnotations
public boolean disableRuntimeInvisibleAnnotations
If true, don't scan runtime-invisible annotations (only scan annotations with RetentionPolicy.RUNTIME).
-
addedClassLoaders
public transient List<ClassLoader> addedClassLoaders
If non-null, specified manually-added classloaders that should be searched after the context classloader(s).
-
overrideClassLoaders
public transient List<ClassLoader> overrideClassLoaders
If non-null, all ClassLoaders have been overriden. In particular, this causes ClassGraph to ignore the java.class.path system property.
-
overrideClasspath
public String overrideClasspath
If non-null, specifies a classpath to override the default one.
-
classpathElementFilters
public transient List<ClassGraph.ClasspathElementFilter> classpathElementFilters
If non-null, a list of filter operations to apply to classpath elements.
-
extraClassLoaderHandlers
public final transient ArrayList<ClassLoaderHandlerRegistry.ClassLoaderHandlerRegistryEntry> extraClassLoaderHandlers
Manually-registered ClassLoaderHandlers.
-
initializeLoadedClasses
public transient boolean initializeLoadedClasses
If true, classes loaded with Class.forName() are initialized before passing class references to MatchProcessors. If false (the default), matched classes are loaded but not initialized before passing class references to MatchProcessors (meaning classes are instead initialized lazily on first usage of the class).
-
removeTemporaryFilesAfterScan
public transient boolean removeTemporaryFilesAfterScan
If true, nested jarfiles (jarfiles within jarfiles) that are extracted during scanning are removed from their temporary directory (e.g. /tmp/ClassGraph-8JX2u4w) after the scan has completed. If false, temporary files are removed by theScanResult
finalizer, or on JVM exit.
-
ignoreParentClassLoaders
public transient boolean ignoreParentClassLoaders
If true, do not fetch paths from parent classloaders.
-
stripSFXHeader
public transient boolean stripSFXHeader
If true, manually strip the self extracting executable header from zipfiles (i.e. anything before the magic marker "PK", e.g. a Bash script added by Spring-Boot). Slightly increases scanning time, since zipfiles have to be opened twice (once as a byte stream, to check if there is an SFX header, then once as a ZipFile, for decompression). 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 (Oracle JVM on Linux does this automatically).
-
createClassLoaderForMatchingClasses
public transient boolean createClassLoaderForMatchingClasses
If this method is called, a newURLClassLoader
is created for all classes found on the classpath that match whitelist criteria. This may be needed if you get a ClassNotFoundException, UnsatisfiedLinkError, NoClassDefFoundError, etc., due to trying to load classes that depend upon each other but that are loaded by different ClassLoaders in the classpath.
-
-
Method Detail
-
registerClassLoaderHandler
public void registerClassLoaderHandler(Class<? extends ClassLoaderHandler> classLoaderHandler)
Register an extra ClassLoaderHandler.- Parameters:
classLoaderHandler
- The class of the ClassLoaderHandler that can handle those ClassLoaders.
-
overrideClasspath
public void overrideClasspath(String overrideClasspath)
Override the automatically-detected classpath with a custom search path. You can specify multiple elements, separated by File.pathSeparatorChar. If this method is called, nothing but the provided classpath will be scanned, i.e. causes ClassLoaders to be ignored, as well as the java.class.path system property.- Parameters:
overrideClasspath
- The classpath to scan.
-
filterClasspathElements
public void 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 classpath element filter to apply to all discovered classpath elements, to decide which should be scanned.
-
addClassLoader
public void addClassLoader(ClassLoader classLoader)
Add a ClassLoader to the list of ClassLoaders to scan. (This only works if overrideClasspath() is not called.)- Parameters:
classLoader
- The classloader to add.
-
overrideClassLoaders
public void overrideClassLoaders(ClassLoader... overrideClassLoaders)
Completely override the list of ClassLoaders to scan. (This only works if overrideClasspath() is not called.) Causes the java.class.path system property to be ignored.- Parameters:
overrideClassLoaders
- The classloaders to override the default context classloaders with.
-
-