Top Description Inners Fields Constructors Methods
io.github.classgraph

pack-priv Class Scanner

extends Object
implements Callable<ScanResult>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Imports
java.io.File, .IOException, java.net.MalformedURLException, .URI, .URISyntaxException, .URL, java.nio.file.FileSystemNotFoundException, .Files, .InvalidPathException, .Path, .Paths, java.nio.file.attribute.BasicFileAttributes, java.util.AbstractMap.SimpleEntry, .ArrayList, .Collection, .Collections, .Comparator, .HashMap, .HashSet, .List, .Map, .Queue, .Set, java.util.concurrent.Callable, .CancellationException, .ConcurrentHashMap, .ConcurrentLinkedQueue, .ExecutionException, .ExecutorService, io.github.classgraph.ClassGraph.FailureHandler, .ClassGraph.ScanResultProcessor, .Classfile.ClassfileFormatException, .Classfile.SkipClassException, nonapi.io.github.classgraph.classpath.ClasspathFinder, .ClasspathOrder.ClasspathEntry, .ModuleFinder, nonapi.io.github.classgraph.concurrency.AutoCloseableExecutorService, .InterruptionChecker, .SingletonMap, .SingletonMap.NewInstanceFactory, .WorkQueue, .WorkQueue.WorkUnitProcessor, nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler, nonapi.io.github.classgraph.reflection.ReflectionUtils, nonapi.io.github.classgraph.scanspec.ScanSpec, nonapi.io.github.classgraph.utils.CollectionUtils, .FastPathResolver, .FileUtils, .JarUtils, .LogNode

The classpath scanner.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Scanner.ClassfileScannerWorkUnitProcessor

WorkUnitProcessor for scanning classfiles.

pack-priv static class
Scanner.ClassfileScanWorkUnit

Used to enqueue classfiles for scanning.

pack-priv static class
Scanner.ClasspathEntryWorkUnit

Used to enqueue classpath elements for opening.

Field Summary

Modifier and TypeField and Description
private final SingletonMap<Object, ClasspathElement, IOException>
classpathEntryObjToClasspathEntrySingletonMap

A singleton map used to eliminate creation of duplicate ClasspathElement objects, to reduce the chance that resources are scanned twice, by mapping canonicalized Path objects, URLs, etc. to ClasspathElements.

private final ClasspathFinder
classpathFinder

The classpath finder.

private final ExecutorService
executorService

The executor service.

private final ClassGraph.FailureHandler
failureHandler

The failure handler.

private final InterruptionChecker
interruptionChecker

The interruption checker.

private final List<ClasspathElementModule>
moduleOrder

The module order.

private final NestedJarHandler
nestedJarHandler

The nested jar handler.

private final int
numParallelTasks

The number of parallel tasks.

public boolean
performScan

If true, performing a scan.

private final ClassGraph.ScanResultProcessor
scanResultProcessor

The scan result processor.

private final ScanSpec
scanSpec

The scan spec.

private final LogNode
topLevelLog

The toplevel log.

Constructor Summary

AccessConstructor and Description
pack-priv
Scanner(final boolean
If true, performing a scan. If false, only fetching the classpath.
performScan
,
final ScanSpec
the scan spec
scanSpec
,
final ExecutorService
the executor service
executorService
,
final int
the num parallel tasks
numParallelTasks
,
final ClassGraph.ScanResultProcessor
the scan result processor
scanResultProcessor
,
final ClassGraph.FailureHandler
the failure handler
failureHandler
,
final ReflectionUtils reflectionUtils, final LogNode
the log
topLevelLog
)

The classpath scanner.

Method Summary

Modifier and TypeMethod and Description
public ScanResult

Returns:

the scan result
call
()

Implements java.util.concurrent.Callable.call.

Determine the unique ordered classpath elements, and run a scan looking for file or classfile matches if necessary.

private List<ClasspathElement>

Returns:

the final classpath order, after depth-first traversal of child classpath elements
findClasspathOrder
(final Set<ClasspathElement>
the toplevel classpath elts, indexed by order within the toplevel classpath
toplevelClasspathElts
)

Recursively perform a depth-first traversal of child classpath elements, breaking cycles if necessary, to determine the final classpath element order.

private static void
findClasspathOrderRec(final ClasspathElement
the current classpath element
currClasspathElement
,
final Set<ClasspathElement>
visited classpath elts
visitedClasspathElts
,
final List<ClasspathElement>
the classpath element order
order
)

Recursively perform a depth-first search of jar interdependencies, breaking cycles if necessary, to determine the final classpath element order.

