Class ClasspathOrModulePathEntry
- java.lang.Object
-
- io.github.lukehutch.fastclasspathscanner.utils.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 Summary
Fields Modifier and Type Field Description ClassLoader[]classLoadersThe ClassLoader(s) used to load classes for this classpath element
-
Constructor Summary
Constructors Constructor Description ClasspathOrModulePathEntry(ModuleRef moduleRef, NestedJarHandler nestedJarHandler, LogNode log)A relative path for a module (in JDK9+).ClasspathOrModulePathEntry(String pathToResolveAgainst, String relativePath, ClassLoader[] classLoaders, NestedJarHandler nestedJarHandler, ScanSpec scanSpec, LogNode log)A relative path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Return true based on equality of canonical paths.StringgetCanonicalPath(LogNode log)Gets the canonical path of the File object corresponding to the resolved path.ClassLoader[]getClassLoaders()Get the ClassLoader(s) that should be used to load classes for this classpath element.FilegetFile(LogNode log)Get the File object for the resolved path.StringgetJarfilePackageRoot()If non-empty, this path represents the package root within a jarfile, e.g.ModuleRefgetModuleRef()Returns the ModuleRef for this module, if this RelativePath corresponds to a module (in JDK9+).StringgetResolvedPath()Get the path of this classpath element, resolved against the parent path.inthashCode()Hash based on canonical path.booleanisClassfile()Returns true if resolved path has a .class extension, ignoring case.booleanisDirectory(LogNode log)True if this relative path corresponds with a directory.booleanisFile(LogNode log)True if this relative path corresponds with a file.booleanisHttpURL()Returns true if the path is an http(s):// URL.booleanisJrtURL()Returns true if the path is a jrt:/ URL.booleanisValidClasspathElement(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.StringtoString()Return the path.
-
-
-
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).
-
ClasspathOrModulePathEntry
public ClasspathOrModulePathEntry(ModuleRef moduleRef, NestedJarHandler nestedJarHandler, LogNode log)
A relative path for a module (in JDK9+).
-
-
Method Detail
-
equals
public boolean equals(Object o)
Return true based on equality of canonical paths.
-
getClassLoaders
public ClassLoader[] getClassLoaders()
Get the ClassLoader(s) that should be used to load classes for this classpath element.
-
getResolvedPath
public String getResolvedPath()
Get 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.
-
getModuleRef
public ModuleRef getModuleRef()
Returns the ModuleRef for this module, if this RelativePath corresponds to a module (in JDK9+).
-
getFile
public File getFile(LogNode log) throws IOException
Get the File object for the resolved path.- Throws:
IOException- if the path cannot be canonicalized.
-
getJarfilePackageRoot
public String getJarfilePackageRoot()
If non-empty, this path represents 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".
-
getCanonicalPath
public String getCanonicalPath(LogNode log) throws IOException
Gets the canonical path of the File object corresponding to the resolved path.- Throws:
IOException
-
isFile
public boolean isFile(LogNode log) throws IOException
True if this relative path corresponds with a file.- Throws:
IOException
-
isDirectory
public boolean isDirectory(LogNode log) throws IOException
True if this relative path corresponds with a directory.- Throws:
IOException
-
isClassfile
public boolean isClassfile()
Returns true if resolved path has a .class extension, ignoring case.
-
isValidClasspathElement
public boolean isValidClasspathElement(ScanSpec scanSpec, LogNode log) throws InterruptedException
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.
- Throws:
InterruptedException
-
-