Browse Source

add environment variable support to <junit> if VM is forked.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271001 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
4687c7dd41
3 changed files with 64 additions and 2 deletions
  1. +1
    -1
      WHATSNEW
  2. +21
    -1
      docs/manual/OptionalTasks/junit.html
  3. +42
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 1
- 1
WHATSNEW View File

@@ -135,7 +135,7 @@ Other changes:
* A "package" mapper type has been added to allow package directory
names replaced with the dotted form.
* you can now specify environment variables in the <java> task
* you can now specify environment variables in the <java> and <junit> tasks
if the fork attribute has been set to true.

Changes from Ant 1.4 to Ant 1.4.1


+ 21
- 1
docs/manual/OptionalTasks/junit.html View File

@@ -91,6 +91,13 @@ elements</a>.</p>
fork is disabled)</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">newenvironment</td>
<td valign="top">Do not propagate old environment when new
environment variables are specified. Ignored if fork is
disabled.</td>
<td align="center" valign="top">No, default is &quot;false&quot;.</td>
</tr>
</table>

<h3><a name="nested">Nested Elements</a></h3>
@@ -134,6 +141,19 @@ The attributes for this element are the same as for <a href="../CoreTasks/exec.h
available to the test.</p>


<h4>env</h4>

<p>It is possible to specify environment variables to pass to the
forked VM via nested <code>&lt;env&gt;</code> elements. See the
description in the section about
<a href="../CoreTasks/exec.html#env">exec</a></p>

<p>Please note that the environment of the current Ant process is
<b>not</b> passed to the forked VM if you specify variables using
<code>&lt;env&gt;</code>.</p>

<p>Settings will be ignored if fork is disabled.</p>

<h4>formatter</h4>

<p>The results of the tests can be printed in different
@@ -405,7 +425,7 @@ string patterns:<pre>
"java.lang.reflect.Method.invoke("
"org.apache.tools.ant."</pre></p>
<hr>
<p align="center">Copyright &copy; 2001 Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
Reserved.</p>
</body>
</html>

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

@@ -141,6 +141,8 @@ import java.net.URL;
* @author <a href="mailto:Gerrit.Riessen@web.de">Gerrit Riessen</a>
* @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a>
*
* @version $Revision$
*
* @see JUnitTest
* @see BatchTest
*/
@@ -157,6 +159,9 @@ public class JUnitTask extends Task {
private String summaryValue = "";
private JUnitTestRunner runner = null;

private boolean newEnvironment = false;
private Environment env = new Environment();

/**
* Tells this task whether to smartly filter the stack frames of JUnit testcase
* errors and failures before reporting them. This property is applied on all
@@ -340,6 +345,28 @@ public class JUnitTask extends Task {
return commandline.createClasspath(project).createPath();
}

/**
* Add a nested env element - an environment variable.
*
* <p>Will be ignored if we are not forking a new VM.
*
* @since 1.33, Ant 1.5
*/
public void addEnv(Environment.Variable var) {
env.addVariable(var);
}

/**
* Use a completely new environment
*
* <p>Will be ignored if we are not forking a new VM.
*
* @since 1.33, Ant 1.5
*/
public void setNewenvironment(boolean newenv) {
newEnvironment = newenv;
}

/**
* Add a new single testcase.
* @param test a new single testcase
@@ -510,6 +537,16 @@ public class JUnitTask extends Task {
execute.setWorkingDirectory(dir);
}

String[] environment = env.getVariables();
if (environment != null) {
for (int i=0; i<environment.length; i++) {
log("Setting environment variable: "+environment[i],
Project.MSG_VERBOSE);
}
}
execute.setNewenvironment(newEnvironment);
execute.setEnvironment(environment);

log("Executing: "+cmd.toString(), Project.MSG_VERBOSE);
int retVal;
try {
@@ -557,6 +594,11 @@ public class JUnitTask extends Task {
log("dir attribute ignored if running in the same VM", Project.MSG_WARN);
}

if (newEnvironment || null != env.getVariables()) {
log("Changes to environment variables are ignored if running in the same VM.",
Project.MSG_WARN);
}

CommandlineJava.SysProperties sysProperties = commandline.getSystemProperties();
if (sysProperties != null) {
sysProperties.setSystem();


Loading…
Cancel
Save