Methods Summary |
---|
public org.apache.tools.ant.types.Path | createClasspath()Create a classpath.
if (this.classpath == null) {
this.classpath = new Path(null);
}
return this.classpath.createPath();
|
public void | execute()do the classloader manipulation.
try {
// Gump friendly - don't mess with the core loader if only classpath
if ("only".equals(getProject().getProperty("build.sysclasspath"))
&& (name == null || SYSTEM_LOADER_REF.equals(name))) {
log("Changing the system loader is disabled "
+ "by build.sysclasspath=only", Project.MSG_WARN);
return;
}
String loaderName = (name == null) ? SYSTEM_LOADER_REF : name;
Object obj = getProject().getReference(loaderName);
if (reset) {
// Are any other references held ? Can we 'close' the loader
// so it removes the locks on jars ?
obj = null; // a new one will be created.
}
// XXX maybe use reflection to addPathElement (other patterns ?)
if (obj != null && !(obj instanceof AntClassLoader)) {
log("Referenced object is not an AntClassLoader",
Project.MSG_ERR);
return;
}
AntClassLoader acl = (AntClassLoader) obj;
if (acl == null) {
// Construct a new class loader
Object parent = null;
if (parentName != null) {
parent = getProject().getReference(parentName);
if (!(parent instanceof ClassLoader)) {
parent = null;
}
}
// TODO: allow user to request the system or no parent
if (parent == null) {
parent = this.getClass().getClassLoader();
}
if (name == null) {
// The core loader must be reverse
//reverse=true;
}
getProject().log("Setting parent loader " + name + " "
+ parent + " " + parentFirst, Project.MSG_DEBUG);
// The param is "parentFirst"
acl = new AntClassLoader((ClassLoader) parent,
getProject(), classpath, parentFirst);
getProject().addReference(loaderName, acl);
if (name == null) {
// This allows the core loader to load optional tasks
// without delegating
acl.addLoaderPackageRoot("org.apache.tools.ant.taskdefs.optional");
getProject().setCoreLoader(acl);
}
}
if (classpath != null) {
String[] list = classpath.list();
for (int i = 0; i < list.length; i++) {
File f = new File(list[i]);
if (f.exists()) {
acl.addPathElement(f.getAbsolutePath());
log("Adding to class loader " + acl + " " + f.getAbsolutePath(),
Project.MSG_DEBUG);
}
}
}
// XXX add exceptions
} catch (Exception ex) {
ex.printStackTrace();
}
|
public void | setClasspath(org.apache.tools.ant.types.Path classpath)Set the classpath to be used when searching for component being defined
if (this.classpath == null) {
this.classpath = classpath;
} else {
this.classpath.append(classpath);
}
|
public void | setClasspathRef(org.apache.tools.ant.types.Reference pathRef)Specify which path will be used. If the loader already exists
and is an AntClassLoader (or any other loader we can extend),
the path will be added to the loader.
classpath = (Path) pathRef.getReferencedObject(getProject());
|
public void | setName(java.lang.String name)Name of the loader. If none, the default loader will be modified
this.name = name;
|
public void | setParentFirst(boolean b)Set reverse attribute.
this.parentFirst = b;
|
public void | setParentName(java.lang.String name)Set the name of the parent.
this.parentName = name;
|
public void | setReset(boolean b)Reset the classloader, if it already exists. A new loader will
be created and all the references to the old one will be removed.
(it is not possible to remove paths from a loader). The new
path will be used.
this.reset = b;
|
public void | setReverse(boolean b)Set reverse attribute.
this.parentFirst = !b;
|