AntClassLoader (Apache Ant API)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.ClassLoader | +--org.apache.tools.ant.AntClassLoader
Used to load classes within ant with a different claspath from that used to start ant. Note that it is possible to force a class into this loader even when that class is on the system classpath by using the forceLoadClass method. Any subsequent classes loaded by that class will then use this loader rather than the system class loader.
Constructor Summary | |
AntClassLoader(java.lang.ClassLoader parent,
boolean parentFirst)
Creates an empty class loader. |
|
AntClassLoader(java.lang.ClassLoader parent,
Project project,
Path classpath,
boolean parentFirst)
Creates a classloader for the given project using the classpath given. |
|
AntClassLoader(Project project,
Path classpath)
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. |
Method Summary | |
void |
addLoaderPackageRoot(java.lang.String packageRoot)
Adds a package root to the list of packages which must be loaded using this loader. |
void |
addPathElement(java.lang.String pathElement)
Adds an element to the classpath to be searched. |
void |
addSystemPackageRoot(java.lang.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. |
java.lang.Class |
findClass(java.lang.String name)
Searches for and load a class on the classpath of this class loader. |
protected java.util.Enumeration |
findResources(java.lang.String name)
Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath. |
java.lang.Class |
forceLoadClass(java.lang.String classname)
Loads a class through this class loader even if that class is available on the parent classpath. |
java.lang.Class |
forceLoadSystemClass(java.lang.String classname)
Loads a class through this class loader but defer to the parent class loader. |
java.lang.String |
getClasspath()
Returns the classpath this classloader will consult. |
java.net.URL |
getResource(java.lang.String name)
Finds the resource with the given name. |
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Returns a stream to read the requested resource name. |
static void |
initializeClass(java.lang.Class theClass)
Forces initialization of a class in a JDK 1.1 compatible, albeit hacky way. |
protected java.lang.Class |
loadClass(java.lang.String classname,
boolean resolve)
Loads a class with this class loader. |
protected void |
log(java.lang.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 |
setIsolated(boolean isolated)
Sets whether this classloader should run in isolated mode. |
void |
setThreadContextLoader()
Sets the current thread's context loader to this classloader, storing the current loader value for later resetting. |
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. |
Methods inherited from class java.lang.ClassLoader |
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AntClassLoader(Project project, Path classpath)
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.public AntClassLoader(java.lang.ClassLoader parent, Project project, Path classpath, boolean parentFirst)
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.public AntClassLoader(Project project, Path classpath, boolean parentFirst)
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.public AntClassLoader(java.lang.ClassLoader parent, boolean parentFirst)
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.Method Detail |
protected void log(java.lang.String message, int priority)
message
- The message to log.
Should not be null
.priority
- The logging priority of the message.public void setThreadContextLoader()
public void resetThreadContextLoader()
public void addPathElement(java.lang.String pathElement) throws BuildException
pathElement
- The path element to add. Must not be
null
.
BuildException
- if the given path element cannot be resolved
against the project.public java.lang.String getClasspath()
public void setIsolated(boolean isolated)
isolated
- Whether or not this classloader should run in
isolated mode.public static void initializeClass(java.lang.Class theClass)
theClass
- The class to initialize.
Must not be null
.public void addSystemPackageRoot(java.lang.String packageRoot)
packageRoot
- The root of all packages to be included.
Should not be null
.public void addLoaderPackageRoot(java.lang.String packageRoot)
packageRoot
- The root of all packages to be included.
Should not be null
.public java.lang.Class forceLoadClass(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- The name of the class to be loaded.
Must not be null
.
java.lang.ClassNotFoundException
- if the requested class does not exist
on this loader's classpath.public java.lang.Class forceLoadSystemClass(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- The name of the class to be loaded.
Must not be null
.
java.lang.ClassNotFoundException
- if the requested class does not exist
on this loader's classpath.public java.io.InputStream getResourceAsStream(java.lang.String name)
getResourceAsStream
in class java.lang.ClassLoader
name
- The name of the resource for which a stream is required.
Must not be null
.
null
if the
resource cannot be found on the loader's classpath.public java.net.URL getResource(java.lang.String name)
getResource
in class java.lang.ClassLoader
name
- The name of the resource for which a stream is required.
Must not be null
.
null
if the
resource could not be found or the caller doesn't have
adequate privileges to get the resource.protected java.util.Enumeration findResources(java.lang.String name) throws java.io.IOException
findResources
in class java.lang.ClassLoader
name
- The resource name to search for.
Must not be null
.
java.io.IOException
- if I/O errors occurs (can't happen)protected java.lang.Class loadClass(java.lang.String classname, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
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.
java.lang.ClassNotFoundException
- if the requested class does not exist
on the system classpath (when not in isolated mode) or this loader's
classpath.public java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
findClass
in class java.lang.ClassLoader
name
- The name of the class to be loaded. Must not be
null
.
java.lang.ClassNotFoundException
- if the requested class does not exist
on this loader's classpath.public void cleanup()
public void buildStarted(BuildEvent event)
buildStarted
in interface BuildListener
event
- the buildStarted eventpublic void buildFinished(BuildEvent event)
buildFinished
in interface BuildListener
event
- the buildFinished eventBuildEvent.getException()
public void targetStarted(BuildEvent event)
targetStarted
in interface BuildListener
event
- the targetStarted eventBuildEvent.getTarget()
public void targetFinished(BuildEvent event)
targetFinished
in interface BuildListener
event
- the targetFinished eventBuildEvent.getException()
public void taskStarted(BuildEvent event)
taskStarted
in interface BuildListener
event
- the taskStarted eventBuildEvent.getTask()
public void taskFinished(BuildEvent event)
taskFinished
in interface BuildListener
event
- the taskFinished eventBuildEvent.getException()
public void messageLogged(BuildEvent event)
messageLogged
in interface BuildListener
event
- the messageLogged eventBuildEvent.getMessage()
,
BuildEvent.getPriority()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |