ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit JUnitTask.java
Date Tue, 29 Jan 2002 16:35:46 GMT
bodewig     02/01/29 08:35:46

  Modified:    .        WHATSNEW
               docs/manual/OptionalTasks junit.html
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        JUnitTask.java
  Log:
  add environment variable support to <junit> if VM is forked.
  
  Revision  Changes    Path
  1.200     +1 -1      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.199
  retrieving revision 1.200
  diff -u -r1.199 -r1.200
  --- WHATSNEW	29 Jan 2002 16:20:20 -0000	1.199
  +++ WHATSNEW	29 Jan 2002 16:35:45 -0000	1.200
  @@ -135,7 +135,7 @@
   * 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
  
  
  
  1.11      +21 -1     jakarta-ant/docs/manual/OptionalTasks/junit.html
  
  Index: junit.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTasks/junit.html,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- junit.html	10 Jan 2002 08:48:31 -0000	1.10
  +++ junit.html	29 Jan 2002 16:35:46 -0000	1.11
  @@ -91,6 +91,13 @@
         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 @@
   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 @@
      "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>
  
  
  
  1.33      +42 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  
  Index: JUnitTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- JUnitTask.java	26 Jan 2002 20:45:21 -0000	1.32
  +++ JUnitTask.java	29 Jan 2002 16:35:46 -0000	1.33
  @@ -141,6 +141,8 @@
    * @author <a href="mailto:Gerrit.Riessen@web.de">Gerrit Riessen</a>
    * @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a>
    *
  + * @version $Revision: 1.33 $
  + *
    * @see JUnitTest
    * @see BatchTest
    */
  @@ -157,6 +159,9 @@
       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
  @@ -341,6 +346,28 @@
       }
   
       /**
  +     * 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
        * @see JUnitTest
  @@ -510,6 +537,16 @@
               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 {
  @@ -555,6 +592,11 @@
           test.setProperties(project.getProperties());
           if (dir != null) {
               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();
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message