Class SplitClassLoader
java.lang.Object
java.lang.ClassLoader
org.apache.tools.ant.AntClassLoader
org.apache.tools.ant.util.SplitClassLoader
- All Implemented Interfaces:
Closeable, AutoCloseable, EventListener, BuildListener, SubBuildListener
Specialized classloader for tasks that need finer grained control
over which classes are to be loaded via Ant's classloader and which
should not even if they are available.
-
Constructor Summary
ConstructorsConstructorDescriptionSplitClassLoader(ClassLoader parent, Path path, Project project, String[] splitClasses) -
Method Summary
Methods inherited from class AntClassLoader
addJavaLibraries, addLoaderPackageRoot, addPathComponent, addPathElement, addPathFile, addSystemPackageRoot, buildFinished, buildStarted, cleanup, close, defineClassFromData, definePackage, definePackage, findClass, findResource, findResources, findResources, forceLoadClass, forceLoadSystemClass, getClasspath, getConfiguredParent, getNamedResources, getResource, getResourceAsStream, getResources, getResourceURL, initializeClass, isInPath, log, messageLogged, newAntClassLoader, resetThreadContextLoader, setClassPath, setIsolated, setParent, setParentFirst, setProject, setThreadContextLoader, subBuildFinished, subBuildStarted, targetFinished, targetStarted, taskFinished, taskStarted, toStringModifier and TypeMethodDescriptionvoidadd any libraries that come with different java versions herevoidaddLoaderPackageRoot(String packageRoot) Adds a package root to the list of packages which must be loaded using this loader.voidaddPathComponent(File file) Add a path component.voidaddPathElement(String pathElement) Adds an element to the classpath to be searched.protected voidaddPathFile(File pathComponent) Add a file to the path.voidaddSystemPackageRoot(String packageRoot) Adds a package root to the list of packages which must be loaded on the parent loader.voidbuildFinished(BuildEvent event) Cleans up any resources held by this classloader at the end of a build.voidbuildStarted(BuildEvent event) Empty implementation to satisfy the BuildListener interface.voidcleanup()Cleans up any resources held by this classloader.voidclose()protected Class<?> defineClassFromData(File container, byte[] classData, String classname) Define a class given its bytesprotected voiddefinePackage(File container, String className) Define the package information associated with a class.protected voiddefinePackage(File container, String packageName, Manifest manifest) Define the package information when the class comes from a jar with a manifestClass<?> Searches for and load a class on the classpath of this class loader.protected URLfindResource(String name) Finds the resource with the given name.protected Enumeration<URL> findResources(String name) Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath.protected Enumeration<URL> findResources(String name, boolean skipParent) Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath.Class<?> forceLoadClass(String classname) Loads a class through this class loader even if that class is available on the parent classpath.Class<?> forceLoadSystemClass(String classname) Loads a class through this class loader but defer to the parent class loader.Returns the classpath this classloader will consult.Gets the parent as has been specified in the constructor or via setParent.getNamedResources(String name) Finds all the resources with the given name.getResource(String name) Finds the resource with the given name.getResourceAsStream(String name) Returns a stream to read the requested resource name.getResources(String name) protected URLgetResourceURL(File file, String resourceName) Returns the URL of a given resource in the given file which may either be a directory or a zip file.static voidinitializeClass(Class<?> theClass) Deprecated.since 1.6.x.protected booleanIndicate if the given file is in this loader's pathprotected voidLogs a message through the project object if one has been provided.voidmessageLogged(BuildEvent event) Empty implementation to satisfy the BuildListener interface.static AntClassLoadernewAntClassLoader(ClassLoader parent, Project project, Path path, boolean parentFirst) Factory methodvoidResets the current thread's context loader to its original value.voidsetClassPath(Path classpath) Set the classpath to search for classes to load.voidsetIsolated(boolean isolated) Sets whether this classloader should run in isolated mode.voidsetParent(ClassLoader parent) Set the parent for this class loader.voidsetParentFirst(boolean parentFirst) Control whether class lookup is delegated to the parent loader first or after this loader.voidsetProject(Project project) Set the project associated with this class loadervoidSets the current thread's context loader to this classloader, storing the current loader value for later resetting.voidsubBuildFinished(BuildEvent event) Cleans up any resources held by this classloader at the end of a subbuild if it has been created for the subbuild's project instance.voidsubBuildStarted(BuildEvent event) Empty implementation to satisfy the BuildListener interface.voidtargetFinished(BuildEvent event) Empty implementation to satisfy the BuildListener interface.voidtargetStarted(BuildEvent event) Empty implementation to satisfy the BuildListener interface.voidtaskFinished(BuildEvent event) Empty implementation to satisfy the BuildListener interface.voidtaskStarted(BuildEvent event) Empty implementation to satisfy the BuildListener interface.toString()Returns aStringrepresenting this loader.Methods inherited from class ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
SplitClassLoader
- Parameters:
parent- ClassLoaderpath- Pathproject- ProjectsplitClasses- classes contained herein will not be loaded via Ant's classloader
-
-
Method Details
-
loadClass
Description copied from class:AntClassLoaderLoads a class with this class loader. This class attempts to load the class in an order determined by whether or not the class matches the system/loader package lists, with the loader package list taking priority. If the classloader is in isolated mode, failure to load the class in this loader will result in a ClassNotFoundException.- Overrides:
loadClassin classAntClassLoader- Parameters:
classname- The name of the class to be loaded. Must not benull.resolve-trueif all classes upon which this class depends are to be loaded.- Returns:
- the required Class object
- Throws:
ClassNotFoundException- if the requested class does not exist on the system classpath (when not in isolated mode) or this loader's classpath.
-