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 ClassLoaderThe classloader that this classpath element was obtained from.(package private) intThe index of the classpath element within the classpath or module path.(package private) final intThe index of the classpath element within the parent classpath element (e.g.(package private) booleanTrue if classpath element contains a specifically-accepted resource path.The map from File to last modified timestamp, if scanFiles is true.(package private) StringThe name of the module from themodule-info.classmodule 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 StringThe package root within the jarfile or Path.protected final AtomicBooleanFlag to ensure classpath element is only scanned once.protected ScanResultThe ScanResult that the classpath element came from.(package private) final ScanSpecThe scan spec.(package private) booleanTrue 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 voidaddAcceptedResource(Resource resource, ScanSpec.ScanSpecPathMatch parentMatchStatus, boolean isClassfileOnly, LogNode log) Add a resource discovered during the scan.protected booleancheckResourcePathAcceptReject(String relativePath, LogNode log) Check relativePath against classpathElementResourcePathAcceptReject.intcompareTo(ClasspathElement other) Sort in increasing order of classpathElementIdxWithinParent.protected voidfinishScanPaths(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) ClassLoaderGet the ClassLoader the classpath element was obtained from.(package private) abstract FilegetFile()Get the file for this classpath element, or null if this is a module with a "jrt:" URI.(package private) abstract StringGet the name of this classpath element's module, or null if there is no module name.(package private) intGet the number of classfile matches.(package private) abstract ResourcegetResource(String relativePath) Get theResourcefor a given relative path.(package private) abstract URIgetURI()Get the URI for this classpath element.protected LogNodeWrite entries to log in classpath / module path order.protected LogNodeWrite entries to log in classpath / module path order.(package private) voidmaskClassfiles(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 voidopen(WorkQueue<Scanner.ClasspathEntryWorkUnit> workQueue, LogNode log) Determine if this classpath element is valid.(package private) abstract voidScan paths in the classpath element for accept/reject criteria, creating Resource objects for accepted and non-rejected resources and classfiles.(package private) voidsetScanResult(ScanResult scanResult) Used to set the ScanResult after the scan is complete.
-
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.classmodule descriptor, if one is present in the root of the classpath element. -
scanSpec
The scan spec. -
scanResult
The ScanResult that the classpath element came from.
-
-
Constructor Details
-
ClasspathElement
ClasspathElement(Scanner.ClasspathEntryWorkUnit workUnit, ScanSpec scanSpec) A classpath element.- Parameters:
workUnit- the work unitscanSpec- the scan spec
-
-
Method Details
-
setScanResult
Used to set the ScanResult after the scan is complete. -
compareTo
Sort in increasing order of classpathElementIdxWithinParent.- Specified by:
compareToin 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 theResourcefor a given relative path.- Parameters:
relativePath- The relative path of theResourceto return. Path should have already be sanitized by calling, or by providing a path that is already sanitized (i.e. doesn't start or end with "/", doesn't contain "/../" or "/./", etc.).invalid reference
FileUtils#sanitizeEntryPath(String, boolean)- Returns:
- The
Resourcefor 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
-