Browse Source

Fix xml formatter. It is still not correct though...

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270955 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
efde026060
2 changed files with 23 additions and 6 deletions
  1. +1
    -1
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseStreamFormatter.java
  2. +22
    -5
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java

+ 1
- 1
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseStreamFormatter.java View File

@@ -86,7 +86,7 @@ public class BaseStreamFormatter extends BaseFormatter {
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 {


+ 22
- 5
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java View File

@@ -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.Document;
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 @@ import org.w3c.dom.Text;
*
* @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 class XMLFormatter extends BaseFormatter {
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 @@ public class XMLFormatter extends BaseFormatter {
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) {
@@ -199,6 +203,19 @@ public class XMLFormatter extends BaseFormatter {
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() {
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder();


Loading…
Cancel
Save