Package io.github.classgraph
Class ClasspathElement
java.lang.Object
io.github.classgraph.ClasspathElement
- All Implemented Interfaces:
Comparable<ClasspathElement>
- Direct Known Subclasses:
ClasspathElementDir
,ClasspathElementModule
,ClasspathElementZip
A classpath element (a directory or jarfile on the classpath).
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe list of all classfiles found within this classpath element that were accepted and not rejected.Resources found within this classpath element that were accepted and not rejected.(package private) Collection
<ClasspathElement> The child classpath elements, keyed by the order of the child classpath element within the Class-Path entry of the manifest file the child classpath element was listed in (or the position of the file within the sorted entries of a lib directory).protected ClassLoader
The classloader that this classpath element was obtained from.(package private) int
The index of the classpath element within the classpath or module path.(package private) final int
The index of the classpath element within the parent classpath element (e.g.(package private) boolean
True if classpath element contains a specifically-accepted resource path.The map from File to last modified timestamp, if scanFiles is true.(package private) String
The name of the module from themodule-info.class
module descriptor, if one is present in the root of the classpath element.If non-null, contains a list of resolved paths for any classpath element roots nested inside this classpath element.protected String
The package root within the jarfile or Path.protected final AtomicBoolean
Flag to ensure classpath element is only scanned once.(package private) final ScanSpec
The scan spec.(package private) boolean
True if there was an exception when trying to open this classpath element (e.g. -
Constructor Summary
ConstructorsConstructorDescriptionClasspathElement
(Scanner.ClasspathEntryWorkUnit workUnit, ScanSpec scanSpec) A classpath element. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAcceptedResource
(Resource resource, ScanSpec.ScanSpecPathMatch parentMatchStatus, boolean isClassfileOnly, LogNode log) Add a resource discovered during the scan.protected boolean
checkResourcePathAcceptReject
(String relativePath, LogNode log) Check relativePath against classpathElementResourcePathAcceptReject.int
compareTo
(ClasspathElement other) Sort in increasing order of classpathElementIdxWithinParent.protected void
finishScanPaths
(LogNode log) Called by scanPaths() after scan completion.Get the URI for this classpath element, and the URIs for any automatic nested package prefixes (e.g.(package private) ClassLoader
Get the ClassLoader the classpath element was obtained from.(package private) abstract File
getFile()
Get the file for this classpath element, or null if this is a module with a "jrt:" URI.(package private) abstract String
Get the name of this classpath element's module, or null if there is no module name.(package private) int
Get the number of classfile matches.(package private) abstract Resource
getResource
(String relativePath) Get theResource
for a given relative path.(package private) abstract URI
getURI()
Get the URI for this classpath element.protected LogNode
Write entries to log in classpath / module path order.protected LogNode
Write entries to log in classpath / module path order.(package private) void
maskClassfiles
(int classpathIdx, Set<String> classpathRelativePathsFound, LogNode log) Apply relative path masking within this classpath resource -- remove relative paths that were found in an earlier classpath element.(package private) abstract void
open
(WorkQueue<Scanner.ClasspathEntryWorkUnit> workQueue, LogNode log) Determine if this classpath element is valid.(package private) abstract void
Scan paths in the classpath element for accept/reject criteria, creating Resource objects for accepted and non-rejected resources and classfiles.
-
Field Details
-
classpathElementIdx
int classpathElementIdxThe index of the classpath element within the classpath or module path. -
nestedClasspathRootPrefixes
If non-null, contains a list of resolved paths for any classpath element roots nested inside this classpath element. (Scanning should stop at a nested classpath element root, otherwise that subtree will be scanned more than once.) N.B. contains only the nested part of the resolved path (the common prefix is removed). Also includes a trailing '/', since only nested directory classpath elements need to be caught (nested jars do not need to be caught, because we don't scan jars-within-jars unless the inner jar is explicitly listed on the classpath). -
skipClasspathElement
boolean skipClasspathElementTrue if there was an exception when trying to open this classpath element (e.g. a corrupt ZipFile). -
containsSpecificallyAcceptedClasspathElementResourcePath
boolean containsSpecificallyAcceptedClasspathElementResourcePathTrue if classpath element contains a specifically-accepted resource path. -
classpathElementIdxWithinParent
final int classpathElementIdxWithinParentThe index of the classpath element within the parent classpath element (e.g. for classpath elements added via a Class-Path entry in the manifest). Set to -1 initially in case the same ClasspathElement is present twice in the classpath, as a child of different parent ClasspathElements. -
childClasspathElements
Collection<ClasspathElement> childClasspathElementsThe child classpath elements, keyed by the order of the child classpath element within the Class-Path entry of the manifest file the child classpath element was listed in (or the position of the file within the sorted entries of a lib directory). -
acceptedResources
Resources found within this classpath element that were accepted and not rejected. (Only written by one thread, so doesn't need to be a concurrent list.) -
acceptedClassfileResources
The list of all classfiles found within this classpath element that were accepted and not rejected. (Only written by one thread, so doesn't need to be a concurrent list.) -
fileToLastModified
The map from File to last modified timestamp, if scanFiles is true. -
scanned
Flag to ensure classpath element is only scanned once. -
classLoader
The classloader that this classpath element was obtained from. -
packageRootPrefix
The package root within the jarfile or Path. -
moduleNameFromModuleDescriptor
String moduleNameFromModuleDescriptorThe name of the module from themodule-info.class
module descriptor, if one is present in the root of the classpath element. -
scanSpec
The scan spec.
-
-
Constructor Details
-
ClasspathElement
ClasspathElement(Scanner.ClasspathEntryWorkUnit workUnit, ScanSpec scanSpec) A classpath element.- Parameters:
workUnit
- the work unitscanSpec
- the scan spec
-
-
Method Details
-
compareTo
Sort in increasing order of classpathElementIdxWithinParent.- Specified by:
compareTo
in interfaceComparable<ClasspathElement>
-
getClassLoader
ClassLoader getClassLoader()Get the ClassLoader the classpath element was obtained from.- Returns:
- the classloader
-
getNumClassfileMatches
int getNumClassfileMatches()Get the number of classfile matches.- Returns:
- the num classfile matches
-
checkResourcePathAcceptReject
Check relativePath against classpathElementResourcePathAcceptReject.- Parameters:
relativePath
- the relative pathlog
- the log- Returns:
- true if path should be scanned
-
maskClassfiles
Apply relative path masking within this classpath resource -- remove relative paths that were found in an earlier classpath element.- Parameters:
classpathIdx
- the classpath indexclasspathRelativePathsFound
- the classpath relative paths foundlog
- the log
-
addAcceptedResource
protected void addAcceptedResource(Resource resource, ScanSpec.ScanSpecPathMatch parentMatchStatus, boolean isClassfileOnly, LogNode log) Add a resource discovered during the scan.- Parameters:
resource
- the resourceparentMatchStatus
- the parent match statusisClassfileOnly
- if true, only add the resource to the list of classfile resources, not to the list of non-classfile resourceslog
- the log
-
finishScanPaths
Called by scanPaths() after scan completion.- Parameters:
log
- the log
-
log
Write entries to log in classpath / module path order.- Parameters:
classpathElementIdx
- the classpath element idxmsg
- the log messagelog
- the log- Returns:
- the new
LogNode
-
log
Write entries to log in classpath / module path order.- Parameters:
classpathElementIdx
- the classpath element idxmsg
- the log messaget
- The exception that was thrownlog
- the log- Returns:
- the new
LogNode
-
open
abstract void open(WorkQueue<Scanner.ClasspathEntryWorkUnit> workQueue, LogNode log) throws InterruptedException Determine if this classpath element is valid. If it is not valid, sets skipClasspathElement. ForClasspathElementZip
, may also open or extract inner jars, and also causes jarfile manifests to be read to look for Class-Path entries. If nested jars or Class-Path entries are found, they are added to the work queue. This method is only run once per classpath element, from a single thread.- Parameters:
workQueue
- the work queuelog
- the log- Throws:
InterruptedException
- if the thread was interrupted while trying to open the classpath element.
-
scanPaths
Scan paths in the classpath element for accept/reject criteria, creating Resource objects for accepted and non-rejected resources and classfiles.- Parameters:
log
- the log
-
getResource
Get theResource
for a given relative path.- Parameters:
relativePath
- The relative path of theResource
to return. Path should have already be sanitized by callinginvalid reference
FileUtils#sanitizeEntryPath(String, boolean)
- Returns:
- The
Resource
for the given relative path, or null if relativePath does not exist in this classpath element.
-
getURI
Get the URI for this classpath element.- Returns:
- the URI for the classpath element.
-
getAllURIs
Get the URI for this classpath element, and the URIs for any automatic nested package prefixes (e.g. "spring-boot.jar/BOOT-INF/classes") within this jarfile.- Returns:
- the URI for the classpath element.
-
getFile
Get the file for this classpath element, or null if this is a module with a "jrt:" URI.- Returns:
- the file for the classpath element.
-
getModuleName
Get the name of this classpath element's module, or null if there is no module name.- Returns:
- the module name
-