private void
findNestedClasspathElements(final List<AbstractMap.SimpleEntry<String, ClasspathElement>>
the classpath elements
classpathElts
,
final LogNode
the log
log
)

Find classpath elements whose path is a prefix of another classpath element, and record the nesting.

private void
maskClassfiles(final List<ClasspathElement>
the classpath element order
classpathElementOrder
,
final LogNode
the mask log
maskLog
)

Perform classpath masking of classfiles.

private WorkQueue.WorkUnitProcessor<Scanner.ClasspathEntryWorkUnit>

Returns:

the work unit processor
newClasspathEntryWorkUnitProcessor
(final Set<ClasspathElement>
on exit, the set of all classpath elements
allClasspathEltsOut
,
final Set<ClasspathElement>
on exit, the toplevel classpath elements
toplevelClasspathEltsOut
)

Create a WorkUnitProcessor for opening traditional classpath entries (which are mapped to ClasspathElementDir or ClasspathElementZip -- is handled separately).

private static Object

Returns:

The normalized classpath entry object.
normalizeClasspathEntry
(final Object
The classpath entry object.
classpathEntryObj
)

Normalize a classpath entry object so that it is mapped to a canonical Path object if possible, falling back to a URL or URI if not possible.

private ScanResult

Returns:

the scan result
openClasspathElementsThenScan
()

Open each of the classpath elements, looking for additional child classpath elements that need scanning (e.g. Class-Path entries in jar manifest files), then perform the scan if ScanSpec#performScan is true, or just get the classpath if ScanSpec#performScan is false.

private ScanResult

Returns:

the scan result
performScan
(final List<ClasspathElement>
the final classpath elt order
finalClasspathEltOrder
,
final List<String>
the final classpath elt order strs
finalClasspathEltOrderStrs
,
final ClasspathFinder classpathFinder)

Scan the classpath and/or visible modules.

private void
preprocessClasspathElementsByType(final List<ClasspathElement>
the final traditional classpath elt order
finalTraditionalClasspathEltOrder
,
final LogNode
the classpath finder log
classpathFinderLog
)

Find classpath elements whose path is a prefix of another classpath element, and record the nesting.

private <
the work unit type
W
>
void
processWorkUnits(final Collection<W>
the work units
workUnits
,
final LogNode
the log entry text to group work units under
log
,
final WorkQueue.WorkUnitProcessor<W>
the work unit processor
workUnitProcessor
)

Process work units.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classpathEntryObjToClasspathEntrySingletonMapback to summary
private final SingletonMap<Object, ClasspathElement, IOException> classpathEntryObjToClasspathEntrySingletonMap

A singleton map used to eliminate creation of duplicate ClasspathElement objects, to reduce the chance that resources are scanned twice, by mapping canonicalized Path objects, URLs, etc. to ClasspathElements.

classpathFinderback to summary
private final ClasspathFinder classpathFinder

The classpath finder.

executorServiceback to summary
private final ExecutorService executorService

The executor service.

failureHandlerback to summary
private final ClassGraph.FailureHandler failureHandler

The failure handler.

interruptionCheckerback to summary
private final InterruptionChecker interruptionChecker

The interruption checker.

moduleOrderback to summary
private final List<ClasspathElementModule> moduleOrder

The module order.

nestedJarHandlerback to summary
private final NestedJarHandler nestedJarHandler

The nested jar handler.

numParallelTasksback to summary
private final int numParallelTasks

The number of parallel tasks.

performScanback to summary
public boolean performScan

If true, performing a scan. If false, only fetching the classpath.

scanResultProcessorback to summary
private final ClassGraph.ScanResultProcessor scanResultProcessor

The scan result processor.

scanSpecback to summary
private final ScanSpec scanSpec

The scan spec.

topLevelLogback to summary
private final LogNode topLevelLog

The toplevel log.

Constructor Detail

Scannerback to summary
pack-priv Scanner(final boolean performScan, final ScanSpec scanSpec, final ExecutorService executorService, final int numParallelTasks, final ClassGraph.ScanResultProcessor scanResultProcessor, final ClassGraph.FailureHandler failureHandler, final ReflectionUtils reflectionUtils, final LogNode topLevelLog) throws InterruptedException

The classpath scanner. Scanning is started by calling call() on this object.

Parameters
performScan:boolean

If true, performing a scan. If false, only fetching the classpath.

scanSpec:ScanSpec

the scan spec

executorService:ExecutorService

the executor service

numParallelTasks:int

the num parallel tasks

scanResultProcessor:ClassGraph.ScanResultProcessor

the scan result processor

failureHandler:ClassGraph.FailureHandler

