Top Description Fields Constructors Methods
io.github.classgraph

pack-priv abstract Class ClasspathElement

extends Object
implements Comparable<ClasspathElement>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
io.github.classgraph.ClasspathElementDir, io.github.classgraph.ClasspathElementModule, io.github.classgraph.ClasspathElementZip
Imports
java.io.File, java.net.URI, java.util.ArrayList, .Collection, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicBoolean, io.github.classgraph.Scanner.ClasspathEntryWorkUnit, nonapi.io.github.classgraph.concurrency.WorkQueue, nonapi.io.github.classgraph.scanspec.ScanSpec, .ScanSpec.ScanSpecPathMatch, nonapi.io.github.classgraph.utils.FileUtils, .JarUtils, .LogNode

A classpath element (a directory or jarfile on the classpath).

Field Summary

Modifier and TypeField and Description
protected List<Resource>
acceptedClassfileResources

The list of all classfiles found within this classpath element that were accepted and not rejected.

protected final List<Resource>
acceptedResources

Resources found within this classpath element that were accepted and not rejected.

pack-priv Collection<ClasspathElement>
childClasspathElements

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
classLoader

The classloader that this classpath element was obtained from.

pack-priv int
classpathElementIdx

The index of the classpath element within the classpath or module path.

pack-priv final int
classpathElementIdxWithinParent

The index of the classpath element within the parent classpath element (e.g. for classpath elements added via a Class-Path entry in the manifest).

pack-priv boolean
containsSpecificallyAcceptedClasspathElementResourcePath

True if classpath element contains a specifically-accepted resource path.

protected final Map<File, Long>
fileToLastModified

The map from File to last modified timestamp, if scanFiles is true.

pack-priv String
moduleNameFromModuleDescriptor

The name of the module from the module-info.class module descriptor, if one is present in the root of the classpath element.

pack-priv List<String>
nestedClasspathRootPrefixes

If non-null, contains a list of resolved paths for any classpath element roots nested inside this classpath element.

protected String
packageRootPrefix

The package root within the jarfile or Path.

protected final AtomicBoolean
scanned

Flag to ensure classpath element is only scanned once.

protected ScanResult
scanResult

The ScanResult that the classpath element came from.

pack-priv final ScanSpec
scanSpec

The scan spec.

pack-priv boolean
skipClasspathElement

True if there was an exception when trying to open this classpath element (e.g. a corrupt ZipFile).

Constructor Summary

AccessConstructor and Description
pack-priv
ClasspathElement(final Scanner.ClasspathEntryWorkUnit
the work unit
workUnit
,
final ScanSpec
the scan spec
scanSpec
)

A classpath element.

Method Summary

Modifier and TypeMethod and Description
protected void
addAcceptedResource(final Resource
the resource
resource
,
final ScanSpec.ScanSpecPathMatch
the parent match status
parentMatchStatus
,
final boolean
if true, only add the resource to the list of classfile resources, not to the list of non-classfile resources
isClassfileOnly
,
final LogNode
the log
log
)

Add a resource discovered during the scan.

protected boolean

Returns:

true if path should be scanned
checkResourcePathAcceptReject
(final String
the relative path
relativePath
,
final LogNode
the log
log
)

Check relativePath against classpathElementResourcePathAcceptReject.

