Class ScanSpec
- java.lang.Object
-
- nonapi.io.github.classgraph.scanspec.ScanSpec
-
public class ScanSpec extends java.lang.ObjectThe scanning specification.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classScanSpec.ScanSpecPathMatchWhether a path is a descendant of a rejected path, or an ancestor or descendant of an accepted path.
-
Field Summary
Fields Modifier and Type Field Description java.util.List<java.lang.ClassLoader>addedClassLoadersIf non-null, specifies manually-added classloaders that should be searched after the context classloader(s).java.util.List<java.lang.Object>addedModuleLayersIf non-null, specifies manually-added ModuleLayers that should be searched after the visible ModuleLayers.java.util.Set<java.lang.String>allowedURLSchemesURL schemes that are allowed in classpath elements (not counting the optional "jar:" prefix and/or "file:", which are automatically allowed).AcceptReject.AcceptRejectWholeStringclassAcceptRejectClass accept/reject criteria (fully-qualified class names, with separator '.').AcceptReject.AcceptRejectWholeStringclassfilePathAcceptRejectClassfile accept/reject criteria (path to classfiles, with separator '/', ending in ".class").AcceptReject.AcceptRejectWholeStringclassPackageAcceptRejectPackage containing accept/reject criteriaed classes (with separator '.').AcceptReject.AcceptRejectWholeStringclassPackagePathAcceptRejectPath to accept/reject criteriaed classes (with separator '/').java.util.List<java.lang.Object>classpathElementFiltersIf non-null, a list of filter operations to apply to classpath elements.AcceptReject.AcceptRejectWholeStringclasspathElementResourcePathAcceptRejectClasspath element resource path accept/reject criteria.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 accepted packages) to be returned in the ScanResult, if they are directly referred to by an accepted 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.booleanenableMemoryMappingIf true, use aMappedByteBufferrather than theFileChannelAPI to access file content.booleanenableMethodInfoIf true, enables the saving of method info during the scan.booleanenableMultiReleaseVersionsIf true, all multi-release versions of a resource are found.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.booleaninitializeLoadedClassesWhether to initialize classes when loading them.AcceptReject.AcceptRejectLeafnamejarAcceptRejectJar accept/reject criteria (leafname only, ending in ".jar").AcceptReject.AcceptRejectLeafnamelibOrExtJarAcceptRejectlib/ext jar accept/reject criteria (leafname only, ending in ".jar").intmaxBufferedJarRAMSizeThe maximum size of an inner (nested) jar that has been deflated (i.e.AcceptReject.AcceptRejectWholeStringmoduleAcceptRejectModule accept/reject criteria (with separator '.').ModulePathInfomodulePathInfoCommandline module path parameters.java.util.List<java.lang.ClassLoader>overrideClassLoadersIf non-null, this list of ClassLoaders will be searched instead of the visible/context ClassLoader(s).java.util.List<java.lang.Object>overrideClasspathIf non-null, specifies a list of classpath elements (String,URLorURIto use to override the default classpath.java.util.List<java.lang.Object>overrideModuleLayersIf non-null, this list of ModuleLayers will be searched instead of the visible ModuleLayers.AcceptReject.AcceptRejectWholeStringpackageAcceptRejectPackage accept/reject criteria (with separator '.').AcceptReject.AcceptRejectPrefixpackagePrefixAcceptRejectPackage prefix accept/reject criteria, for recursive scanning (with separator '.', ending in '.').AcceptReject.AcceptRejectWholeStringpathAcceptRejectPath accept/reject criteria (with separator '/').AcceptReject.AcceptRejectPrefixpathPrefixAcceptRejectPath prefix accept/reject criteria, for recursive scanning (with separator '/', ending in '/').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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClassLoader(java.lang.ClassLoader classLoader)Add a ClassLoader to the list of ClassLoaders to scan.voidaddClasspathOverride(java.lang.Object overrideClasspathElement)Override the automatically-detected classpath with a custom path.voidaddModuleLayer(java.lang.Object moduleLayer)Add a ModuleLayer to the list of ModuleLayers to scan.booleanclassfileIsSpecificallyAccepted(java.lang.String relativePath)Returns true if the given relative path (for a classfile name, including ".class") matches a specifically-accepted (and non-rejected) classfile's relative path.booleanclassOrPackageIsRejected(java.lang.String className)Returns true if the class is specifically rejected, or is within a rejected package.ScanSpec.ScanSpecPathMatchdirAcceptMatchStatus(java.lang.String relativePath)Returns true if the given directory path is a descendant of a rejected path, or an ancestor or descendant of an accepted path.voidenableURLScheme(java.lang.String scheme)Allow a specified URL scheme in classpath elements.voidfilterClasspathElements(java.lang.Object filterLambda)Add a classpath element filter.private static booleanisModuleLayer(java.lang.Object moduleLayer)Return true if the argument is a ModuleLayer or a subclass of ModuleLayer.voidlog(LogNode log)Write to log.voidoverrideClassLoaders(java.lang.ClassLoader... overrideClassLoaders)Completely override the list of ClassLoaders to scan.voidoverrideModuleLayers(java.lang.Object... overrideModuleLayers)Completely override (and ignore) the visible ModuleLayers, and instead scan the requested ModuleLayers.voidsortPrefixes()Sort prefixes to ensure correct accept/reject evaluation (see Issue #167).
-
-
-
Field Detail
-
packageAcceptReject
public AcceptReject.AcceptRejectWholeString packageAcceptReject
Package accept/reject criteria (with separator '.').
-
packagePrefixAcceptReject
public AcceptReject.AcceptRejectPrefix packagePrefixAcceptReject
Package prefix accept/reject criteria, for recursive scanning (with separator '.', ending in '.').
-
pathAcceptReject
public AcceptReject.AcceptRejectWholeString pathAcceptReject
Path accept/reject criteria (with separator '/').
-
pathPrefixAcceptReject
public AcceptReject.AcceptRejectPrefix pathPrefixAcceptReject
Path prefix accept/reject criteria, for recursive scanning (with separator '/', ending in '/').
-
classAcceptReject
public AcceptReject.AcceptRejectWholeString classAcceptReject
Class accept/reject criteria (fully-qualified class names, with separator '.').
-
classfilePathAcceptReject
public AcceptReject.AcceptRejectWholeString classfilePathAcceptReject
Classfile accept/reject criteria (path to classfiles, with separator '/', ending in ".class").
-
classPackageAcceptReject
public AcceptReject.AcceptRejectWholeString classPackageAcceptReject
Package containing accept/reject criteriaed classes (with separator '.').
-
classPackagePathAcceptReject
public AcceptReject.AcceptRejectWholeString classPackagePathAcceptReject
Path to accept/reject criteriaed classes (with separator '/').
-
moduleAcceptReject
public AcceptReject.AcceptRejectWholeString moduleAcceptReject
Module accept/reject criteria (with separator '.').
-
jarAcceptReject
public AcceptReject.AcceptRejectLeafname jarAcceptReject
Jar accept/reject criteria (leafname only, ending in ".jar").
-
classpathElementResourcePathAcceptReject
public AcceptReject.AcceptRejectWholeString classpathElementResourcePathAcceptReject
Classpath element resource path accept/reject criteria.
-
libOrExtJarAcceptReject
public AcceptReject.AcceptRejectLeafname libOrExtJarAcceptReject
lib/ext jar accept/reject criteria (leafname only, ending in ".jar").
-
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 accepted packages) to be returned in the ScanResult, if they are directly referred to by an accepted 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.)
-
allowedURLSchemes
public java.util.Set<java.lang.String> allowedURLSchemes
URL schemes that are allowed in classpath elements (not counting the optional "jar:" prefix and/or "file:", which are automatically allowed).
-
addedClassLoaders
public transient java.util.List<java.lang.ClassLoader> addedClassLoaders
If non-null, specifies manually-added classloaders that should be searched after the context classloader(s).
-
overrideClassLoaders
public transient java.util.List<java.lang.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 java.util.List<java.lang.Object> addedModuleLayers
If non-null, specifies manually-added ModuleLayers that should be searched after the visible ModuleLayers.
-
overrideModuleLayers
public transient java.util.List<java.lang.Object> overrideModuleLayers
If non-null, this list of ModuleLayers will be searched instead of the visible ModuleLayers.
-
overrideClasspath
public java.util.List<java.lang.Object> overrideClasspath
If non-null, specifies a list of classpath elements (String,URLorURIto use to override the default classpath.
-
classpathElementFilters
public transient java.util.List<java.lang.Object> classpathElementFilters
If non-null, a list of filter operations to apply to classpath elements.
-
initializeLoadedClasses
public boolean initializeLoadedClasses
Whether to initialize classes when loading them.
-
removeTemporaryFilesAfterScan
public 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 boolean ignoreParentClassLoaders
If true, do not fetch paths from parent classloaders.
-
ignoreParentModuleLayers
public boolean ignoreParentModuleLayers
If true, do not scan module layers that are the parent of other module layers.
-
modulePathInfo
public ModulePathInfo modulePathInfo
Commandline module path parameters.
-
maxBufferedJarRAMSize
public int maxBufferedJarRAMSize
The maximum size of an inner (nested) jar that has been deflated (i.e. compressed, not stored) within an outer jar, before it has to be spilled to disk rather than stored in a RAM-backedByteBufferwhen it is deflated, in order for the inner jar's entries to be read. (Note that this situation of having to deflate a nested jar to RAM or disk in order to read it is rare, because normally adding a jarfile to another jarfile will store the inner jar, rather than deflate it, because deflating a jarfile does not usually produce any further compression gains. If an inner jar is stored, not deflated, then its zip entries can be read directly using ClassGraph's own zipfile central directory parser, which can use file slicing to extract entries directly from stored nested jars.)This is also the maximum size of a jar downloaded from an
http://orhttps://classpathURLto RAM. Once this many bytes have been read from theURL'sInputStream, then the RAM contents are spilled over to a temporary file on disk, and the rest of the content is downloaded to the temporary file. (This is also rare, because normally there are nohttp://orhttps://classpath entries.)Default: 64MB (i.e. writing to disk is avoided wherever possible). Setting a lower max RAM size value will decrease ClassGraph's memory usage if either of the above rare situations occurs.
-
enableMemoryMapping
public boolean enableMemoryMapping
If true, use aMappedByteBufferrather than theFileChannelAPI to access file content.
-
enableMultiReleaseVersions
public boolean enableMultiReleaseVersions
If true, all multi-release versions of a resource are found.
-
-
Method Detail
-
sortPrefixes
public void sortPrefixes()
Sort prefixes to ensure correct accept/reject evaluation (see Issue #167).
-
addClasspathOverride
public void addClasspathOverride(java.lang.Object overrideClasspathElement)
Override the automatically-detected classpath with a custom path. You can specify multiple elements in separate calls, and if this method is called even once, the default classpath will be overridden, such that 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:
overrideClasspathElement- The classpath element to add as an override to the default classpath.
-
filterClasspathElements
public void filterClasspathElements(java.lang.Object filterLambda)
Add a classpath element filter. The providedClassGraph.ClasspathElementFilterorClassGraph.ClasspathElementURLFiltershould return true if the path string orURLpassed to it is a path that should be scanned.- Parameters:
filterLambda- The classpath element filter to apply to all discovered classpath elements, to decide which should be scanned.
-
addClassLoader
public void addClassLoader(java.lang.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.
-
enableURLScheme
public void enableURLScheme(java.lang.String scheme)
Allow a specified URL scheme in classpath elements.- Parameters:
scheme- the scheme, e.g. "http".
-
overrideClassLoaders
public void overrideClassLoaders(java.lang.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.
-
isModuleLayer
private static boolean isModuleLayer(java.lang.Object moduleLayer)
Return true if the argument is a ModuleLayer or a subclass of ModuleLayer.- Parameters:
moduleLayer- the module layer- Returns:
- true if the argument is a ModuleLayer or a subclass of ModuleLayer.
-
addModuleLayer
public void addModuleLayer(java.lang.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(java.lang.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[].)
-
dirAcceptMatchStatus
public ScanSpec.ScanSpecPathMatch dirAcceptMatchStatus(java.lang.String relativePath)
Returns true if the given directory path is a descendant of a rejected path, or an ancestor or descendant of an accepted path. The path should end in "/".- Parameters:
relativePath- the relative path- Returns:
- the
ScanSpec.ScanSpecPathMatch
-
classfileIsSpecificallyAccepted
public boolean classfileIsSpecificallyAccepted(java.lang.String relativePath)
Returns true if the given relative path (for a classfile name, including ".class") matches a specifically-accepted (and non-rejected) classfile's relative path.- Parameters:
relativePath- the relative path- Returns:
- true if the given relative path (for a classfile name, including ".class") matches a specifically-accepted (and non-rejected) classfile's relative path.
-
classOrPackageIsRejected
public boolean classOrPackageIsRejected(java.lang.String className)
Returns true if the class is specifically rejected, or is within a rejected package.- Parameters:
className- the class name- Returns:
- true if the class is specifically rejected, or is within a rejected package.
-
-