Package nonapi.io.github.classgraph
Class ScanSpec
- java.lang.Object
-
- nonapi.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classScanSpec.ScanSpecPathMatchWhether a path is a descendant of a blacklisted path, or an ancestor or descendant of a whitelisted path.
-
Field Summary
Fields Modifier and Type Field Description List<ClassLoader>addedClassLoadersIf non-null, specifies manually-added classloaders that should be searched after the context classloader(s).List<Object>addedModuleLayersIf non-null, specifies manually-added ModuleLayers that should be searched after the visible ModuleLayers.WhiteBlackList.WhiteBlackListWholeStringclassfilePathWhiteBlackListClassfile white/blacklist (path to classfiles, with separator '/', ending in ".class").WhiteBlackList.WhiteBlackListWholeStringclassPackagePathWhiteBlackListPath to white/blacklisted classes (with separator '/').WhiteBlackList.WhiteBlackListWholeStringclassPackageWhiteBlackListPackage containing white/blacklisted classes (with separator '.').List<ClassGraph.ClasspathElementFilter>classpathElementFiltersIf non-null, a list of filter operations to apply to classpath elements.WhiteBlackList.WhiteBlackListWholeStringclasspathElementResourcePathWhiteBlackListClasspath element resource path white/blacklist.WhiteBlackList.WhiteBlackListWholeStringclassWhiteBlackListClass white/blacklist (fully-qualified class names, with separator '.').booleandisableRuntimeInvisibleAnnotationsIf true, don't scan runtime-invisible annotations (only scan annotations with RetentionPolicy.RUNTIME).booleanenableAnnotationInfoIf true, enables the saving of annotation info (for class, field, method or method parameter annotations) during the scan.booleanenableClassInfoIf true, scan classfile bytecodes, producingClassInfoobjects.booleanenableExternalClassesIf 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.booleanenableFieldInfoIf true, enables the saving of field info during the scan.booleanenableInterClassDependenciesIf true, enables the determination of inter-class dependencies.booleanenableMethodInfoIf true, enables the saving of method info during the scan.booleanenableRemoteJarScanningIf true, enable http(s) classpath elements to be fetched to local temporary files and scanned.booleanenableStaticFinalFieldConstantInitializerValuesEnable the storing of constant initializer values for static final fields in ClassInfo objects.booleanenableSystemJarsAndModulesIf true, system jarfiles (rt.jar) and system packages and modules (java.*, jre.*, etc.) should be scanned .booleanextendScanningUpwardsToExternalClassesIf true, when classes have superclasses, implemented interfaces or annotations that are external classes, those classes are also scanned.booleanignoreClassVisibilityIf true, ignore class visibility.booleanignoreFieldVisibilityIf true, ignore field visibility.booleanignoreMethodVisibilityIf true, ignore method visibility.booleanignoreParentClassLoadersIf true, do not fetch paths from parent classloaders.booleanignoreParentModuleLayersIf true, do not scan module layers that are the parent of other module layers.booleaninitializeLoadedClassesIf true, classes loaded with Class.forName() are initialized before passing class references to MatchProcessors.WhiteBlackList.WhiteBlackListLeafnamejarWhiteBlackListJar white/blacklist (leafname only, ending in ".jar").WhiteBlackList.WhiteBlackListLeafnamelibOrExtJarWhiteBlackListlib/ext jar white/blacklist (leafname only, ending in ".jar").WhiteBlackList.WhiteBlackListWholeStringmoduleWhiteBlackListModule white/blacklist (with separator '.').List<ClassLoader>overrideClassLoadersIf non-null, this list of ClassLoaders will be searched instead of the visible/context ClassLoader(s).StringoverrideClasspathIf non-null, specifies a classpath to override the default one.List<Object>overrideModuleLayersIf non-null, this list of ModuleLayers will be searched instead of the visible ModuleLayers.WhiteBlackList.WhiteBlackListPrefixpackagePrefixWhiteBlackListPackage prefix white/blacklist, for recursive scanning (with separator '.', ending in '.').WhiteBlackList.WhiteBlackListWholeStringpackageWhiteBlackListPackage white/blacklist (with separator '.').WhiteBlackList.WhiteBlackListPrefixpathPrefixWhiteBlackListPath prefix white/blacklist, for recursive scanning (with separator '/', ending in '/').WhiteBlackList.WhiteBlackListWholeStringpathWhiteBlackListPath white/blacklist (with separator '/').booleanperformScanIf true, performing a scan.booleanremoveTemporaryFilesAfterScanIf true, nested jarfiles (jarfiles within jarfiles) that are extracted during scanning are removed from their temporary directory (e.g.booleanscanDirsIf true, scan directories.booleanscanJarsIf true, scan jarfiles.booleanscanModulesIf true, scan modules.booleanscanNestedJarsIf true, scan nested jarfiles (jarfiles within jarfiles).
-
Constructor Summary
Constructors Constructor Description ScanSpec()Constructor for deserialization.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClassLoader(ClassLoader classLoader)Add a ClassLoader to the list of ClassLoaders to scan.voidaddModuleLayer(Object moduleLayer)Add a ModuleLayer to the list of ModuleLayers to scan.booleanclassfileIsSpecificallyWhitelisted(String relativePath)Returns true if the given relative path (for a classfile name, including ".class") matches a specifically-whitelisted (and non-blacklisted) classfile's relative path.booleanclassOrPackageIsBlacklisted(String className)Returns true if the class is specifically blacklisted, or is within a blacklisted package.booleanclassOrPackageIsSpecificallyWhitelisted(String className)Returns true if the class is specifically whitelisted, or is within a whitelisted package.ScanSpec.ScanSpecPathMatchdirWhitelistMatchStatus(String relativePath)Returns true if the given directory path is a descendant of a blacklisted path, or an ancestor or descendant of a whitelisted path.voidfilterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter)Add a classpath element filter.voidlog(LogNode log)voidoverrideClassLoaders(ClassLoader... overrideClassLoaders)Completely override the list of ClassLoaders to scan.voidoverrideClasspath(String overrideClasspath)Override the automatically-detected classpath with a custom search path.voidoverrideModuleLayers(Object... overrideModuleLayers)Completely override (and ignore) the visible ModuleLayers, and instead scan the requested ModuleLayers.voidsortPrefixes()Sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).
-
-
-
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").
-
classpathElementResourcePathWhiteBlackList
public WhiteBlackList.WhiteBlackListWholeString classpathElementResourcePathWhiteBlackList
Classpath element resource path white/blacklist.
-
libOrExtJarWhiteBlackList
public WhiteBlackList.WhiteBlackListLeafname libOrExtJarWhiteBlackList
lib/ext jar white/blacklist (leafname only, ending in ".jar").
-
performScan
public boolean performScan
If true, performing a scan. If false, only fetching the classpath.
-
scanJars
public boolean scanJars
If true, scan jarfiles.
-
scanNestedJars
public boolean scanNestedJars
If true, scan nested jarfiles (jarfiles within 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, producingClassInfoobjects.
-
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.
-
enableInterClassDependencies
public boolean enableInterClassDependencies
If true, enables the determination of inter-class dependencies.
-
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.
-
enableSystemJarsAndModules
public boolean enableSystemJarsAndModules
If true, system jarfiles (rt.jar) and system packages and modules (java.*, jre.*, etc.) should be scanned .
-
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).
-
extendScanningUpwardsToExternalClasses
public boolean extendScanningUpwardsToExternalClasses
If true, when classes have superclasses, implemented interfaces or annotations that are external classes, those classes are also scanned. (Even though this slows down scanning a bit, there is no API for disabling this currently, since disabling it can lead to problems -- see #261.)
-
enableRemoteJarScanning
public boolean enableRemoteJarScanning
If true, enable http(s) classpath elements to be fetched to local temporary files and scanned. 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).
-
addedClassLoaders
public transient List<ClassLoader> addedClassLoaders
If non-null, specifies manually-added classloaders that should be searched after the context classloader(s).
-
overrideClassLoaders
public transient List<ClassLoader> overrideClassLoaders
If non-null, this list of ClassLoaders will be searched instead of the visible/context ClassLoader(s). In particular, this causes ClassGraph to ignore the java.class.path system property.
-
addedModuleLayers
public transient List<Object> addedModuleLayers
If non-null, specifies manually-added ModuleLayers that should be searched after the visible ModuleLayers.
-
overrideModuleLayers
public transient List<Object> overrideModuleLayers
If non-null, this list of ModuleLayers will be searched instead of the visible ModuleLayers.
-
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.
-
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 theScanResultfinalizer, or on JVM exit.
-
ignoreParentClassLoaders
public transient boolean ignoreParentClassLoaders
If true, do not fetch paths from parent classloaders.
-
ignoreParentModuleLayers
public transient boolean ignoreParentModuleLayers
If true, do not scan module layers that are the parent of other module layers.
-
-
Method Detail
-
sortPrefixes
public void sortPrefixes()
Sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).
-
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.
-
addModuleLayer
public void 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.)
-
overrideModuleLayers
public void 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[].)
-
dirWhitelistMatchStatus
public ScanSpec.ScanSpecPathMatch dirWhitelistMatchStatus(String relativePath)
Returns true if the given directory path is a descendant of a blacklisted path, or an ancestor or descendant of a whitelisted path. The path should end in "/".
-
classfileIsSpecificallyWhitelisted
public boolean classfileIsSpecificallyWhitelisted(String relativePath)
Returns true if the given relative path (for a classfile name, including ".class") matches a specifically-whitelisted (and non-blacklisted) classfile's relative path.
-
classOrPackageIsSpecificallyWhitelisted
public boolean classOrPackageIsSpecificallyWhitelisted(String className)
Returns true if the class is specifically whitelisted, or is within a whitelisted package.
-
classOrPackageIsBlacklisted
public boolean classOrPackageIsBlacklisted(String className)
Returns true if the class is specifically blacklisted, or is within a blacklisted package.
-
-