Class ClasspathElement

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<Resource> acceptedClassfileResources
      The list of all classfiles found within this classpath element that were accepted and not rejected.
      protected java.util.List<Resource> acceptedResources
      Resources found within this classpath element that were accepted and not rejected.
      (package private) java.util.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 java.lang.ClassLoader classLoader
      The classloader that this classpath element was obtained from.
      (package private) int classpathElementIdx
      The index of the classpath element within the classpath or module path.
      (package private) int classpathElementIdxWithinParent
      The index of the classpath element within the parent classpath element (e.g.
      (package private) boolean containsSpecificallyAcceptedClasspathElementResourcePath
      True if classpath element contains a specifically-accepted resource path.
      protected java.util.Map<java.io.File,​java.lang.Long> fileToLastModified
      The map from File to last modified timestamp, if scanFiles is true.
      (package private) java.lang.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.
      (package private) java.util.List<java.lang.String> nestedClasspathRootPrefixes
      If non-null, contains a list of resolved paths for any classpath element roots nested inside this classpath element.
      protected java.lang.String packageRootPrefix
      The package root within the jarfile or Path.
      protected java.util.concurrent.atomic.AtomicBoolean scanned
      Flag to ensure classpath element is only scanned once.
      (package private) ScanSpec scanSpec
      The scan spec.
      (package private) boolean skipClasspathElement
      True if there was an exception when trying to open this classpath element (e.g.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addAcceptedResource​(Resource resource, ScanSpec.ScanSpecPathMatch parentMatchStatus, boolean isClassfileOnly, LogNode log)
      Add a resource discovered during the scan.
      protected boolean checkResourcePathAcceptReject​(java.lang.String relativePath, LogNode log)
      Check relativePath against classpathElementResourcePathAcceptReject.
      int compareTo​(ClasspathElement other)
      Sort in increasing order of classpathElementIdxWithinParent.
      protected void finishScanPaths​(LogNode log)
      Called by scanPaths() after scan completion.
      (package private) abstract java.util.List<java.net.URI> getAllURIs()
      Get the URI for this classpath element, and the URIs for any automatic nested package prefixes (e.g.
      (package private) java.lang.ClassLoader getClassLoader()
      Get the ClassLoader the classpath element was obtained from.
      (package private) abstract java.io.File getFile()
      Get the file for this classpath element, or null if this is a module with a "jrt:" URI.
      (package private) abstract java.lang.String getModuleName()
      Get the name of this classpath element's module, or null if there is no module name.
      (package private) int getNumClassfileMatches()
      Get the number of classfile matches.
      (package private) abstract Resource getResource​(java.lang.String relativePath)
      Get the Resource for a given relative path.
      (package private) abstract java.net.URI getURI()
      Get the URI for this classpath element.
      protected LogNode log​(int classpathElementIdx, java.lang.String msg, java.lang.Throwable t, LogNode log)
      Write entries to log in classpath / module path order.
      protected LogNode log​(int classpathElementIdx, java.lang.String msg, LogNode log)
      Write entries to log in classpath / module path order.
      (package private) void maskClassfiles​(int classpathIdx, java.util.Set<java.lang.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 void open​(WorkQueue<Scanner.ClasspathEntryWorkUnit> workQueue, LogNode log)
      Determine if this classpath element is valid.
      (package private) abstract void scanPaths​(LogNode log)
      Scan paths in the classpath element for accept/reject criteria, creating Resource objects for accepted and non-rejected resources and classfiles.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • classpathElementIdx

        int classpathElementIdx
        The index of the classpath element within the classpath or module path.
      • nestedClasspathRootPrefixes

        java.util.List<java.lang.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).
      • skipClasspathElement

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

        boolean containsSpecificallyAcceptedClasspathElementResourcePath
        True if classpath element contains a specifically-accepted resource path.
      • classpathElementIdxWithinParent

        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.
      • childClasspathElements

        java.util.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).
      • acceptedResources

        protected final java.util.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.)
      • acceptedClassfileResources

        protected java.util.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.)
      • fileToLastModified

        protected final java.util.Map<java.io.File,​java.lang.Long> fileToLastModified
        The map from File to last modified timestamp, if scanFiles is true.
      • scanned

        protected final java.util.concurrent.atomic.AtomicBoolean scanned
        Flag to ensure classpath element is only scanned once.
      • classLoader

        protected java.lang.ClassLoader classLoader
        The classloader that this classpath element was obtained from.
      • packageRootPrefix

        protected java.lang.String packageRootPrefix
        The package root within the jarfile or Path.
      • moduleNameFromModuleDescriptor

        java.lang.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.
      • scanSpec

        final ScanSpec scanSpec
        The scan spec.
    • Constructor Detail

    • Method Detail

      • compareTo

        public int compareTo​(ClasspathElement other)
        Sort in increasing order of classpathElementIdxWithinParent.
        Specified by:
        compareTo in interface java.lang.Comparable<ClasspathElement>
      • getClassLoader

        java.lang.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

        protected boolean checkResourcePathAcceptReject​(java.lang.String relativePath,
                                                        LogNode log)
        Check relativePath against classpathElementResourcePathAcceptReject.
        Parameters:
        relativePath - the relative path
        log - the log
        Returns:
        true if path should be scanned
      • maskClassfiles

        void maskClassfiles​(int classpathIdx,
                            java.util.Set<java.lang.String> classpathRelativePathsFound,
                            LogNode log)
        Apply relative path masking within this classpath resource -- remove relative paths that were found in an earlier classpath element.
        Parameters:
        classpathIdx - the classpath index
        classpathRelativePathsFound - the classpath relative paths found
        log - 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 resource
        parentMatchStatus - the parent match status
        isClassfileOnly - if true, only add the resource to the list of classfile resources, not to the list of non-classfile resources
        log - the log
      • finishScanPaths

        protected void finishScanPaths​(LogNode log)
        Called by scanPaths() after scan completion.
        Parameters:
        log - the log
      • log

        protected LogNode log​(int classpathElementIdx,
                              java.lang.String msg,
                              LogNode log)
        Write entries to log in classpath / module path order.
        Parameters:
        classpathElementIdx - the classpath element idx
        msg - the log message
        log - the log
        Returns:
        the new LogNode
      • log

        protected LogNode log​(int classpathElementIdx,
                              java.lang.String msg,
                              java.lang.Throwable t,
                              LogNode log)
        Write entries to log in classpath / module path order.
        Parameters:
        classpathElementIdx - the classpath element idx
        msg - the log message
        t - The exception that was thrown
        log - the log
        Returns:
        the new LogNode
      • open

        abstract void open​(WorkQueue<Scanner.ClasspathEntryWorkUnit> workQueue,
                           LogNode log)
                    throws java.lang.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 - the work queue
        log - the log
        Throws:
        java.lang.InterruptedException - if the thread was interrupted while trying to open the classpath element.
      • scanPaths

        abstract void scanPaths​(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 - the log
      • getResource

        abstract Resource getResource​(java.lang.String relativePath)
        Get the Resource for a given relative path.
        Parameters:
        relativePath - 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:
        The Resource for the given relative path, or null if relativePath does not exist in this classpath element.
      • getURI

        abstract java.net.URI getURI()
        Get the URI for this classpath element.
        Returns:
        the URI for the classpath element.
      • getAllURIs

        abstract java.util.List<java.net.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:
        the URI for the classpath element.
      • getFile

        abstract java.io.File 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

        abstract java.lang.String getModuleName()
        Get the name of this classpath element's module, or null if there is no module name.
        Returns:
        the module name