Class Scanner

java.lang.Object
io.github.classgraph.Scanner
All Implemented Interfaces:
Callable<ScanResult>

class Scanner extends Object implements Callable<ScanResult>
The classpath scanner.
  • Field Details

    • scanSpec

      private final ScanSpec scanSpec
      The scan spec.
    • performScan

      public boolean performScan
      If true, performing a scan. If false, only fetching the classpath.
    • nestedJarHandler

      private final NestedJarHandler nestedJarHandler
      The nested jar handler.
    • executorService

      private final ExecutorService executorService
      The executor service.
    • interruptionChecker

      private final InterruptionChecker interruptionChecker
      The interruption checker.
    • numParallelTasks

      private final int numParallelTasks
      The number of parallel tasks.
    • scanResultProcessor

      private final ClassGraph.ScanResultProcessor scanResultProcessor
      The scan result processor.
    • failureHandler

      private final ClassGraph.FailureHandler failureHandler
      The failure handler.
    • topLevelLog

      private final LogNode topLevelLog
      The toplevel log.
    • classpathFinder

      private final ClasspathFinder classpathFinder
      The classpath finder.
    • moduleOrder

      private final List<ClasspathElementModule> moduleOrder
      The module order.
    • classpathEntryObjToClasspathEntrySingletonMap

      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.
  • Constructor Details

  • 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 element
      visitedClasspathElts - visited classpath elts
      order - the classpath element order
    • findClasspathOrder

      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. 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 units
      log - the log entry text to group work units under
      workUnitProcessor - the work unit processor
      Throws:
      InterruptedException - if a worker was interrupted.
      ExecutionException - If a worker threw an uncaught exception.
    • normalizeClasspathEntry

      private static Object normalizeClasspathEntry(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 - 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 to ClasspathElementDir or ClasspathElementZip -- is handled separately).
      Parameters:
      allClasspathEltsOut - on exit, the set of all classpath elements
      toplevelClasspathEltsOut - 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 elements
      log - 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 order
      classpathFinderLog - the classpath finder log
    • maskClassfiles

      private void maskClassfiles(List<ClasspathElement> classpathElementOrder, 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 - the classpath element order
      maskLog - 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 order
      finalClasspathEltOrderStrs - the final classpath elt order strs
      classpathFinder - the ClasspathFinder
      Returns:
      the scan result
      Throws:
      InterruptedException - if the scan was interrupted
      ExecutionException - if the scan threw an uncaught exception
    • openClasspathElementsThenScan

      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
      invalid reference
      ScanSpec#performScan
      is true, or just get the classpath if
      invalid reference
      ScanSpec#performScan
      is false.
      Returns:
      the scan result
      Throws:
      InterruptedException - if the scan was interrupted
      ExecutionException - 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 interface Callable<ScanResult>
      Returns:
      the scan result
      Throws:
      InterruptedException - if scanning was interrupted
      CancellationException - if scanning was cancelled
      ExecutionException - if a worker threw an uncaught exception