diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java index c842274e7..77a729290 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Java.java +++ b/src/main/org/apache/tools/ant/taskdefs/Java.java @@ -61,6 +61,7 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; import java.io.File; import java.io.IOException; @@ -79,6 +80,7 @@ public class Java extends Task { private boolean fork = false; private File dir = null; private boolean failOnError = false; + private Vector classpathReferences = new Vector(); /** * Do the execution. @@ -137,6 +139,22 @@ public class Java extends Task { return cmdl.createClasspath(project); } + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void addClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + /** * Set the class name. */ @@ -218,7 +236,10 @@ public class Java extends Task { private void run(CommandlineJava command) throws BuildException { ExecuteJava exe = new ExecuteJava(); exe.setJavaCommand(command.getJavaCommand()); - exe.setClasspath(command.getClasspath()); + Path p = new Path(project); + p.append(command.getClasspath()); + addReferencesToPath(classpathReferences, p); + exe.setClasspath(p); exe.execute(project); } @@ -252,10 +273,33 @@ public class Java extends Task { for (int i=0; i 0) { + Path p = cmdj.createClasspath(project); + if (cmdl.getClasspath() != null) { + p.append(cmdl.getClasspath()); + } + addReferencesToPath(classpathReferences, p); } run(cmdj); } + /** + * Appends the referenced Path instances to the other path. + * + * @param v Vector of Reference objects referring to Path objects. + * @param p Path to append to. + */ + private void addReferencesToPath(Vector v, Path p) { + for (int i=0; i element. + */ + public void addClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + /** * Sets the bootclasspath that will be used to compile the classes * against. @@ -185,6 +203,22 @@ public class Javac extends MatchingTask { return bootclasspath; } + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void addBootClasspathRef(Reference r) { + bootClasspathReferences.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setBootClasspathRef(Reference r) { + bootClasspathReferences.addElement(r); + } + /** * Sets the extension directories that will be used during the * compilation. @@ -355,6 +389,7 @@ public class Javac extends MatchingTask { if (compileClasspath != null) { addExistingToClasspath(classpath,compileClasspath); } + addReferencesToPath(classpathReferences, classpath); // add the system classpath @@ -505,7 +540,8 @@ public class Javac extends MatchingTask { if (optimize) { cmd.createArgument().setValue("-O"); } - if (bootclasspath != null) { + if (bootclasspath != null || bootClasspathReferences.size() > 0) { + addReferencesToPath(bootClasspathReferences, createBootclasspath()); cmd.createArgument().setValue("-bootclasspath"); cmd.createArgument().setPath(bootclasspath); } @@ -559,7 +595,8 @@ public class Javac extends MatchingTask { // Jikes doesn't support bootclasspath dir (-bootclasspath) // so we'll emulate it for compatibility and convenience. - if (bootclasspath != null) { + if (bootclasspath != null || bootClasspathReferences.size() > 0) { + addReferencesToPath(bootClasspathReferences, createBootclasspath()); classpath.append(bootclasspath); } @@ -713,7 +750,7 @@ public class Javac extends MatchingTask { /** * Emulation of extdirs feature in java >= 1.2. - * This method adds all file in the given + * This method adds all files in the given * directories (but not in sub-directories!) to the classpath, * so that you don't have to specify them all one by one. * @param classpath - Path to append files to @@ -740,5 +777,25 @@ public class Javac extends MatchingTask { classpath.addFileset(fs); } } + + /** + * Appends the referenced Path instances to the other path. + * + * @param v Vector of Reference objects referring to Path objects. + * @param p Path to append to. + */ + private void addReferencesToPath(Vector v, Path p) { + for (int i=0; i element. + */ + public void addPathRef(Reference r) { + pathRefs.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setPathRef(Reference r) { + pathRefs.addElement(r); + } + public DocletParam createParam() { DocletParam param = new DocletParam(); params.addElement(param); @@ -196,7 +215,9 @@ public class Javadoc extends Task { private String packageList = null; private Vector links = new Vector(2); private Vector groups = new Vector(2); - + private Vector classpathReferences = new Vector(); + private Vector bootClasspathReferences = new Vector(); + private Vector sourcepathReferences = new Vector(); public void setMaxmemory(String max){ if(javadoc1){ @@ -223,6 +244,22 @@ public class Javadoc extends Task { } return sourcePath; } + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void addSourcepathRef(Reference r) { + sourcepathReferences.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setSourcepathRef(Reference r) { + sourcepathReferences.addElement(r); + } + public void setDestdir(File dir) { cmd.createArgument().setValue("-d"); cmd.createArgument().setFile(dir); @@ -266,6 +303,13 @@ public class Javadoc extends Task { doclet.setPath(src); } + public void setDocletPathRef(Reference r) { + if (doclet == null) { + doclet = new DocletInfo(); + } + doclet.setPathRef(r); + } + public DocletInfo createDoclet() { doclet = new DocletInfo(); return doclet; @@ -287,6 +331,22 @@ public class Javadoc extends Task { } return classpath; } + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void addClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + public void setBootclasspath(Path src) { if (bootclasspath == null) { bootclasspath = src; @@ -300,6 +360,22 @@ public class Javadoc extends Task { } return bootclasspath; } + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void addBootClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setBootClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + public void setExtdirs(String src) { if (!javadoc1) { cmd.createArgument().setValue("-extdirs"); @@ -522,14 +598,14 @@ public class Javadoc extends Task { if (classpath == null) classpath = Path.systemClasspath; + addReferencesToPath(classpathReferences, classpath); + addReferencesToPath(sourcepathReferences, sourcePath); - if ( (!javadoc1) || (sourcePath == null) ) { + if (!javadoc1) { cmd.createArgument().setValue("-classpath"); cmd.createArgument().setPath(classpath); - if (sourcePath != null) { - cmd.createArgument().setValue("-sourcepath"); - cmd.createArgument().setPath(sourcePath); - } + cmd.createArgument().setValue("-sourcepath"); + cmd.createArgument().setPath(sourcePath); } else { cmd.createArgument().setValue("-classpath"); cmd.createArgument().setValue(sourcePath.toString() + @@ -570,7 +646,9 @@ public class Javadoc extends Task { } } } - if (bootclasspath != null) { + if (bootclasspath != null || bootClasspathReferences.size() > 0) { + addReferencesToPath(bootClasspathReferences, + createBootclasspath()); cmd.createArgument().setValue("-bootclasspath"); cmd.createArgument().setPath(bootclasspath); } @@ -694,6 +772,25 @@ public class Javadoc extends Task { } } + /** + * Appends the referenced Path instances to the other path. + * + * @param v Vector of Reference objects referring to Path objects. + * @param p Path to append to. + */ + private void addReferencesToPath(Vector v, Path p) { + for (int i=0; i element. + */ + public void addClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + + /** + * Adds a reference to a CLASSPATH defined elsewhere - nested + * element. + */ + public void setClasspathRef(Reference r) { + classpathReferences.addElement(r); + } + /** * Indicates that the classes found by the directory match should be * checked to see if they implement java.rmi.Remote. - * This defaults to false if not set. - */ + * This defaults to false if not set. */ public void setVerify(String verify) { this.verify = Project.toBoolean(verify); } @@ -170,7 +187,19 @@ public class Rmic extends MatchingTask { if (null != sourceBase) { sourceBaseFile = project.resolveFile(sourceBase); } - String classpath = getCompileClasspath(baseDir); + Path classpath = getCompileClasspath(baseDir); + + for (int i=0; i