Package io.github.classgraph
Class Scanner
java.lang.Object
io.github.classgraph.Scanner
- All Implemented Interfaces:
Callable<ScanResult>
The classpath scanner.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
WorkUnitProcessor for scanning classfiles.(package private) static class
Used to enqueue classfiles for scanning.(package private) static class
Used to enqueue classpath elements for opening. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SingletonMap
<Object, ClasspathElement, IOException> A singleton map used to eliminate creation of duplicateClasspathElement
objects, to reduce the chance that resources are scanned twice, by mapping canonicalized Path objects, URLs, etc.private final ClasspathFinder
The classpath finder.private final ExecutorService
The executor service.private final ClassGraph.FailureHandler
The failure handler.private final InterruptionChecker
The interruption checker.private final List
<ClasspathElementModule> The module order.private final NestedJarHandler
The nested jar handler.private final int
The number of parallel tasks.boolean
If true, performing a scan.private final ClassGraph.ScanResultProcessor
The scan result processor.private final ScanSpec
The scan spec.private final LogNode
The toplevel log. -
Constructor Summary
ConstructorsConstructorDescriptionScanner
(boolean performScan, ScanSpec scanSpec, ExecutorService executorService, int numParallelTasks, ClassGraph.ScanResultProcessor scanResultProcessor, ClassGraph.FailureHandler failureHandler, ReflectionUtils reflectionUtils, LogNode topLevelLog) The classpath scanner. -
Method Summary
Modifier and TypeMethodDescriptioncall()
Determine the unique ordered classpath elements, and run a scan looking for file or classfile matches if necessary.private List
<ClasspathElement> findClasspathOrder
(Set<ClasspathElement> 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
(ClasspathElement currClasspathElement, Set<ClasspathElement> visitedClasspathElts, List<ClasspathElement> order) Recursively perform a depth-first search of jar interdependencies, breaking cycles if necessary, to determine the final classpath element order.private void
findNestedClasspathElements
(List<AbstractMap.SimpleEntry<String, ClasspathElement>> classpathElts, LogNode log) Find classpath elements whose path is a prefix of another classpath element, and record the nesting.private void
maskClassfiles
(List<ClasspathElement> classpathElementOrder, LogNode maskLog) Perform classpath masking of classfiles.newClasspathEntryWorkUnitProcessor
(Set<ClasspathElement> allClasspathEltsOut, Set<ClasspathElement> toplevelClasspathEltsOut) Create a WorkUnitProcessor for opening traditional classpath entries (which are mapped toClasspathElementDir
orClasspathElementZip
--is handled separately
).private static Object
normalizeClasspathEntry
(Object classpathEntryObj) private ScanResult
Open each of the classpath elements, looking for additional child classpath elements that need scanning (e.g.private ScanResult
performScan
(List<ClasspathElement> finalClasspathEltOrder, List<String> finalClasspathEltOrderStrs, ClasspathFinder classpathFinder) Scan the classpath and/or visible modules.private void
preprocessClasspathElementsByType
(List<ClasspathElement> finalTraditionalClasspathEltOrder, LogNode classpathFinderLog) Find classpath elements whose path is a prefix of another classpath element, and record the nesting.private <W> void
processWorkUnits
(Collection<W> workUnits, LogNode log, WorkQueue.WorkUnitProcessor<W> workUnitProcessor) Process work units.
-
Field Details
-
scanSpec
The scan spec. -
performScan
public boolean performScanIf true, performing a scan. If false, only fetching the classpath. -
nestedJarHandler
The nested jar handler. -
executorService
The executor service. -
interruptionChecker
The interruption checker. -
numParallelTasks
private final int numParallelTasksThe number of parallel tasks. -
scanResultProcessor
The scan result processor. -
failureHandler
The failure handler. -
topLevelLog
The toplevel log. -
classpathFinder
The classpath finder. -
moduleOrder
The module order. -
classpathEntryObjToClasspathEntrySingletonMap
private final SingletonMap<Object,ClasspathElement, classpathEntryObjToClasspathEntrySingletonMapIOException> A singleton map used to eliminate creation of duplicateClasspathElement
objects, to reduce the chance that resources are scanned twice, by mapping canonicalized Path objects, URLs, etc. to ClasspathElements.
-
-
Constructor Details
-
Scanner
Scanner(boolean performScan, ScanSpec scanSpec, ExecutorService executorService, int numParallelTasks, ClassGraph.ScanResultProcessor scanResultProcessor, ClassGraph.FailureHandler failureHandler, ReflectionUtils reflectionUtils, LogNode topLevelLog) throws InterruptedException The classpath scanner. Scanning is started by callingcall()
on this object.- Parameters:
performScan
- If true, performing a scan. If false, only fetching the classpath.scanSpec
- the scan specexecutorService
- the executor servicenumParallelTasks
- the num parallel tasksscanResultProcessor
- the scan result processorfailureHandler
- the failure handlertopLevelLog
- the log- Throws:
InterruptedException
- if interrupted
-
-
Method Details
-
findClasspathOrderRec
private static void findClasspathOrderRec(ClasspathElement currClasspathElement, Set<ClasspathElement> visitedClasspathElts, 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
- the current classpath elementvisitedClasspathElts
- visited classpath eltsorder
- the classpath element order
-
findClasspathOrder
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
- the toplevel classpath elts, indexed by order within the toplevel classpath- Returns:
- the final classpath order, after depth-first traversal of child classpath elements
-
processWorkUnits
private <W> void processWorkUnits(Collection<W> workUnits, LogNode log, WorkQueue.WorkUnitProcessor<W> workUnitProcessor) throws InterruptedException, ExecutionException Process work units.- Type Parameters:
W
- the work unit type- Parameters:
workUnits
- the work unitslog
- the log entry text to group work units underworkUnitProcessor
- the work unit processor- Throws:
InterruptedException
- if a worker was interrupted.ExecutionException
- If a worker threw an uncaught exception.
-
normalizeClasspathEntry
Normalize a classpath entry object so that it is mapped to a canonicalPath
object if possible, falling back to aURL
orURI
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
- The classpath entry object.- Returns:
- The normalized classpath entry object.
- Throws:
IOException
-
newClasspathEntryWorkUnitProcessor
private WorkQueue.WorkUnitProcessor<Scanner.ClasspathEntryWorkUnit> newClasspathEntryWorkUnitProcessor(Set<ClasspathElement> allClasspathEltsOut, Set<ClasspathElement> toplevelClasspathEltsOut) Create a WorkUnitProcessor for opening traditional classpath entries (which are mapped toClasspathElementDir
orClasspathElementZip
--is handled separately
).- Parameters:
allClasspathEltsOut
- on exit, the set of all classpath elementstoplevelClasspathEltsOut
- on exit, the toplevel classpath elements- Returns:
- the work unit processor
-
findNestedClasspathElements
private void findNestedClasspathElements(List<AbstractMap.SimpleEntry<String, ClasspathElement>> classpathElts, LogNode log) Find classpath elements whose path is a prefix of another classpath element, and record the nesting.- Parameters:
classpathElts
- the classpath elementslog
- the log
-
preprocessClasspathElementsByType
private void preprocessClasspathElementsByType(List<ClasspathElement> finalTraditionalClasspathEltOrder, LogNode classpathFinderLog) Find classpath elements whose path is a prefix of another classpath element, and record the nesting.- Parameters:
finalTraditionalClasspathEltOrder
- the final traditional classpath elt orderclasspathFinderLog
- the classpath finder log
-
maskClassfiles
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
- the classpath element ordermaskLog
- the mask log
-
performScan
private ScanResult performScan(List<ClasspathElement> finalClasspathEltOrder, List<String> finalClasspathEltOrderStrs, ClasspathFinder classpathFinder) throws InterruptedException, ExecutionException Scan the classpath and/or visible modules.- Parameters:
finalClasspathEltOrder
- the final classpath elt orderfinalClasspathEltOrderStrs
- the final classpath elt order strsclasspathFinder
- theClasspathFinder
- Returns:
- the scan result
- Throws:
InterruptedException
- if the scan was interruptedExecutionException
- if the scan threw an uncaught exception
-
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 ifinvalid reference
ScanSpec#performScan
invalid reference
ScanSpec#performScan
- Returns:
- the scan result
- Throws:
InterruptedException
- if the scan was interruptedExecutionException
- if a worker threw an uncaught exception
-
call
Determine the unique ordered classpath elements, and run a scan looking for file or classfile matches if necessary.- Specified by:
call
in interfaceCallable<ScanResult>
- Returns:
- the scan result
- Throws:
InterruptedException
- if scanning was interruptedCancellationException
- if scanning was cancelledExecutionException
- if a worker threw an uncaught exception
-