public int
compareTo(final ClasspathElement
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Sort in increasing order of classpathElementIdxWithinParent.

protected void
finishScanPaths(final LogNode
the log
log
)

Called by scanPaths() after scan completion.

pack-priv abstract List<URI>

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.

pack-priv ClassLoader

Returns:

the classloader
getClassLoader
()

Get the ClassLoader the classpath element was obtained from.

pack-priv abstract File

Returns:

the file for the classpath element.
getFile
()

Get the file for this classpath element, or null if this is a module with a "jrt:" URI.

pack-priv abstract String

Returns:

the module name
getModuleName
()

Get the name of this classpath element's module, or null if there is no module name.

pack-priv int

Returns:

the num classfile matches
getNumClassfileMatches
()

Get the number of classfile matches.

pack-priv abstract Resource

Returns:

The Resource for the given relative path, or null if relativePath does not exist in this classpath element.
getResource
(final String
The relative path of the Resource to return. Path should have already be sanitized by calling FileUtils#sanitizeEntryPath(String, boolean), or by providing a path that is already sanitized (i.e. doesn't start or end with "/", doesn't contain "/../" or "/./", etc.).
relativePath
)

Get the Resource for a given relative path.

pack-priv abstract URI

Returns:

the URI for the classpath element.
getURI
()

Get the URI for this classpath element.

protected LogNode

Returns:

the new LogNode
log
(final int
the classpath element idx
classpathElementIdx
,
final String
the log message
msg
,
final LogNode
the log
log
)

Write entries to log in classpath / module path order.

protected LogNode

Returns:

the new LogNode
log
(final int
the classpath element idx
classpathElementIdx
,
final String
the log message
msg
,
final Throwable
The exception that was thrown
t
,
final LogNode
the log
log
)

Write entries to log in classpath / module path order.

pack-priv void
maskClassfiles(final int
the classpath index
classpathIdx
,
final Set<String>
the classpath relative paths found
classpathRelativePathsFound
,
final LogNode
the log
log
)

Apply relative path masking within this classpath resource -- remove relative paths that were found in an earlier classpath element.

pack-priv abstract void
open(final WorkQueue<Scanner.ClasspathEntryWorkUnit>
the work queue
workQueue
,
final LogNode
the log
log
)

Determine if this classpath element is valid.

pack-priv abstract void
scanPaths(final LogNode
the log
log
)

Scan paths in the classpath element for accept/reject criteria, creating Resource objects for accepted and non-rejected resources and classfiles.

pack-priv void
setScanResult(final ScanResult scanResult)

Used to set the ScanResult after the scan is complete.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

acceptedClassfileResourcesback to summary
protected List<Resource> 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.)

acceptedResourcesback to summary
protected final List<Resource> 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.)

childClasspathElementsback to summary
pack-priv Collection<ClasspathElement> childClasspathElements

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).

classLoaderback to summary
protected ClassLoader classLoader

The classloader that this classpath element was obtained from.

classpathElementIdxback to summary
pack-priv int classpathElementIdx

The index of the classpath element within the classpath or module path.

classpathElementIdxWithinParentback to summary
pack-priv final int classpathElementIdxWithinParent

The 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.

containsSpecificallyAcceptedClasspathElementResourcePathback to summary
pack-priv boolean containsSpecificallyAcceptedClasspathElementResourcePath

True if classpath element contains a specifically-accepted resource path.

fileToLastModifiedback to summary
protected final Map<File, Long> fileToLastModified

The map from File to last modified timestamp, if scanFiles is true.

moduleNameFromModuleDescriptorback to summary
pack-priv String moduleNameFromModuleDescriptor

The name of the module from the module-info.class module descriptor, if one is present in the root of the classpath element.

nestedClasspathRootPrefixesback to summary
pack-priv List<String> 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).

packageRootPrefixback to summary
protected String packageRootPrefix

The package root within the jarfile or Path.

scannedback to summary
protected final AtomicBoolean scanned

Flag to ensure classpath element is only scanned once.

scanResultback to summary
protected ScanResult scanResult

The ScanResult that the classpath element came from.

scanSpecback to summary
pack-priv final ScanSpec scanSpec

The scan spec.

skipClasspathElementback to summary
pack-priv boolean skipClasspathElement

True if there was an exception when trying to open this classpath element (e.g. a corrupt ZipFile).

Constructor Detail

ClasspathElementback to summary
pack-priv ClasspathElement(final Scanner.ClasspathEntryWorkUnit workUnit, final ScanSpec scanSpec)

A classpath element.

Parameters
workUnit:Scanner.ClasspathEntryWorkUnit

the work unit

scanSpec:ScanSpec

the scan spec

Method Detail

addAcceptedResourceback to summary
protected void addAcceptedResource(final Resource resource, final ScanSpec.ScanSpecPathMatch parentMatchStatus, final boolean isClassfileOnly, final LogNode log)

Add a resource discovered during the scan.

Parameters
resource:Resource

the resource

