bodewig 2003/05/27 01:49:42
Modified: . WHATSNEW docs/manual/CoreTasks java.html docs/manual/OptionalTasks junit.html src/main/org/apache/tools/ant/taskdefs Java.java src/main/org/apache/tools/ant/taskdefs/optional/junit JUnitTask.java src/main/org/apache/tools/ant/types CommandlineJava.java Log: Add a nested <bootclasspath> to <java>. Submitted by: W. Craig Trader <craig dot trader at lmco dot com> Do the same for <junit>. Revision Changes Path 1.428 +3 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.427 retrieving revision 1.428 diff -u -r1.427 -r1.428 --- WHATSNEW 25 May 2003 11:40:54 -0000 1.427 +++ WHATSNEW 27 May 2003 08:49:41 -0000 1.428 @@ -375,6 +375,9 @@ * new selector <type/> allowing to select only files or only directories. Bugzilla Report 20222. +* <java> and <junit> now support a nested <bootclasspath> element that + will be ignored if not forking a new VM. + Changes from Ant 1.5.2 to Ant 1.5.3 =================================== 1.19 +10 -0 ant/docs/manual/CoreTasks/java.html Index: java.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/java.html,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- java.html 12 May 2003 15:19:18 -0000 1.18 +++ java.html 27 May 2003 08:49:41 -0000 1.19 @@ -189,6 +189,16 @@ <p><code>Java</code>'s <i>classpath</i> attribute is a <a href="../using.html#path">PATH like structure</a> and can also be set via a nested <i>classpath</i> element.</p> + +<h4>bootclasspath</h4> + +<p>The location of bootstrap class files can be specified using this +<a href="../using.html#path">PATH like structure</a> - will be ignored +if <i>fork</i> is not <code>true</code> or the target VM doesn't +support it (i.e. Java 1.1).</p> + +<p><em>since Ant 1.6</em>.</p> + <h4>env</h4> <p>It is possible to specify environment variables to pass to the forked VM via nested <i>env</i> elements. See the description in the 1.26 +9 -0 ant/docs/manual/OptionalTasks/junit.html Index: junit.html =================================================================== RCS file: /home/cvs/ant/docs/manual/OptionalTasks/junit.html,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- junit.html 12 May 2003 15:19:18 -0000 1.25 +++ junit.html 27 May 2003 08:49:41 -0000 1.26 @@ -228,6 +228,15 @@ <p>Settings will be ignored if <code>fork</code> is disabled.</p> +<h4>bootclasspath</h4> + +<p>The location of bootstrap class files can be specified using this +<a href="../using.html#path">PATH like structure</a> - will be ignored +if <i>fork</i> is not <code>true</code> or the target VM doesn't +support it (i.e. Java 1.1).</p> + +<p><em>since Ant 1.6</em>.</p> + <h4>formatter</h4> <p>The results of the tests can be printed in different 1.60 +13 -0 ant/src/main/org/apache/tools/ant/taskdefs/Java.java Index: Java.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v retrieving revision 1.59 retrieving revision 1.60 diff -u -r1.59 -r1.60 --- Java.java 12 May 2003 14:00:09 -0000 1.59 +++ Java.java 27 May 2003 08:49:41 -0000 1.60 @@ -149,6 +149,11 @@ + "JVM is used.", Project.MSG_WARN); } + if (cmdl.getBootclasspath() != null) { + log("bootclasspath ignored when same JVM is used.", + Project.MSG_WARN); + } + log("Running in same VM " + cmdl.describeJavaCommand(), Project.MSG_VERBOSE); } @@ -195,6 +200,14 @@ */ public Path createClasspath() { return cmdl.createClasspath(getProject()).createPath(); + } + + /** + * Adds a path to the bootclasspath. + * @since Ant 1.6 + */ + public Path createBootclasspath() { + return cmdl.createBootclasspath(getProject()).createPath(); } /** 1.66 +14 -1 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Index: JUnitTask.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- JUnitTask.java 23 May 2003 14:23:58 -0000 1.65 +++ JUnitTask.java 27 May 2003 08:49:42 -0000 1.66 @@ -426,6 +426,14 @@ } /** + * Adds a path to the bootclasspath. + * @since Ant 1.6 + */ + public Path createBootclasspath() { + return commandline.createBootclasspath(getProject()).createPath(); + } + + /** * Adds an environment variable; used when forking. * * <p>Will be ignored if we are not forking a new VM.</p> @@ -823,6 +831,11 @@ if (newEnvironment || null != env.getVariables()) { log("Changes to environment variables are ignored if running in " + "the same VM.", Project.MSG_WARN); + } + + if (commandline.getBootclasspath() != null) { + log("bootclasspath is ignored if running in the same VM.", + Project.MSG_WARN); } CommandlineJava.SysProperties sysProperties = 1.39 +82 -6 ant/src/main/org/apache/tools/ant/types/CommandlineJava.java Index: CommandlineJava.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/CommandlineJava.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- CommandlineJava.java 12 May 2003 14:00:10 -0000 1.38 +++ CommandlineJava.java 27 May 2003 08:49:42 -0000 1.39 @@ -85,6 +85,7 @@ */ private SysProperties sysProperties = new SysProperties(); private Path classpath = null; + private Path bootclasspath = null; private String vmVersion; private String maxMemory = null; @@ -270,6 +271,16 @@ return classpath; } + /** + * @since Ant 1.6 + */ + public Path createBootclasspath(Project p) { + if (bootclasspath == null) { + bootclasspath = new Path(p); + } + return bootclasspath; + } + public String getVmversion() { return vmVersion; } @@ -294,11 +305,16 @@ result, pos, sysProperties.size()); pos += sysProperties.size(); } - // classpath is a vm option too.. - Path fullClasspath = classpath != null ? classpath.concatSystemClasspath("ignore") : null; - if (fullClasspath != null && fullClasspath.toString().trim().length() > 0) { + + // classpath and bootclasspath are vm options too.. + if (haveBootclasspath(false)) { + result[pos++] = "-Xbootclasspath:" + bootclasspath.toString(); + } + + if (haveClasspath()) { result[pos++] = "-classpath"; - result[pos++] = fullClasspath.toString(); + result[pos++] = + classpath.concatSystemClasspath("ignore").toString(); } // JDK usage command line says that -jar must be the first option, as there is @@ -377,10 +393,13 @@ public int size() { int size = getActualVMCommand().size() + javaCommand.size() + sysProperties.size(); // classpath is "-classpath <classpath>" -> 2 args - Path fullClasspath = classpath != null ? classpath.concatSystemClasspath("ignore") : null; - if (fullClasspath != null && fullClasspath.toString().trim().length() > 0) { + if (haveClasspath()) { size += 2; } + // bootclasspath is "-Xbootclasspath:<classpath>" -> 1 arg + if (haveBootclasspath(true)) { + size++; + } // jar execution requires an additional -jar option if (executeJar){ size++ ; @@ -400,6 +419,10 @@ return classpath; } + public Path getBootclasspath() { + return bootclasspath; + } + public void setSystemProperties() throws BuildException { sysProperties.setSystem(); } @@ -425,6 +448,9 @@ if (classpath != null) { c.classpath = (Path) classpath.clone(); } + if (bootclasspath != null) { + c.bootclasspath = (Path) bootclasspath.clone(); + } c.vmVersion = vmVersion; c.executeJar = executeJar; return c; @@ -435,6 +461,56 @@ */ public void clearJavaArgs() { javaCommand.clearArgs(); + } + + /** + * Has the classpath been specified and shall it really be used or + * will build.sysclasspath null it? + * + * @since Ant 1.6 + */ + private boolean haveClasspath() { + Path fullClasspath = classpath != null + ? classpath.concatSystemClasspath("ignore") : null; + return fullClasspath != null + && fullClasspath.toString().trim().length() > 0; + } + + /** + * Has the bootclasspath been specified and shall it really be + * used (build.sysclasspath could be set or the VM may not support + * it)? + * + * @param log whether to log a warning if a bootclasspath has been + * specified but will be ignored. + * + * @since Ant 1.6 + */ + private boolean haveBootclasspath(boolean log) { + if (bootclasspath != null + && bootclasspath.toString().trim().length() > 0) { + + /* + * XXX - need to log something, but there is no ProjectComponent + * around to log to. + */ + if (!bootclasspath.toString() + .equals(bootclasspath.concatSystemClasspath("ignore") + .toString())) { + if (log) { + System.out.println("Ignoring bootclasspath as " + + "build.sysclasspath has been set."); + } + } else if (vmVersion.startsWith("1.1")) { + if (log) { + System.out.println("Ignoring bootclasspath as " + + "the target VM doesn't support it."); + } + } else { + return true; + } + } + return false; } }