Package hudson

Class 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's WEB-INF/lib/*.jar and WEB-INF/classes directories and the Jenkins core class loader (in that order).

To use this class loader, set pluginFirstClassLoader to true in the maven-hpi-plugin configuration.

Author:
Basil Crow
  • Constructor Details

    • PluginFirstClassLoader2

      public PluginFirstClassLoader2(String name, @NonNull URL[] urls, @NonNull ClassLoader parent)
  • Method Details

    • 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:
      1. Invoke ClassLoader.findLoadedClass(String) to check if the class has already been loaded.

      2. Invoke URLClassLoader2.findClass(String) to find the class.

      3. 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 invoke ClassLoader.resolveClass(Class) on the resulting Class object.

      This method synchronizes on the result of URLClassLoader2.getClassLoadingLock(String) during the entire class loading process.

      Overrides:
      loadClass in class ClassLoader
      Parameters:
      name - The binary name of the class
      resolve - If true 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:

      1. Invoke URLClassLoader.findResource(String) to find the resource.

      2. Invoke getResource(String) on the parent class loader.

      Overrides:
      getResource in class ClassLoader
      Parameters:
      name - The resource name
      Returns:
      URL object for reading the resource; null if the resource could not be found, a URL 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 - If name is null
    • 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 invokes URLClassLoader.findResources(String) to find the resources with the name in this class loader. Finally, it invokes getResources(String) on the parent class loader. It returns an enumeration whose elements are the URLs found by searching the URLs found with URLClassLoader.findResources(String), followed by the URLs found by searching the parent class loader.

      Overrides:
      getResources in class ClassLoader
      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 a URL 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 occur
      NullPointerException - If name is null