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).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQuarkusClassLoader.Builder
-
Field Summary
Fields Modifier and Type Field Description protected static StringJAVAprotected static StringMETA_INF_SERVICES
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCloseTask(Runnable task)static QuarkusClassLoader.Builderbuilder(String name, ClassLoader parent, boolean parentFirst)voidclose()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.protected URLfindResource(String name)protected Enumeration<URL>findResources(String name)List<ClassPathElement>getAllElements(boolean onlyFromCurrentClassLoader)static List<ClassPathElement>getElements(String resourceName, boolean onlyFromCurrentClassLoader)List<ClassPathElement>getElementsWithResource(String name)List<ClassPathElement>getElementsWithResource(String name, boolean localOnly)List<String>getLocalClassNames()StringgetName()URLgetResource(String unsanitisedName)InputStreamgetResourceAsStream(String unsanitisedName)Enumeration<URL>getResources(String unsanitisedName)Enumeration<URL>getResources(String unsanitisedName, boolean parentAlreadyFoundResources)static booleanisClassPresentAtRuntime(String className)Indicates if a given class is present at runtime.booleanisClosed()booleanisParentFirst(String name)Returns true if the supplied class is a class that would be loaded parent-firststatic booleanisResourcePresentAtRuntime(String resourcePath)Indicates if a given resource is present at runtime.Class<?>loadClass(String name)protected Class<?>loadClass(String name, boolean resolve)ClassLoaderparent()voidreset(Map<String,byte[]> generatedResources, Map<String,byte[]> transformedClasses)StringtoString()Class<?>visibleDefineClass(String name, byte[] b, int off, int len)-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
META_INF_SERVICES
protected static final String META_INF_SERVICES
- See Also:
- Constant Field Values
-
JAVA
protected static final String JAVA
- See Also:
- Constant Field Values
-
-
Method Detail
-
getElements
public static List<ClassPathElement> getElements(String resourceName, boolean onlyFromCurrentClassLoader)
-
getAllElements
public List<ClassPathElement> getAllElements(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.
-
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 instancepath/to/my-resources.propertiesfor a properties file ormy/package/MyClass.classfor a class.
-
builder
public static QuarkusClassLoader.Builder builder(String name, ClassLoader parent, boolean parentFirst)
-
isParentFirst
public boolean isParentFirst(String name)
Returns true if the supplied class is a class that would be loaded parent-first
-
reset
public void reset(Map<String,byte[]> generatedResources, Map<String,byte[]> transformedClasses)
-
getResources
public Enumeration<URL> getResources(String unsanitisedName) throws IOException
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getResources
public Enumeration<URL> getResources(String unsanitisedName, boolean parentAlreadyFoundResources) throws IOException
- Throws:
IOException
-
getResource
public URL getResource(String unsanitisedName)
- Overrides:
getResourcein classClassLoader
-
getResourceAsStream
public InputStream getResourceAsStream(String unsanitisedName)
- Overrides:
getResourceAsStreamin classClassLoader
-
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:
findClassin classClassLoader- Parameters:
moduleName-name-- Returns:
-
findResource
protected URL findResource(String name)
- Overrides:
findResourcein classClassLoader
-
findResources
protected Enumeration<URL> findResources(String name) throws IOException
- Overrides:
findResourcesin classClassLoader- Throws:
IOException
-
loadClass
public Class<?> loadClass(String name) throws ClassNotFoundException
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
loadClass
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
getElementsWithResource
public List<ClassPathElement> getElementsWithResource(String name)
-
getElementsWithResource
public List<ClassPathElement> getElementsWithResource(String name, boolean localOnly)
-
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed()
-
parent
public ClassLoader parent()
-
getName
public String getName()
- Overrides:
getNamein classClassLoader
-
-