Class ClasspathOrModulePathEntry


  • public class ClasspathOrModulePathEntry
    extends Object
    An entry in the classpath or module path. If the path is an http(s):// URL, the remote jar will be fetched and cached if getFile() / isFile() etc. are called. If the path is a '!'-separated path to a nested jar, the innermost jar will be extracted and cached on these calls.
    • Field Detail

      • classLoaders

        public ClassLoader[] classLoaders
        The ClassLoader(s) used to load classes for this classpath element
    • Constructor Detail

      • ClasspathOrModulePathEntry

        public ClasspathOrModulePathEntry​(String pathToResolveAgainst,
                                          String relativePath,
                                          ClassLoader[] classLoaders,
                                          NestedJarHandler nestedJarHandler,
                                          ScanSpec scanSpec,
                                          LogNode log)
        A relative path. This is used for paths relative to the current directory (for classpath elements), and also for relative paths within classpath elements (e.g. the files within a ZipFile).
        Parameters:
        pathToResolveAgainst - The base path.
        relativePath - The relative path.
        classLoaders - The environment classloaders.
        nestedJarHandler - The NestedJarHandler.
        scanSpec - The ScanSpec.
        log - The log.
    • Method Detail

      • getClassLoaders

        public ClassLoader[] getClassLoaders()
        Returns:
        The ClassLoader(s) that should be used to load classes for this classpath element.
      • getResolvedPath

        public String getResolvedPath()
        Returns:
        The path of this classpath element, resolved against the parent path.
      • isHttpURL

        public boolean isHttpURL()
        Returns:
        true if the path is an http(s):// URL.
      • isJrtURL

        public boolean isJrtURL()
        Returns:
        true if the path is a jrt:/ URL.
      • getFile

        public File getFile​(LogNode log)
                     throws IOException
        Parameters:
        log - The log.
        Returns:
        The File object for the resolved path.
        Throws:
        IOException - if the path cannot be canonicalized.
      • getJarfilePackageRoot

        public String getJarfilePackageRoot()
        Returns:
        The package root within a jarfile, e.g. if the path is "spring-project.jar!/BOOT-INF/classes", the package root is "BOOT-INF/classes". Usually empty ("").
      • getCanonicalPath

        public String getCanonicalPath​(LogNode log)
                                throws IOException
        Parameters:
        log - The log.
        Returns:
        The canonical path of the File object corresponding to the resolved path.
        Throws:
        IOException - If there was an error in canonicalization.
      • isFile

        public boolean isFile​(LogNode log)
                       throws IOException
        Parameters:
        log - The log.
        Returns:
        true if this relative path corresponds with a file.
        Throws:
        IOException - If the file can't be read.
      • isDirectory

        public boolean isDirectory​(LogNode log)
                            throws IOException
        Parameters:
        log - The log.
        Returns:
        True if this relative path corresponds with a directory.
        Throws:
        IOException - If the file can't be read.
      • isClassfile

        public boolean isClassfile()
        Returns:
        true if resolved path has a .class extension, ignoring case.
      • isValidClasspathElement

        public boolean isValidClasspathElement​(ScanSpec scanSpec,
                                               LogNode log)
        True if this relative path is a valid classpath element: that its path can be canonicalized, that it exists, that it is a jarfile or directory, that it is not a blacklisted jar, that it should be scanned, etc.

        N.B. this has the side effect of fetching any http(s):// URLs, and/or unzipping any inner jarfiles, to determine if these paths are valid. Any resulting temporary files will be cached.

        Parameters:
        scanSpec - The ScanSpec.
        log - The log.
        Returns:
        true if this relative path is a valid classpath element.
      • hashCode

        public int hashCode()
        Hash based on canonical path.
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object o)
        Return true based on equality of canonical paths.
        Overrides:
        equals in class Object