ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter XMLFormatter.java BaseStreamFormatter.java
Date Sun, 27 Jan 2002 18:29:20 GMT
sbailliez    02/01/27 10:29:20

  Modified:    proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter
                        XMLFormatter.java BaseStreamFormatter.java
  Log:
  Fix xml formatter. It is still not correct though...
  
  Revision  Changes    Path
  1.6       +22 -5     jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java
  
  Index: XMLFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLFormatter.java	14 Jan 2002 00:26:04 -0000	1.5
  +++ XMLFormatter.java	27 Jan 2002 18:29:20 -0000	1.6
  @@ -54,6 +54,7 @@
   package org.apache.tools.ant.taskdefs.optional.junit.formatter;
   
   import java.util.Hashtable;
  +import java.io.IOException;
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
   
  @@ -61,6 +62,9 @@
   import org.w3c.dom.Element;
   import org.w3c.dom.Text;
   
  +import org.apache.tools.ant.util.DOMElementWriter;
  +import org.apache.tools.ant.BuildException;
  +
   /**
    * XML Formatter. Due to the nature of the XML we are forced to store
    * everything in memory until it is finished. It might be resource
  @@ -68,7 +72,7 @@
    *
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
    */
  -public class XMLFormatter extends BaseFormatter {
  +public class XMLFormatter extends BaseStreamFormatter {
   
       /** the testsuites element for the aggregate document */
       public final static String TESTSUITES = "testsuites";
  @@ -125,10 +129,10 @@
       public final static String ATTR_VALUE = "value";
   
       /** The XML document. */
  -    private Document doc;
  +    private Document doc = getDocumentBuilder().newDocument();
   
       /**  The wrapper for the whole testsuite. */
  -    private Element rootElement;
  +    private Element rootElement = doc.createElement(TESTSUITE);
   
       /** Element for the current test. */
       private Hashtable testElements = new Hashtable();
  @@ -158,8 +162,8 @@
           currentTest.setAttribute(ATTR_TIME, Float.toString(time));
           super.onTestEnded(testname);
           // remove the test objects
  -        testStarts.remove(testname);
  -        testElements.remove(testname);
  +        //testStarts.remove(testname);
  +        //testElements.remove(testname);
       }
   
       public void onTestFailed(int status, String testname, String trace) {
  @@ -197,6 +201,19 @@
   
       public void onTestRunStopped(long elapsedtime) {
           super.onTestRunStopped(elapsedtime);
  +    }
  +
  +    protected void close() {
  +        DOMElementWriter domWriter = new DOMElementWriter();
  +        // the underlying writer uses UTF8 encoding
  +        getWriter().println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
  +        try {
  +            domWriter.write(rootElement, getWriter(), 0, "  ");
  +        } catch (IOException e){
  +            throw new BuildException(e);
  +        } finally {
  +            super.close();
  +        }
       }
   
       private static DocumentBuilder getDocumentBuilder() {
  
  
  
  1.2       +1 -1      jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseStreamFormatter.java
  
  Index: BaseStreamFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseStreamFormatter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseStreamFormatter.java	27 Jan 2002 02:11:59 -0000	1.1
  +++ BaseStreamFormatter.java	27 Jan 2002 18:29:20 -0000	1.2
  @@ -86,7 +86,7 @@
       private PrintWriter writer;
   
       public void init(Properties props) throws BuildException {
  -        String file = props.getProperty("file");
  +        String file = props.getProperty(FILE_KEY);
           OutputStream os = null;
           if (file != null) {
               try {
  
  
  

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