Class QuarkusClassLoader

java.lang.Object
java.lang.ClassLoader
io.quarkus.bootstrap.classloading.QuarkusClassLoader
All Implemented Interfaces:
Closeable, AutoCloseable

public class QuarkusClassLoader extends ClassLoader implements Closeable
The ClassLoader used for non production Quarkus applications (i.e. dev and test mode).
  • Field Details

  • Method Details

    • visitRuntimeResources

      public static void visitRuntimeResources(String resourceName, Consumer<io.quarkus.paths.PathVisit> visitor)
      Visits every found runtime resource with a given name. If a resource is not found, the visitor will simply not be called.

      IMPORTANT: this method works only when the current class loader is an instance of QuarkusClassLoader, otherwise it throws an error with the corresponding message.

      Parameters:
      resourceName - runtime resource name to visit
      visitor - runtime resource visitor
    • getElements

      public static List<ClassPathElement> getElements(String resourceName, boolean onlyFromCurrentClassLoader)
    • isClassPresentAtRuntime

      public static boolean isClassPresentAtRuntime(String className)
      Indicates if a given class is present at runtime.
      Parameters:
      className - the name of the class.
    • isApplicationClass

      public static boolean isApplicationClass(String className)
      Indicates if a given class is considered an application class.
    • isResourcePresentAtRuntime

      public static boolean isResourcePresentAtRuntime(String resourcePath)
      Indicates if a given resource is present at runtime. Can also be used to check if a class is present as a class is just a regular resource.
      Parameters:
      resourcePath - the path of the resource, for instance path/to/my-resources.properties for a properties file or my/package/MyClass.class for a class.
    • builder

      public static QuarkusClassLoader.Builder builder(String name, ClassLoader parent, boolean parentFirst)
    • reset

      public void reset(Map<String,byte[]> generatedResources, Map<String,byte[]> transformedClasses)
    • getInMemoryClassBytes

      public Map<String,byte[]> getInMemoryClassBytes()
      Returns all in-memory generated and transformed class bytes, keyed by resource path (e.g. io/quarkus/runner/Foo.class).

      Classes are collected in classloader priority order: transformed classes first, then resettable element, then normal priority elements, then lesser priority elements. Only MemoryClassPathElement instances are included. Uses putIfAbsent so higher-priority entries win.

      Intended for reproducibility testing infrastructure.

    • getResources

      public Enumeration<URL> getResources(String unsanitisedName) throws IOException
      Overrides:
      getResources in class ClassLoader
      Throws:
      IOException
    • getResources

      public Enumeration<URL> getResources(String unsanitisedName, boolean parentAlreadyFoundResources) throws IOException
      Throws:
      IOException
    • getResource

      public URL getResource(String unsanitisedName)
      Overrides:
      getResource in class ClassLoader
    • getResourceAsStream

      public InputStream getResourceAsStream(String unsanitisedName)
      Overrides:
      getResourceAsStream in class ClassLoader
    • findClass

      protected Class<?> findClass(String moduleName, String name)
      This method is needed to make packages work correctly on JDK9+, as it will be called to load the package-info class.
      Overrides:
      findClass in class ClassLoader
      Parameters:
      moduleName -
      name -
      Returns:
    • findResource

      protected URL findResource(String name)
      Overrides:
      findResource in class ClassLoader
    • findResources

      protected Enumeration<URL> findResources(String name) throws IOException
      Overrides:
      findResources in class ClassLoader
      Throws:
      IOException
    • loadClass

      public Class<?> loadClass(String name) throws ClassNotFoundException
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • loadClass

      protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • getElementsWithResource

      public List<ClassPathElement> getElementsWithResource(String name)
    • getElementsWithResource

      public List<ClassPathElement> getElementsWithResource(String name, boolean localOnly)
    • getReloadableClassNames

      public Set<String> getReloadableClassNames()
    • visibleDefineClass

      public Class<?> visibleDefineClass(String name, byte[] b, int off, int len) throws ClassFormatError
      Throws:
      ClassFormatError
    • addCloseTask

      public void addCloseTask(Runnable task)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isClosed

      public boolean isClosed()
    • getCuratedApplication

      public CuratedApplication getCuratedApplication()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getStartupAction

      public StartupAction getStartupAction()
    • setStartupAction

      public void setStartupAction(StartupAction startupAction)
    • parent

      @Deprecated(since="3.34", forRemoval=true) public ClassLoader parent()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getName

      public String getName()
      Overrides:
      getName in class ClassLoader