diff --git a/WHATSNEW b/WHATSNEW index 06fce786b..93c561322 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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 task +* you can now specify environment variables in the and tasks if the fork attribute has been set to true. Changes from Ant 1.4 to Ant 1.4.1 diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html index 2757f28dd..735c2a422 100644 --- a/docs/manual/OptionalTasks/junit.html +++ b/docs/manual/OptionalTasks/junit.html @@ -91,6 +91,13 @@ elements.

fork is disabled) No + + newenvironment + Do not propagate old environment when new + environment variables are specified. Ignored if fork is + disabled. + No, default is "false". +

Nested Elements

@@ -134,6 +141,19 @@ The attributes for this element are the same as for exec

+ +

Please note that the environment of the current Ant process is +not passed to the forked VM if you specify variables using +<env>.

+ +

Settings will be ignored if fork is disabled.

+

formatter

The results of the tests can be printed in different @@ -405,7 +425,7 @@ string patterns:

    "java.lang.reflect.Method.invoke("
    "org.apache.tools.ant."


-

Copyright © 2001 Apache Software Foundation. All rights +

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.

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 6bced3495..f41e75860 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 @@ -141,6 +141,8 @@ import java.net.URL; * @author Gerrit Riessen * @author Erik Hatcher * + * @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. + * + *

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 + * + *

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