Browse Source

Loading tasks from a ClassLoader other than the default one now works

on JDK 1.1 as well.

Added org.apache.tools.ant to the list of packages that need to be
loaded via the system class loader as the loaded class wouldn't be an
instance of Task (loaded by default loader) otherwise.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268038 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
dddcf551a9
3 changed files with 18 additions and 7 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/AntClassLoader.java
  2. +3
    -3
      src/main/org/apache/tools/ant/Project.java
  3. +13
    -2
      src/main/org/apache/tools/ant/taskdefs/Taskdef.java

+ 2
- 2
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -115,7 +115,7 @@ public class AntClassLoader extends ClassLoader {
/**
* Create a classloader for the given project using the classpath given.
*
* @param project the project to ehich this classloader is to belong.
* @param project the project to which this classloader is to belong.
* @param classpath the classpath to use to load the classes.
*/
public AntClassLoader(Project project, Path classpath, boolean systemFirst) {
@@ -129,7 +129,7 @@ public class AntClassLoader extends ClassLoader {
*
* All subpackages are also included.
*
* @param packageRoot the root of akll packages to be included.
* @param packageRoot the root of all packages to be included.
*/
public void addSystemPackageRoot(String packageRoot) {
systemPackages.addElement(packageRoot + ".");


+ 3
- 3
src/main/org/apache/tools/ant/Project.java View File

@@ -452,10 +452,10 @@ public class Project {
String msg = " +Task: " + taskType;
log (msg, MSG_DEBUG);
return task;
} catch (Exception e) {
} catch (Throwable t) {
String msg = "Could not create task of type: "
+ taskType + " due to " + e;
throw new BuildException(msg);
+ taskType + " due to " + t;
throw new BuildException(msg, t);
}
}



+ 13
- 2
src/main/org/apache/tools/ant/taskdefs/Taskdef.java View File

@@ -95,7 +95,14 @@ public class Taskdef extends Task {
try {
ClassLoader loader = null;
if (classpath != null) {
loader = new AntClassLoader(project, classpath, false);
AntClassLoader al = new AntClassLoader(project, classpath,
false);
al.addSystemPackageRoot("org.apache.tools.ant");
if (project.getJavaVersion().startsWith("1.1")) {
// JDK > 1.1 adds these by default
al.addSystemPackageRoot("java");
}
loader = al;
} else {
loader = this.getClass().getClassLoader();
}
@@ -110,7 +117,11 @@ public class Taskdef extends Task {
} catch (ClassNotFoundException cnfe) {
String msg = "taskdef class " + value +
" cannot be found";
throw new BuildException(msg, location);
throw new BuildException(msg, cnfe, location);
} catch (NoClassDefFoundError ncdfe) {
String msg = "taskdef class " + value +
" cannot be found";
throw new BuildException(msg, ncdfe, location);
}
}


Loading…
Cancel
Save