ehatcher    2003/05/28 06:12:04

  Modified:    .        WHATSNEW
               docs/manual/OptionalTasks junit.html
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        FormatterElement.java JUnitTask.java
  Log:
  Apply patch from #20270 - adds if/unless clause to junit formatters.  
Submitted by Eli Tucker
  
  Revision  Changes    Path
  1.430     +17 -15    ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.429
  retrieving revision 1.430
  diff -u -r1.429 -r1.430
  --- WHATSNEW  27 May 2003 15:25:47 -0000      1.429
  +++ WHATSNEW  28 May 2003 13:12:02 -0000      1.430
  @@ -23,8 +23,8 @@
   
   * <xmlproperty> will no longer fail if the file to be loaded doesn't exist.
   
  -* XML namespaces are now enabled in the XML parser, meaning XML namespace 
  -  declarations no longer cause errors. 
  +* XML namespaces are now enabled in the XML parser, meaning XML namespace
  +  declarations no longer cause errors.
   
   * The <ftp> and <telnet> tasks now require Jakarta Commons Net instead
     of the older ORO Netcomponents version.  See
  @@ -82,7 +82,7 @@
   * <exec> output and error streams can now be redirected independently
     to either a property or a file (or both)
   
  -* TarEntry's File-arg constructor would fail with a 
  +* TarEntry's File-arg constructor would fail with a
     StringIndexOutOfBoundsException on all OSes where os.name is shorter
     than seven characters.  Bugzilla Report 18105.
   
  @@ -112,7 +112,7 @@
   * Perforce tasks relying on output from the server such as <p4change> and 
<p4label>
     were hanging. Bugzilla Reports 18129 and 18956.
   
  -* build.sh install had a problem on cygwin (with REALANTHOME). 
  +* build.sh install had a problem on cygwin (with REALANTHOME).
     Bugzilla Report 17257
   
   * <replaceregexp> didn't work for multi-byte encodings if byline was false.
  @@ -139,19 +139,19 @@
   * <different> selector : make ignoreFileTimes effectively default to true
     and fix a bug in the comparison of timestamps. Bugzilla Report 20205.
   
  -* <different> selector can now be nested directly under a fileset 
  +* <different> selector can now be nested directly under a fileset
     Bugzilla Report 20220.
   
   Other changes:
   --------------
   * Six new Clearcase tasks added.
   
  -* A new filter reader namely tokenfilter has been added.  Bugzilla 
  +* A new filter reader namely tokenfilter has been added.  Bugzilla
     Report 18312.
   
   * A new attribute named skip is added to the TailFilter and
     HeadFilter filter readers.
  -  
  +
   * Shipped XML parser is now Xerces 2.4.0
   
   * The filesetmanifest attribute of <jar> has been reenabled.
  @@ -223,25 +223,25 @@
     all compilers.
   
   * a new attribute "globalopts" can be added to all Perforce tasks.
  -  You can put in it all the strings described by p4 help usage. Refer to 
  +  You can put in it all the strings described by p4 help usage. Refer to
     the docs for more information.
   
   * new Perforce tasks <p4integrate> , <p4resolve>, and <p4labelsync>
   
  -* <p4submit> will change the property p4.change if the Perforce server 
  +* <p4submit> will change the property p4.change if the Perforce server
     renumbers the change list.
  -  It will set the property p4.needsresolve if the submit fails, 
  +  It will set the property p4.needsresolve if the submit fails,
     and the message says that file(s) need to be resolved.
   
   * <replaceregexp> now has an optional encoding attribute to support
     replacing in files that are in a different encoding than the
     platform's default.
  -  
  +
   * The <exec> task may now have its input redirected from either a file
     or a string from the build file. The error output can be separated
     to a different file when outut is redirected. standard error may be
     logged to the Ant log when redirecting output to a file
  -  
  +
   * The <java> task also supports the input redirection and separate
     error streams introduced to the <exec> task. In addition, it is now
     possible to save the output into a property for use within the build
  @@ -302,7 +302,7 @@
   * <mail> has a new attribute encoding. Bugzilla Report 15434.
   
   * <mail> has new attributes user and password for SMTP auth.
  -maillogger can also use this. 
  +maillogger can also use this.
   The implementation only with JavaMail (encoding="MIME").
   Implementation with plain mail remains to do.
   Bugzilla Report 5969.
  @@ -384,6 +384,8 @@
   * <java> and <junit> now support a nested <bootclasspath> element that
     will be ignored if not forking a new VM.
   
  +* <junit>'s nested <formatter> elements now support if/unless clauses.
  +
   Changes from Ant 1.5.2 to Ant 1.5.3
   ===================================
   
  @@ -426,7 +428,7 @@
   
   Other Changes:
   --------------
  -* Added ability to specify manifest encoding for the <jar> and 
  +* Added ability to specify manifest encoding for the <jar> and
     <manifest> tasks
   
   Changes from Ant 1.5.1 to Ant 1.5.2
  @@ -515,7 +517,7 @@
   * Corrected a problem in XMLLogger where it would not associated
     messages with a taskdef'd task
   
  -* <uptodate> now works when using attributes (i.e. not filesets) and 
