You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by sb...@apache.org on 2002/01/06 21:03:15 UTC

cvs commit: jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit OutputAttribute.java FormatterElement.java JUnitHelper.java FilterElement.java

sbailliez    02/01/06 12:03:15

  Modified:    proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit
                        FormatterElement.java JUnitHelper.java
                        FilterElement.java
  Added:       proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit
                        OutputAttribute.java
  Log:
  - Introduce a specific OutputAttribute to deal with output.
  - Cleaning
  
  Revision  Changes    Path
  1.2       +11 -78    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
  
  Index: FormatterElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormatterElement.java	6 Jan 2002 18:03:19 -0000	1.1
  +++ FormatterElement.java	6 Jan 2002 20:03:14 -0000	1.2
  @@ -53,8 +53,6 @@
    */
   package org.apache.tools.ant.taskdefs.optional.junit;
   
  -import java.io.File;
  -import java.io.FileOutputStream;
   import java.io.OutputStream;
   import java.util.StringTokenizer;
   import java.util.Vector;
  @@ -79,42 +77,27 @@
    *
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
    *
  - * @see JUnitTask,
  + * @see JUnitTask
    * @see Formatter
    */
   public class FormatterElement {
   
  +    /** output stream for the formatter */
       private OutputStream out = new KeepAliveOutputStream(System.out);
  -    private String classname;
   
  -    /**
  -     * @fixme we can remove this and use a specific attribute
  -     * to denote a filepathname and stdout as a reserved word.
  -     */
  -    private String extension;
  -
  -    /** are we using a file ? */
  -    private File outFile;
  -    private boolean useFile = true;
  +    /** formatter classname */
  +    private String classname;
   
       /** the filters to apply to this formatter */
       private Vector filters = new Vector();
   
       /**
  -     * <p> Quick way to use a standard formatter.
  -     *
  -     * <p> At the moment, there are three supported standard formatters.
  -     * <ul>
  -     * <li> The <code>xml</code> type uses a <code>XMLJUnitResultFormatter</code>.
  -     * <li> The <code>brief</code> type uses a <code>BriefJUnitResultFormatter</code>.
  -     * <li> The <code>plain</code> type (the default) uses a <code>PlainJUnitResultFormatter</code>.
  -     * </ul>
  -     *
  -     * <p> Sets <code>classname</code> attribute - so you can't use that attribute if you use this one.
  +     * set an existing type of formatter.
  +     * @see TypeAttribute
  +     * @see #setClassname(String)
        */
       public void setType(TypeAttribute type) {
           setClassname(type.getClassName());
  -        setExtension(type.getExtension());
       }
   
       /**
  @@ -127,21 +110,6 @@
       }
   
       /**
  -     * Get name of class to be used as the formatter.
  -     */
  -    public String getClassname() {
  -        return classname;
  -    }
  -
  -    public void setExtension(String ext) {
  -        this.extension = ext;
  -    }
  -
  -    public String getExtension() {
  -        return extension;
  -    }
  -
  -    /**
        * Setting a comma separated list of filters in the specified order.
        * @see #addFilter(FilterAttribute)
        * @see FilterAttribute
  @@ -165,35 +133,10 @@
       }
   
       /**
  -     * <p> Set the file which the formatte should log to.
  -     *
  -     * <p> Note that logging to file must be enabled .
  -     */
  -    void setOutfile(File out) {
  -        this.outFile = out;
  -    }
  -
  -    /**
  -     * <p> Set output stream for formatter to use.
  -     *
  -     * <p> Defaults to standard out.
  -     */
  -    public void setOutput(OutputStream out) {
  -        this.out = out;
  -    }
  -
  -    /**
        * Set whether the formatter should log to file.
        */
  -    public void setUseFile(boolean useFile) {
  -        this.useFile = useFile;
  -    }
  -
  -    /**
  -     * Get whether the formatter should log to file.
  -     */
  -    boolean getUseFile() {
  -        return useFile;
  +    public void setOutput(OutputAttribute output) {
  +        this.out = output.getOutputStream();
       }
   
       /**
  @@ -207,14 +150,9 @@
           try {
               Class clazz = Class.forName(classname);
               if (!Formatter.class.isAssignableFrom(clazz)) {
  -                throw new BuildException(clazz + " is not a JUnitResultFormatter");
  +                throw new BuildException(clazz + " is not a Formatter");
               }
               f = (Formatter) clazz.newInstance();
  -
  -            // create the stream if necessary
  -            if (useFile && outFile != null) {
  -                out = new FileOutputStream(outFile);
  -            }
           } catch (BuildException e) {
               throw e;
           } catch (Exception e) {
  @@ -234,12 +172,11 @@
   
       /**
        * <p> Enumerated attribute with the values "plain", "xml" and "brief".
  -     * <p> Use to enumerate options for <code>type</code> attribute.
  +     * <p> Use to enumerate options for <tt>type</tt> attribute.
        */
       public static class TypeAttribute extends EnumeratedAttribute {
           private final static String[] VALUES = {"plain", "xml", "brief"};
           private final static String[] CLASSNAMES = {"xxx", XMLFormatter.class.getName(), BriefFormatter.class.getName()};
  -        private final static String[] EXTENSIONS = {".txt", ".xml", ".txt"};
   
           public String[] getValues() {
               return VALUES;
  @@ -247,10 +184,6 @@
   
           public String getClassName() {
               return CLASSNAMES[index];
  -        }
  -
  -        public String getExtension() {
  -            return EXTENSIONS[index];
           }
       }
   
  
  
  
  1.2       +1 -1      jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitHelper.java
  
  Index: JUnitHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JUnitHelper.java	5 Jan 2002 19:06:44 -0000	1.1
  +++ JUnitHelper.java	6 Jan 2002 20:03:14 -0000	1.2
  @@ -65,7 +65,7 @@
    */
   public final class JUnitHelper {
   
  -    private static final String SUITE_METHODNAME = "suite";
  +    private final static String SUITE_METHODNAME = "suite";
   
       /**
        * This method parse the output of the method <tt>toString()</tt>
  
  
  
  1.2       +1 -1      jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/FilterElement.java
  
  Index: FilterElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/FilterElement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilterElement.java	6 Jan 2002 18:03:19 -0000	1.1
  +++ FilterElement.java	6 Jan 2002 20:03:14 -0000	1.2
  @@ -68,7 +68,7 @@
    * being the bottom filter.
    *
    * <pre>
  - * <!ELEMENT filter (type|classname)>
  + * <!ELEMENT filter>
    * <!ATTLIST filter type (stack) required>
    * <!ATTLIST filter classname CDATA required>
    * </pre>
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/OutputAttribute.java
  
  Index: OutputAttribute.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.junit;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.ProjectComponent;
  import org.apache.tools.ant.taskdefs.optional.junit.formatter.KeepAliveOutputStream;
  
  /**
   * Attempt to create an output specific attribute.
   * <p>
   * The possible output values are 'stdout' and 'stderr', otherwise
   * it is assumed that the value represent a file.
   * </p>
   * Note that stdout and stderr are wrapped by a <tt>KeepAliveOutputStream</tt>
   * so that the stream cannot be closed.
   *
   * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
   * @see KeepAliveOutputStream
   */
  public class OutputAttribute extends ProjectComponent {
  
      /** keyword to represent stdout output */
      public final static String STDOUT = "stdout";
  
      /** keyword to represent stderr output */
      public final static String STDERR = "stderr";
  
      /** the selected value for output, either stdout,stderr or filepath */
      protected String value;
  
      /**
       * Create a new output attribute from a value.
       */
      public OutputAttribute(String value) {
          this.value = value;
      }
  
      /**
       * @return the outputstream corresponding to the selected attribute.
       */
      public OutputStream getOutputStream() {
          if (STDOUT.equals(value)) {
              return new KeepAliveOutputStream(System.out);
          } else if (STDERR.equals(value)) {
              return new KeepAliveOutputStream(System.err);
          }
          File f = project.resolveFile(value);
          try {
              return new FileOutputStream(f);
          } catch (IOException e) {
              throw new BuildException(e);
          }
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>