org.apache.tools.ant
public class AntClassLoader extends ClassLoader implements SubBuildListener
Note that this classloader has a feature to allow loading in reverse order and for "isolation". Due to the fact that a number of methods in java.lang.ClassLoader are final (at least in java 1.4 getResources) this means that the class has to fake the given parent.
Constructor Summary | |
---|---|
AntClassLoader(ClassLoader parent, Project project, Path classpath)
Create an Ant ClassLoader for a given project, with
a parent classloader and an initial classpath. | |
AntClassLoader()
Create an Ant Class Loader | |
AntClassLoader(Project project, Path classpath)
Creates a classloader for the given project using the classpath given.
| |
AntClassLoader(ClassLoader parent, Project project, Path classpath, boolean parentFirst)
Creates a classloader for the given project using the classpath given.
| |
AntClassLoader(Project project, Path classpath, boolean parentFirst)
Creates a classloader for the given project using the classpath given.
| |
AntClassLoader(ClassLoader parent, boolean parentFirst)
Creates an empty class loader. |
Method Summary | |
---|---|
void | addJavaLibraries()
add any libraries that come with different java versions
here |
void | addLoaderPackageRoot(String packageRoot)
Adds a package root to the list of packages which must be loaded using
this loader.
|
void | addPathComponent(File file)
Add a path component.
|
void | addPathElement(String pathElement)
Adds an element to the classpath to be searched.
|
protected void | addPathFile(File pathComponent)
Add a file to the path.
|
void | addSystemPackageRoot(String packageRoot)
Adds a package root to the list of packages which must be loaded on the
parent loader.
|
void | buildFinished(BuildEvent event)
Cleans up any resources held by this classloader at the end
of a build.
|
void | buildStarted(BuildEvent event)
Empty implementation to satisfy the BuildListener interface.
|
void | cleanup()
Cleans up any resources held by this classloader. |
protected Class | defineClassFromData(File container, byte[] classData, String classname)
Define a class given its bytes
|
protected void | definePackage(File container, String className)
Define the package information associated with a class.
|
protected void | definePackage(File container, String packageName, Manifest manifest)
Define the package information when the class comes from a
jar with a manifest
|
Class | findClass(String name)
Searches for and load a class on the classpath of this class loader.
|
protected Enumeration | findResources(String name)
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.
|
String | getClasspath()
Returns the classpath this classloader will consult.
|
URL | getResource(String name)
Finds the resource with the given name. |
InputStream | getResourceAsStream(String name)
Returns a stream to read the requested resource name.
|
protected URL | getResourceURL(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 void | initializeClass(Class theClass)
Forces initialization of a class in a JDK 1.1 compatible, albeit hacky
way.
|
protected boolean | isInPath(File component)
Indicate if the given file is in this loader's path
|
protected Class | loadClass(String classname, boolean resolve)
Loads a class with this class loader.
|
protected void | log(String message, int priority)
Logs a message through the project object if one has been provided.
|
void | messageLogged(BuildEvent event)
Empty implementation to satisfy the BuildListener interface.
|
void | resetThreadContextLoader()
Resets the current thread's context loader to its original value. |
void | setClassPath(Path classpath)
Set the classpath to search for classes to load. |
void | setIsolated(boolean isolated)
Sets whether this classloader should run in isolated mode. |
void | setParent(ClassLoader parent)
Set the parent for this class loader. |
void | setParentFirst(boolean parentFirst)
Control whether class lookup is delegated to the parent loader first
or after this loader. |
void | setProject(Project project)
Set the project associated with this class loader
|
void | setThreadContextLoader()
Sets the current thread's context loader to this classloader, storing
the current loader value for later resetting. |
void | subBuildFinished(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.
|
void | subBuildStarted(BuildEvent event)
Empty implementation to satisfy the BuildListener interface.
|
void | targetFinished(BuildEvent event)
Empty implementation to satisfy the BuildListener interface.
|
void | targetStarted(BuildEvent event)
Empty implementation to satisfy the BuildListener interface.
|
void | taskFinished(BuildEvent event)
Empty implementation to satisfy the BuildListener interface.
|
void | taskStarted(BuildEvent event)
Empty implementation to satisfy the BuildListener interface.
|
String | toString()
Returns a String representing this loader. |
Parameters: parent the parent for this classloader. project The project to which this classloader is to belong. classpath The classpath to use to load classes.
Since: Ant 1.7.
Parameters: project The project to which this classloader is to belong.
Must not be null
. classpath The classpath to use to load the classes. This
is combined with the system classpath in a manner
determined by the value of ${build.sysclasspath}.
May be null
, in which case no path
elements are set up to start with.
Parameters: parent The parent classloader to which unsatisfied loading
attempts are delegated. May be null
,
in which case the classloader which loaded this
class is used as the parent. project The project to which this classloader is to belong.
Must not be null
. classpath the classpath to use to load the classes.
May be null
, in which case no path
elements are set up to start with. parentFirst If true
, indicates that the parent
classloader should be consulted before trying to
load the a class through this loader.
Parameters: project The project to which this classloader is to belong.
Must not be null
. classpath The classpath to use to load the classes. May be
null
, in which case no path
elements are set up to start with. parentFirst If true
, indicates that the parent
classloader should be consulted before trying to
load the a class through this loader.
Parameters: parent The parent classloader to which unsatisfied loading
attempts are delegated. May be null
,
in which case the classloader which loaded this
class is used as the parent. parentFirst If true
, indicates that the parent
classloader should be consulted before trying to
load the a class through this loader.
Parameters: packageRoot The root of all packages to be included.
Should not be null
.
Parameters: file the jar file or directory to add.
Parameters: pathElement The path element to add. Must not be
null
.
Throws: BuildException if the given path element cannot be resolved against the project.
Parameters: pathComponent the file which is to be added to the path for this class loader
Throws: IOException if data needed from the file cannot be read.
Parameters: packageRoot The root of all packages to be included.
Should not be null
.
Parameters: event the buildFinished event
Parameters: event the buildStarted event
Parameters: container the container from which the class data has been read may be a directory or a jar/zip file. classData the bytecode data for the class classname the name of the class
Returns: the Class instance created from the given data
Throws: IOException if the class data cannot be read.
Parameters: container the file containing the class definition. className the class name of for which the package information is to be determined.
Throws: IOException if the package information cannot be read from the container.
Parameters: container the jar file containing the manifest packageName the name of the package being defined. manifest the jar's manifest
Parameters: name The name of the class to be loaded. Must not be
null
.
Returns: the required Class object
Throws: ClassNotFoundException if the requested class does not exist on this loader's classpath.
Parameters: name The resource name to search for.
Must not be null
.
Returns: an enumeration of URLs for the resources
Throws: IOException if I/O errors occurs (can't happen)
Parameters: classname The name of the class to be loaded.
Must not be null
.
Returns: the required Class object
Throws: ClassNotFoundException if the requested class does not exist on this loader's classpath.
Parameters: classname The name of the class to be loaded.
Must not be null
.
Returns: the required Class object
Throws: ClassNotFoundException if the requested class does not exist on this loader's classpath.
Returns: the classpath used for this classloader, with elements separated by the path separator for the system.
Parameters: name The name of the resource for which a stream is required.
Must not be null
.
Returns: a URL for reading the resource, or null
if the
resource could not be found or the caller doesn't have
adequate privileges to get the resource.
Parameters: name The name of the resource for which a stream is required.
Must not be null
.
Returns: a stream to the required resource or null
if the
resource cannot be found on the loader's classpath.
Parameters: file The file (directory or jar) in which to search for
the resource. Must not be null
. resourceName The name of the resource for which a stream
is required. Must not be null
.
Returns: a stream to the required resource or null
if the
resource cannot be found in the given file object.
Deprecated: since 1.6.x. Use Class.forName with initialize=true instead.
Forces initialization of a class in a JDK 1.1 compatible, albeit hacky way.Parameters: theClass The class to initialize.
Must not be null
.
Parameters: component the file which is to be checked
Returns: true if the file is in the class path
Parameters: classname The name of the class to be loaded.
Must not be null
. resolve true
if 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.
Parameters: message The message to log.
Should not be null
.
priority The logging priority of the message.
Parameters: event the messageLogged event
Parameters: classpath the search classpath consisting of directories and jar/zip files.
Parameters: isolated Whether or not this classloader should run in isolated mode.
Parameters: parent the parent class loader.
Parameters: parentFirst if true, delegate initial class search to the parent classloader.
Parameters: project the project instance
Parameters: event the buildFinished event
Since: Ant 1.6.2
Parameters: event the buildStarted event
Since: Ant 1.6.2
Parameters: event the targetFinished event
Parameters: event the targetStarted event
Parameters: event the taskFinished event
Parameters: event the taskStarted event
String
representing this loader.Returns: the path that this classloader has.