Class PluginFirstClassLoader2
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- jenkins.util.URLClassLoader2
-
- hudson.PluginFirstClassLoader2
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,JenkinsClassLoader
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public class PluginFirstClassLoader2 extends URLClassLoader2
Class loader that consults the plugin'sWEB-INF/lib/*.jar
andWEB-INF/classes
directories and the Jenkins core class loader (in that order).To use this class loader, set
pluginFirstClassLoader
totrue
in themaven-hpi-plugin
configuration.- Author:
- Basil Crow
-
-
Constructor Summary
Constructors Constructor Description PluginFirstClassLoader2(URL[] urls, ClassLoader parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description URL
getResource(String name)
Find the resource with the given name.Enumeration<URL>
getResources(String name)
Find all the resources with the given name.protected Class<?>
loadClass(String name, boolean resolve)
Load the class with the specified binary name.-
Methods inherited from class jenkins.util.URLClassLoader2
addURL, findClass, findLoadedClass2, getClassLoadingLock
-
Methods inherited from class java.net.URLClassLoader
close, definePackage, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
-
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jenkins.util.JenkinsClassLoader
findResource, findResources
-
-
-
-
Constructor Detail
-
PluginFirstClassLoader2
public PluginFirstClassLoader2(@NonNull URL[] urls, @NonNull ClassLoader parent)
-
-
Method Detail
-
loadClass
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
Load the class with the specified binary name. This method searches for classes in the following order:-
Invoke
ClassLoader.findLoadedClass(String)
to check if the class has already been loaded. -
Invoke
URLClassLoader2.findClass(String)
to find the class. -
Invoke
ClassLoader.loadClass(String)
on the parent class loader.
If the class was found using the above steps and the
resolve
flag is true, this method will then invokeClassLoader.resolveClass(Class)
on the resultingClass
object.This method synchronizes on the result of
URLClassLoader2.getClassLoadingLock(String)
during the entire class loading process.- Overrides:
loadClass
in classClassLoader
- Parameters:
name
- The binary name of the classresolve
- Iftrue
then resolve the class- Returns:
- The resulting
Class
object - Throws:
ClassNotFoundException
- If the class could not be found
-
-
getResource
public URL getResource(String name)
Find the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.The name of a resource is a '
/
'-separated path name that identifies the resource. This method searches for resources in the following order:-
Invoke
URLClassLoader.findResource(String)
to find the resource. -
Invoke
getResource(String)
on the parent class loader.
- Overrides:
getResource
in classClassLoader
- Parameters:
name
- The resource name- Returns:
URL
object for reading the resource;null
if the resource could not be found, aURL
could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.- Throws:
NullPointerException
- Ifname
isnull
-
-
getResources
public Enumeration<URL> getResources(String name) throws IOException
Find all the resources with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.The name of a resource is a
/
-separated path name that identifies the resource. This method first invokesURLClassLoader.findResources(String)
to find the resources with the name in this class loader. Finally, it invokesgetResources(String)
on the parent class loader. It returns an enumeration whose elements are theURL
s found by searching theURL
s found withURLClassLoader.findResources(String)
, followed by theURL
s found by searching the parent class loader.- Overrides:
getResources
in classClassLoader
- Parameters:
name
- The resource name- Returns:
- An enumeration of
URL
objects for the resource. If no resources could be found, the enumeration will be empty. Resources for which aURL
cannot be constructed, which are in a package that is not opened unconditionally, or for which access to the resource is denied by the security manager, are not returned in the enumeration. - Throws:
IOException
- If I/O errors occurNullPointerException
- Ifname
isnull
-
-