the failure handler

topLevelLog:LogNode

the log

Exceptions
InterruptedException:
if interrupted

Method Detail

callback to summary
public ScanResult call() throws InterruptedException, CancellationException, ExecutionException

Implements java.util.concurrent.Callable.call.

Determine the unique ordered classpath elements, and run a scan looking for file or classfile matches if necessary.

Returns:ScanResult

the scan result

Annotations
@Override
Exceptions
InterruptedException:
if scanning was interrupted
CancellationException:
if scanning was cancelled
ExecutionException:
if a worker threw an uncaught exception
findClasspathOrderback to summary
private List<ClasspathElement> findClasspathOrder(final Set<ClasspathElement> toplevelClasspathElts)

Recursively perform a depth-first traversal of child classpath elements, breaking cycles if necessary, to determine the final classpath element order. This causes child classpath elements to be inserted in-place in the classpath order, after the parent classpath element that contained them.

Parameters
toplevelClasspathElts:Set<ClasspathElement>

the toplevel classpath elts, indexed by order within the toplevel classpath

Returns:List<ClasspathElement>

the final classpath order, after depth-first traversal of child classpath elements

findClasspathOrderRecback to summary
private static void findClasspathOrderRec(final ClasspathElement currClasspathElement, final Set<ClasspathElement> visitedClasspathElts, final List<ClasspathElement> order)

Recursively perform a depth-first search of jar interdependencies, breaking cycles if necessary, to determine the final classpath element order.

Parameters
currClasspathElement:ClasspathElement

the current classpath element

visitedClasspathElts:Set<ClasspathElement>

visited classpath elts

order:List<ClasspathElement>

the classpath element order

findNestedClasspathElementsback to summary
private void findNestedClasspathElements(final List<AbstractMap.SimpleEntry<String, ClasspathElement>> classpathElts, final LogNode log)

Find classpath elements whose path is a prefix of another classpath element, and record the nesting.

Parameters
classpathElts:List<AbstractMap.SimpleEntry<String, ClasspathElement>>

the classpath elements

log:LogNode

the log

maskClassfilesback to summary
private void maskClassfiles(final List<ClasspathElement> classpathElementOrder, final LogNode maskLog)

Perform classpath masking of classfiles. If the same relative classfile path occurs multiple times in the classpath, causes the second and subsequent occurrences to be ignored (removed).

Parameters
classpathElementOrder:List<ClasspathElement>

the classpath element order

maskLog:LogNode

the mask log

newClasspathEntryWorkUnitProcessorback to summary
private WorkQueue.WorkUnitProcessor<Scanner.ClasspathEntryWorkUnit> newClasspathEntryWorkUnitProcessor(final Set<ClasspathElement> allClasspathEltsOut, final Set<ClasspathElement> toplevelClasspathEltsOut)

Create a WorkUnitProcessor for opening traditional classpath entries (which are mapped to ClasspathElementDir or ClasspathElementZip -- is handled separately).

Parameters
allClasspathEltsOut:Set<ClasspathElement>

on exit, the set of all classpath elements

toplevelClasspathEltsOut:Set<ClasspathElement>

on exit, the toplevel classpath elements

Returns:WorkQueue.WorkUnitProcessor<Scanner.ClasspathEntryWorkUnit>

the work unit processor

normalizeClasspathEntryback to summary
private static Object normalizeClasspathEntry(final Object classpathEntryObj) throws IOException

Normalize a classpath entry object so that it is mapped to a canonical Path object if possible, falling back to a URL or URI if not possible. This is needed to avoid treating "file:///path/to/x.jar" and "/path/to/x.jar" as different classpath elements. Maps URL("jar:file:x.jar!/") to Path("x.jar"), etc.

Parameters
classpathEntryObj:Object

The classpath entry object.

Returns:Object

The normalized classpath entry object.

openClasspathElementsThenScanback to summary
private ScanResult openClasspathElementsThenScan() throws InterruptedException, ExecutionException

Open each of the classpath elements, looking for additional child classpath elements that need scanning (e.g. Class-Path entries in jar manifest files), then perform the scan if ScanSpec#performScan is true, or just get the classpath if ScanSpec#performScan is false.

Returns:ScanResult

the scan result

Exceptions
InterruptedException:
if the scan was interrupted
ExecutionException:
if a worker threw an uncaught exception
performScanback to summary
private ScanResult performScan(final List<ClasspathElement> finalClasspathEltOrder, final List<String> finalClasspathEltOrderStrs, final ClasspathFinder classpathFinder) throws InterruptedException, ExecutionException

Scan the classpath and/or visible modules.