pointing 
  +* <uptodate> now works when using attributes (i.e. not filesets) and pointing
     to the same file
   
   * Java task (and output system) now stores output which doos not end
  
  
  
  1.27      +10 -0     ant/docs/manual/OptionalTasks/junit.html
  
  Index: junit.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/OptionalTasks/junit.html,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- junit.html        27 May 2003 08:49:41 -0000      1.26
  +++ junit.html        28 May 2003 13:12:03 -0000      1.27
  @@ -285,6 +285,16 @@
         sent to a file.</td>
       <td align="center">No; default is <code>true</code>.</td>
     </tr>
  +  <tr>
  +    <td valign="top">if</td>
  +    <td valign="top">Only use formatter if the named property is set.</td>
  +    <td align="center">No; default is <code>true</code>.</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">unless</td>
  +    <td valign="top">Only use formatter if the named property is <b>not</b> 
set.</td>
  +    <td align="center">No; default is <code>true</code>.</td>
  +  </tr>  
   </table>
   
   <h4>test</h4>
  
  
  
  1.13      +40 -0     
ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
  
  Index: FormatterElement.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FormatterElement.java     23 May 2003 14:15:42 -0000      1.12
  +++ FormatterElement.java     28 May 2003 13:12:03 -0000      1.13
  @@ -59,6 +59,7 @@
   import java.io.OutputStream;
   import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.EnumeratedAttribute;
   
   /**
  @@ -76,6 +77,7 @@
    * must be set. 
    *
    * @author Stefan Bodewig
  + * @author <a href="http://nerdmonkey.com";>Eli Tucker</a>
    *
    * @see JUnitTask
    * @see XMLJUnitResultFormatter
  @@ -90,6 +92,8 @@
       private OutputStream out = System.out;
       private File outFile;
       private boolean useFile = true;
  +    private String ifProperty;
  +    private String unlessProperty;
   
       /**
        * <p> Quick way to use a standard formatter.
  @@ -171,6 +175,42 @@
        */
       boolean getUseFile() {
           return useFile;
  +    }
  +
  +    /**
  +     * Set whether this formatter should be used.  It will be
  +     * used if the property has been set, otherwise it won't.  
  +     * @param ifProperty name of property
  +     */
  +    public void setIf(String ifProperty)
  +    {
  +        this.ifProperty = ifProperty;
  +    }
  +    
  +    /**
  +     * Set whether this formatter should NOT be used. It
  +     * will not be used if the property has been set, orthwise it
  +     * will be used.
  +     * @param unlessProperty name of property
  +     */
  +    public void setUnless(String unlessProperty)
  +    {
  +        this.unlessProperty = unlessProperty;
  +    }
  +
  +    /**
  +     * Ensures that the selector passes the conditions placed
  +     * on it with <code>if</code> and <code>unless</code> properties.
  +     */    
  +    public boolean shouldUse(Task t) {
  +        if (ifProperty != null && t.getProject().getProperty(ifProperty) == 
null) {
  +            return false;
  +        } else if (unlessProperty != null && 
  +                   t.getProject().getProperty(unlessProperty) != null) {
  +            return false;
  +        }
  +
  +        return true;
       }
   
       /**
  
  
  
  1.67      +20 -15    
ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  
  Index: JUnitTask.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- JUnitTask.java    27 May 2003 08:49:42 -0000      1.66
  +++ JUnitTask.java    28 May 2003 13:12:03 -0000      1.67
  @@ -147,6 +147,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Gerrit Riessen</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Erik Hatcher</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Martijn Kruithof></a>
  + * @author <a href="http://nerdmonkey.com";>Eli Tucker</a>
    *
    * @version $Revision$
    *
  @@ -653,15 +654,17 @@
           final FormatterElement[] feArray = mergeFormatters(test);
           for (int i = 0; i < feArray.length; i++) {
               FormatterElement fe = feArray[i];
  -            formatterArg.append("formatter=");
  -            formatterArg.append(fe.getClassname());
  -            File outFile = getOutput(fe, test);
  -            if (outFile != null) {
  -                formatterArg.append(",");
  -                formatterArg.append(outFile);
  +            if(fe.shouldUse(this)) {
  +                formatterArg.append("formatter=");
  +                formatterArg.append(fe.getClassname());
  +                File outFile = getOutput(fe, test);
  +                if (outFile != null) {
  +                    formatterArg.append(",");
  +                    formatterArg.append(outFile);
  +                }
  +                cmd.createArgument().setValue(formatterArg.toString());
  +                formatterArg = new StringBuffer();
               }
  -            cmd.createArgument().setValue(formatterArg.toString());
  -            formatterArg = new StringBuffer();
           }
   
           // Create a temporary file to pass the Ant properties to the
  @@ -868,13 +871,15 @@
               final FormatterElement[] feArray = mergeFormatters(test);
               for (int i = 0; i < feArray.length; i++) {
                   FormatterElement fe = feArray[i];
  -                File outFile = getOutput(fe, test);
  -                if (outFile != null) {
  -                    fe.setOutfile(outFile);
  -                } else {
  -                    fe.setOutput(getDefaultOutput());
  +                if(fe.shouldUse(this)) {
  +                    File outFile = getOutput(fe, test);
  +                    if (outFile != null) {
  +                        fe.setOutfile(outFile);
  +                    } else {
  +                        fe.setOutput(getDefaultOutput());
  +                    }
  +                    runner.addFormatter(fe.createFormatter(cl));
                   }
  -                runner.addFormatter(fe.createFormatter(cl));
               }
   
               runner.run();
  
  
  

Reply via email to