Browse Source

Add a nested <bootclasspath> to <java>.

Submitted by:	W. Craig Trader <craig dot trader at lmco dot com>

Do the same for <junit>.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274621 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
b5bd5af059
6 changed files with 130 additions and 6 deletions
  1. +3
    -0
      WHATSNEW
  2. +10
    -0
      docs/manual/CoreTasks/java.html
  3. +9
    -0
      docs/manual/OptionalTasks/junit.html
  4. +13
    -0
      src/main/org/apache/tools/ant/taskdefs/Java.java
  5. +13
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  6. +82
    -6
      src/main/org/apache/tools/ant/types/CommandlineJava.java

+ 3
- 0
WHATSNEW View File

@@ -375,6 +375,9 @@ Other changes:
* 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
===================================



+ 10
- 0
docs/manual/CoreTasks/java.html View File

@@ -189,6 +189,16 @@ with <a href="../CoreTypes/propertyset.html">syspropertyset</a>s.</p>
<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


+ 9
- 0
docs/manual/OptionalTasks/junit.html View File

@@ -228,6 +228,15 @@ description in the <a href="../CoreTasks/exec.html#env">exec</a> task.</p>

<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


+ 13
- 0
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -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.
*/


+ 13
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -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) {


+ 82
- 6
src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -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 <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 @@ 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;
}

}

Loading…
Cancel
Save