Parameters
finalClasspathEltOrder:List<ClasspathElement>

the final classpath elt order

finalClasspathEltOrderStrs:List<String>

the final classpath elt order strs

classpathFinder:ClasspathFinder

the ClasspathFinder

Returns:ScanResult

the scan result

Exceptions
InterruptedException:
if the scan was interrupted
ExecutionException:
if the scan threw an uncaught exception
preprocessClasspathElementsByTypeback to summary
private void preprocessClasspathElementsByType(final List<ClasspathElement> finalTraditionalClasspathEltOrder, final LogNode classpathFinderLog)

Find classpath elements whose path is a prefix of another classpath element, and record the nesting.

Parameters
finalTraditionalClasspathEltOrder:List<ClasspathElement>

the final traditional classpath elt order

classpathFinderLog:LogNode

the classpath finder log

processWorkUnitsback to summary
private <W> void processWorkUnits(final Collection<W> workUnits, final LogNode log, final WorkQueue.WorkUnitProcessor<W> workUnitProcessor) throws InterruptedException, ExecutionException

Process work units.

Parameters
<W>
the work unit type
workUnits:Collection<W>

the work units

log:LogNode

the log entry text to group work units under

workUnitProcessor:WorkQueue.WorkUnitProcessor<W>

the work unit processor

Exceptions
InterruptedException:
if a worker was interrupted.
ExecutionException:
If a worker threw an uncaught exception.
io.github.classgraph back to summary

private Class Scanner.ClassfileScannerWorkUnitProcessor

extends Object
implements WorkQueue.WorkUnitProcessor<Scanner.ClassfileScanWorkUnit>
Class Inheritance
  • java.lang.Object
  • io.github.classgraph.Scanner.ClassfileScannerWorkUnitProcessor
All Implemented Interfaces
nonapi.io.github.classgraph.concurrency.WorkQueue.WorkUnitProcessor

WorkUnitProcessor for scanning classfiles.

Field Summary

Modifier and TypeField and Description
private final Set<String>
acceptedClassNamesFound

The names of accepted classes found in the classpath while scanning paths within classpath elements.

private final Set<String>
classNamesScheduledForExtendedScanning

The names of external (non-accepted) classes scheduled for extended scanning (where scanning is extended upwards to superclasses, interfaces and annotations).

private final List<ClasspathElement>
classpathOrder

The classpath order.

private final Queue<Classfile>
scannedClassfiles

The valid Classfile objects created by scanning classfiles.

private final ScanSpec
scanSpec

The scan spec.

private final ConcurrentHashMap<String, String>
stringInternMap

The string intern map.

Constructor Summary

