log("Referenced object is not an AntClassLoader",
Project.MSG_ERR);
return;
}
AntClassLoader acl = (AntClassLoader) obj;
boolean existingLoader = acl != null;
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 = AntClassLoader.newAntClassLoader((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 (existingLoader && classpath != null) {
String[] list = classpath.list();
for (int i = 0; i < list.length; i++) {
File f = new File(list[i]);
if (f.exists()) {
log("Adding to class loader " + acl + " " + f.getAbsolutePath(),
Project.MSG_DEBUG);
acl.addPathElement(f.getAbsolutePath());
}
}
}
// TODO add exceptions