Package io.github.classgraph.utils
Class ClasspathOrModulePathEntry
- java.lang.Object
-
- io.github.classgraph.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[]
classLoaders
The 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 boolean
equals(Object o)
Return true based on equality of resolved paths.String
getCanonicalPath(LogNode log)
ClassLoader[]
getClassLoaders()
File
getFile(LogNode log)
String
getJarfilePackageRoot()
ModuleRef
getModuleRef()
String
getResolvedPath()
int
hashCode()
Hash based on canonical path.boolean
isClassfile()
boolean
isDirectory(LogNode log)
boolean
isFile(LogNode log)
boolean
isHttpURL()
boolean
isJrtURL()
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.String
toString()
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).- Parameters:
pathToResolveAgainst
- The base path.relativePath
- The relative path.classLoaders
- The environment classloaders.nestedJarHandler
- TheNestedJarHandler
.scanSpec
- TheScanSpec
.log
- The log.
-
ClasspathOrModulePathEntry
public ClasspathOrModulePathEntry(ModuleRef moduleRef, NestedJarHandler nestedJarHandler, LogNode log)
A relative path for a module (in JDK9+).- Parameters:
moduleRef
- TheModuleRef
.nestedJarHandler
- TheNestedJarHandler
.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.
-
getModuleRef
public ModuleRef getModuleRef()
- Returns:
- The
ModuleRef
for this module, if thisClasspathOrModulePathEntry
corresponds to a module.
-
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 (""). N.B. this should only be called after
getFile(LogNode)
, since that method sets this field.
-
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
- TheScanSpec
.log
- The log.- Returns:
- true if this relative path is a valid classpath element.
-
equals
public boolean equals(Object o)
Return true based on equality of resolved paths.
-
-