AccessConstructor and Description
public
ClassfileScannerWorkUnitProcessor(final ScanSpec
the scan spec
scanSpec
,
final List<ClasspathElement>
the classpath order
classpathOrder
,
final Set<String>
the names of accepted classes found in the classpath while scanning paths within classpath elements.
acceptedClassNamesFound
,
final Queue<Classfile>
the Classfile objects created by scanning classfiles
scannedClassfiles
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
processWorkUnit(final Scanner.ClassfileScanWorkUnit
the work unit
workUnit
,
final WorkQueue<Scanner.ClassfileScanWorkUnit>
the work queue
workQueue
,
final LogNode
the log
log
)

Implements nonapi.io.github.classgraph.concurrency.WorkQueue.WorkUnitProcessor.processWorkUnit.

Process work unit.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

acceptedClassNamesFoundback to summary
private final Set<String> acceptedClassNamesFound

The names of accepted classes found in the classpath while scanning paths within classpath elements.

classNamesScheduledForExtendedScanningback to summary
private final Set<String> classNamesScheduledForExtendedScanning

The names of external (non-accepted) classes scheduled for extended scanning (where scanning is extended upwards to superclasses, interfaces and annotations).

classpathOrderback to summary
private final List<ClasspathElement> classpathOrder

The classpath order.

scannedClassfilesback to summary
private final Queue<Classfile> scannedClassfiles

The valid Classfile objects created by scanning classfiles.

scanSpecback to summary
private final ScanSpec scanSpec

The scan spec.

stringInternMapback to summary
private final ConcurrentHashMap<String, String> stringInternMap

The string intern map.

Constructor Detail

ClassfileScannerWorkUnitProcessorback to summary
public ClassfileScannerWorkUnitProcessor(final ScanSpec scanSpec, final List<ClasspathElement> classpathOrder, final Set<String> acceptedClassNamesFound, final Queue<Classfile> scannedClassfiles)

Constructor.

Parameters
scanSpec:ScanSpec

the scan spec

classpathOrder:List<ClasspathElement>

the classpath order

acceptedClassNamesFound:Set<String>

the names of accepted classes found in the classpath while scanning paths within classpath elements.

scannedClassfiles:Queue<Classfile>

the Classfile objects created by scanning classfiles

Method Detail

processWorkUnitback to summary
public void processWorkUnit(final Scanner.ClassfileScanWorkUnit workUnit, final WorkQueue<Scanner.ClassfileScanWorkUnit> workQueue, final LogNode log) throws InterruptedException

Implements nonapi.io.github.classgraph.concurrency.WorkQueue.WorkUnitProcessor.processWorkUnit.

Process work unit.

Parameters
workUnit:Scanner.ClassfileScanWorkUnit

the work unit

workQueue:WorkQueue<Scanner.ClassfileScanWorkUnit>

the work queue

log:LogNode

the log

Annotations
@Override
Exceptions
InterruptedException:
the interrupted exception
io.github.classgraph back to summary

pack-priv Class Scanner.ClassfileScanWorkUnit

extends Object
Class Inheritance

Used to enqueue classfiles for scanning.

Field Summary

Modifier and TypeField and Description
private final Resource
classfileResource

The classfile resource.

private final ClasspathElement
classpathElement

The classpath element.

private final boolean
isExternalClass

True if this is an external class.

Constructor Summary

AccessConstructor and Description
pack-priv
ClassfileScanWorkUnit(final ClasspathElement
the classpath element
classpathElement
,
final Resource
the classfile resource
classfileResource
,
final boolean
the is external class
isExternalClass
)

Constructor.

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classfileResourceback to summary
private final Resource classfileResource

The classfile resource.

classpathElementback to summary
private final ClasspathElement classpathElement

The classpath element.

isExternalClassback to summary
private final boolean isExternalClass

True if this is an external class.

Constructor Detail

ClassfileScanWorkUnitback to summary
pack-priv ClassfileScanWorkUnit(final ClasspathElement classpathElement, final Resource classfileResource, final boolean isExternalClass)

Constructor.

Parameters
classpathElement:ClasspathElement

the classpath element

classfileResource:Resource

the classfile resource

isExternalClass:boolean

the is external class

io.github.classgraph back to summary

pack-priv Class Scanner.ClasspathEntryWorkUnit

extends Object
Class Inheritance

Used to enqueue classpath elements for opening.

Field Summary

Modifier and TypeField and Description
pack-priv final ClassLoader
classLoader

The classloader the classpath entry object was obtained from.

pack-priv final int
classpathElementIdxWithinParent

The order within the parent classpath element.

pack-priv Object
classpathEntryObj

The classpath entry object (a String path, Path, URL or URI).

pack-priv final String
packageRootPrefix

The package root prefix (e.g. "BOOT-INF/classes/").

pack-priv final ClasspathElement
parentClasspathElement

The parent classpath element.

Constructor Summary

AccessConstructor and Description
public
ClasspathEntryWorkUnit(final Object
the raw classpath entry object
classpathEntryObj
,
final ClassLoader
the classloader the classpath entry object was obtained from
classLoader
,
final ClasspathElement
the parent classpath element
parentClasspathElement
,
final int
the order within parent classpath element
classpathElementIdxWithinParent
,
final String
the package root prefix
packageRootPrefix
)

Constructor.

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classLoaderback to summary
pack-priv final ClassLoader classLoader

The classloader the classpath entry object was obtained from.

classpathElementIdxWithinParentback to summary
pack-priv final int classpathElementIdxWithinParent

The order within the parent classpath element.

classpathEntryObjback to summary
pack-priv Object classpathEntryObj

The classpath entry object (a String path, Path, URL or URI).

packageRootPrefixback to summary
pack-priv final String packageRootPrefix

The package root prefix (e.g. "BOOT-INF/classes/").

parentClasspathElementback to summary
pack-priv final ClasspathElement parentClasspathElement

The parent classpath element.

Constructor Detail

ClasspathEntryWorkUnitback to summary
public ClasspathEntryWorkUnit(final Object classpathEntryObj, final ClassLoader classLoader, final ClasspathElement parentClasspathElement, final int classpathElementIdxWithinParent, final String packageRootPrefix)

Constructor.

Parameters
classpathEntryObj:Object

the raw classpath entry object

classLoader:ClassLoader

the classloader the classpath entry object was obtained from

parentClasspathElement:ClasspathElement

the parent classpath element

classpathElementIdxWithinParent:int

the order within parent classpath element

packageRootPrefix:String

the package root prefix