parentMatchStatus:ScanSpec.ScanSpecPathMatch

the parent match status

isClassfileOnly:boolean

if true, only add the resource to the list of classfile resources, not to the list of non-classfile resources

log:LogNode

the log

checkResourcePathAcceptRejectback to summary
protected boolean checkResourcePathAcceptReject(final String relativePath, final LogNode log)

Check relativePath against classpathElementResourcePathAcceptReject.

Parameters
relativePath:String

the relative path

log:LogNode

the log

Returns:boolean

true if path should be scanned

compareToback to summary
public int compareTo(final ClasspathElement other)

Implements java.lang.Comparable.compareTo.

Sort in increasing order of classpathElementIdxWithinParent.

Parameters
other:ClasspathElement

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
finishScanPathsback to summary
protected void finishScanPaths(final LogNode log)

Called by scanPaths() after scan completion.

Parameters
log:LogNode

the log

getAllURIsback to summary
pack-priv abstract List<URI> 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:List<URI>

the URI for the classpath element.

getClassLoaderback to summary
pack-priv ClassLoader getClassLoader()

Get the ClassLoader the classpath element was obtained from.

Returns:ClassLoader

the classloader

getFileback to summary
pack-priv abstract File getFile()

Get the file for this classpath element, or null if this is a module with a "jrt:" URI.

Returns:File

the file for the classpath element.

getModuleNameback to summary
pack-priv abstract String getModuleName()

Get the name of this classpath element's module, or null if there is no module name.

Returns:String

the module name

getNumClassfileMatchesback to summary
pack-priv int getNumClassfileMatches()

Get the number of classfile matches.

Returns:int

the num classfile matches

getResourceback to summary
pack-priv abstract Resource getResource(final String relativePath)

Get the Resource for a given relative path.

Parameters
relativePath:String

The relative path of the Resource to return. Path should have already be sanitized by calling FileUtils#sanitizeEntryPath(String, boolean), or by providing a path that is already sanitized (i.e. doesn't start or end with "/", doesn't contain "/../" or "/./", etc.).

Returns:Resource

The Resource for the given relative path, or null if relativePath does not exist in this classpath element.

getURIback to summary
pack-priv abstract URI getURI()

Get the URI for this classpath element.

Returns:URI

the URI for the classpath element.

logback to summary
protected LogNode log(final int classpathElementIdx, final String msg, final LogNode log)

Write entries to log in classpath / module path order.

Parameters
classpathElementIdx:int

the classpath element idx

msg:String

the log message

log:LogNode

the log

Returns:LogNode

the new LogNode

logback to summary
protected LogNode log(final int classpathElementIdx, final String msg, final Throwable t, final LogNode log)

Write entries to log in classpath / module path order.

Parameters
classpathElementIdx:int

the classpath element idx

msg:String

the log message

t:Throwable

The exception that was thrown

log:LogNode

the log

Returns:LogNode

the new LogNode

maskClassfilesback to summary
pack-priv void maskClassfiles(final int classpathIdx, final Set<String> classpathRelativePathsFound, final LogNode log)

Apply relative path masking within this classpath resource -- remove relative paths that were found in an earlier classpath element.

Parameters
classpathIdx:int

the classpath index

classpathRelativePathsFound:Set<String>

the classpath relative paths found

log:LogNode

the log

openback to summary
pack-priv abstract void open(final WorkQueue<Scanner.ClasspathEntryWorkUnit> workQueue, final LogNode log) throws InterruptedException

Determine if this classpath element is valid. If it is not valid, sets skipClasspathElement. For ClasspathElementZip, 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:WorkQueue<Scanner.ClasspathEntryWorkUnit>

the work queue

log:LogNode

the log

Exceptions
InterruptedException:
if the thread was interrupted while trying to open the classpath element.
scanPathsback to summary
pack-priv abstract void scanPaths(final LogNode log)

Scan paths in the classpath element for accept/reject criteria, creating Resource objects for accepted and non-rejected resources and classfiles.

Parameters
log:LogNode

the log

setScanResultback to summary
pack-priv void setScanResult(final ScanResult scanResult)

Used to set the ScanResult after the scan is complete.