From b5bd5af0590db16a907d2c845821623934a8ff0f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 27 May 2003 08:49:42 +0000 Subject: [PATCH] Add a nested to . Submitted by: W. Craig Trader Do the same for . git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274621 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 + docs/manual/CoreTasks/java.html | 10 +++ docs/manual/OptionalTasks/junit.html | 9 ++ .../org/apache/tools/ant/taskdefs/Java.java | 13 +++ .../taskdefs/optional/junit/JUnitTask.java | 13 +++ .../tools/ant/types/CommandlineJava.java | 88 +++++++++++++++++-- 6 files changed, 130 insertions(+), 6 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 43d5de8f5..f4e524763 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -375,6 +375,9 @@ Other changes: * new selector allowing to select only files or only directories. Bugzilla Report 20222. +* and now support a nested element that + will be ignored if not forking a new VM. + Changes from Ant 1.5.2 to Ant 1.5.3 =================================== diff --git a/docs/manual/CoreTasks/java.html b/docs/manual/CoreTasks/java.html index dcb5cafcd..f0d022268 100644 --- a/docs/manual/CoreTasks/java.html +++ b/docs/manual/CoreTasks/java.html @@ -189,6 +189,16 @@ with syspropertysets.

Java's classpath attribute is a PATH like structure and can also be set via a nested classpath element.

+ +

bootclasspath

+ +

The location of bootstrap class files can be specified using this +PATH like structure - will be ignored +if fork is not true or the target VM doesn't +support it (i.e. Java 1.1).

+ +

since Ant 1.6.

+

env

It is possible to specify environment variables to pass to the forked VM via nested env elements. See the description in the diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html index 9414b3b3d..46961f33a 100644 --- a/docs/manual/OptionalTasks/junit.html +++ b/docs/manual/OptionalTasks/junit.html @@ -228,6 +228,15 @@ description in the exec task.

Settings will be ignored if fork is disabled.

+

bootclasspath

+ +

The location of bootstrap class files can be specified using this +PATH like structure - will be ignored +if fork is not true or the target VM doesn't +support it (i.e. Java 1.1).

+ +

since Ant 1.6.

+

formatter

The results of the tests can be printed in different diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java index 8bb3fde07..9092f57df 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Java.java +++ b/src/main/org/apache/tools/ant/taskdefs/Java.java @@ -149,6 +149,11 @@ public class Java extends Task { + "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); } @@ -197,6 +202,14 @@ public class Java extends Task { return cmdl.createClasspath(getProject()).createPath(); } + /** + * Adds a path to the bootclasspath. + * @since Ant 1.6 + */ + public Path createBootclasspath() { + return cmdl.createBootclasspath(getProject()).createPath(); + } + /** * Classpath to use, by reference. */ diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index 5e2939d75..d639c07fb 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -425,6 +425,14 @@ public class JUnitTask extends Task { return commandline.createClasspath(getProject()).createPath(); } + /** + * 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. * @@ -825,6 +833,11 @@ public class JUnitTask extends Task { + "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 = commandline.getSystemProperties(); if (sysProperties != null) { diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index a55b9c9f7..2b9569326 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -85,6 +85,7 @@ public class CommandlineJava implements Cloneable { */ private SysProperties sysProperties = new SysProperties(); private Path classpath = null; + private Path bootclasspath = null; private String vmVersion; private String maxMemory = null; @@ -270,6 +271,16 @@ public class CommandlineJava implements Cloneable { 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 @@ public class CommandlineJava implements Cloneable { 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 class CommandlineJava implements Cloneable { public int size() { int size = getActualVMCommand().size() + javaCommand.size() + sysProperties.size(); // classpath is "-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:" -> 1 arg + if (haveBootclasspath(true)) { + size++; + } // jar execution requires an additional -jar option if (executeJar){ size++ ; @@ -400,6 +419,10 @@ public class CommandlineJava implements Cloneable { return classpath; } + public Path getBootclasspath() { + return bootclasspath; + } + public void setSystemProperties() throws BuildException { sysProperties.setSystem(); } @@ -425,6 +448,9 @@ public class CommandlineJava implements Cloneable { if (classpath != null) { c.classpath = (Path) classpath.clone(); } + if (bootclasspath != null) { + c.bootclasspath = (Path) bootclasspath.clone(); + } c.vmVersion = vmVersion; c.executeJar = executeJar; return c; @@ -437,4 +463,54 @@ public class CommandlineJava implements Cloneable { 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; + } + }