Class AuxClasspathLoader
- All Implemented Interfaces:
AutoCloseable
URLClassLoader, the Jar files on the classpath are not opened with JarFile and
their signature is not verified which saves memory. The Jar files are opened directly
with ZipFile.
This classpath loader also supports loading platform classes (e.g. java.lang) from
the jrt-fs filesystem. All zip files and the jrt-fs are kept open, until this classpath loader
is closed.
To create a new instance, use create(String). Because verifying the classpath and
opening the platform classloader via the jrt-fs filesystem is expensive, it supports a simple
caching mechanism. See enableReuse(int) and disableReuse().
To load resources, use findResource(String).
This class is usually not used directly for calling PMD but rather by language implementations
such as Java. The auxClasspath should be configured
via PMDConfiguration.setAuxClasspath(String)
- Experimental Status:
- Replacement for
ClasspathClassLoader. - Since:
- 7.27.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static AuxClasspathLoaderstatic voidIfenableReuse(int)is used, then this method can be used to explicitly close the cached auxiliary classpath classloaders.static voidenableReuse(int count) Enables caching of AuxClasspathLoader instances.@Nullable InputStreamfindResource(String name) Finds the first resource with the given name (e.g.toString()
-
Method Details
-
create
-
enableReuse
Enables caching of AuxClasspathLoader instances. This is useful for unit tests or IDE plugins, when PMD is executed multiple times within one JVM instance.- Experimental Status:
- Parameters:
count- Maximum number of instances to be cached. The oldest instances are evicted first.- Since:
- 7.27.0
- See Also:
-
disableReuse
IfenableReuse(int)is used, then this method can be used to explicitly close the cached auxiliary classpath classloaders.Call this only, when it is known, that PMD is not currently executing (e.g. PmdAnalysis is finished).
- Experimental Status:
- Since:
- 7.27.0
-
findResource
Finds the first resource with the given name (e.g.package/A.class) in the jars of the auxClasspath. If there is no match in the jar files, then the Java Runtime Image is searched via the given "jrt-fs.jar". This allows to find e.g.java/lang/Object.class. If no resource is found,nullis returned.The name is expected to be a valid, relative path name within a jar file without a leading slash, e.g.
package/A.class.In order to load
module-info.classfiles, which are all at the root of the jar files, these can be referenced by prefixing the module name, e.g.full.module.name/module-info.classorjava.base/module-info.class.Note: Multi-Release Jars are not handled in a special way. This method does not automatically search for versioned resources.
- Parameters:
name- Name of the resource to load, e.g.package/A.class- Returns:
- an open
InputStreamornullif the resource is not found. - See Also:
-
toString
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-