Browse Source

close streams in junitreport.

PR: 6852

Make XalanExecutor independent of Xalan2 so one can compile
Xalan1Executor without Xalan2.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272185 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
284e7904db
5 changed files with 36 additions and 18 deletions
  1. +0
    -2
      build.xml
  2. +20
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
  3. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java
  4. +7
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java
  5. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java

+ 0
- 2
build.xml View File

@@ -188,8 +188,6 @@
unless="xalan2.present" />
<exclude name="${optional.package}/junit/AggregateTransformer.java"
unless="xalan2.present" />
<exclude name="${optional.package}/junit/XalanExecutor.java"
unless="xalan2.present" />
<exclude name="${optional.package}/junit/Xalan2Executor.java"
unless="xalan2.present" />
</patternset>


+ 20
- 9
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java View File

@@ -226,15 +226,26 @@ public class XMLResultAggregator extends Task implements XMLConstants {
* @throws IOException thrown if there is an error while writing the content.
*/
protected void writeDOMTree(Document doc, File file) throws IOException {
OutputStream out = new FileOutputStream( file );
PrintWriter wri = new PrintWriter(new OutputStreamWriter(out, "UTF8"));
wri.write("<?xml version=\"1.0\"?>\n");
(new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " ");
wri.flush();
wri.close();
// writers do not throw exceptions, so check for them.
if (wri.checkError()){
throw new IOException("Error while writing DOM content");
OutputStream out = null;
PrintWriter wri = null;
try {
out = new FileOutputStream( file );
wri = new PrintWriter(new OutputStreamWriter(out, "UTF8"));
wri.write("<?xml version=\"1.0\"?>\n");
(new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " ");
wri.flush();
// writers do not throw exceptions, so check for them.
if (wri.checkError()){
throw new IOException("Error while writing DOM content");
}
} finally {
if (wri != null) {
wri.close();
out = null;
}
if (out != null) {
out.close();
}
}
}



+ 6
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java View File

@@ -76,7 +76,11 @@ public class Xalan1Executor extends XalanExecutor {
String system_id = caller.getStylesheetSystemId();
XSLTInputSource xsl_src = new XSLTInputSource(system_id);
OutputStream os = getOutputStream();
XSLTResultTarget target = new XSLTResultTarget(os);
processor.process( xml_src, xsl_src, target);
try {
XSLTResultTarget target = new XSLTResultTarget(os);
processor.process( xml_src, xsl_src, target);
} finally {
os.close();
}
}
}

+ 7
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java View File

@@ -77,8 +77,12 @@ public class Xalan2Executor extends XalanExecutor {
Transformer tformer = tfactory.newTransformer(xsl_src);
Source xml_src = new DOMSource(caller.document);
OutputStream os = getOutputStream();
tformer.setParameter("output.dir", caller.toDir.getAbsolutePath());
Result result = new StreamResult(os);
tformer.transform(xml_src, result);
try {
tformer.setParameter("output.dir", caller.toDir.getAbsolutePath());
Result result = new StreamResult(os);
tformer.transform(xml_src, result);
} finally {
os.close();
}
}
}

+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -105,7 +105,8 @@ abstract class XalanExecutor {
XalanExecutor executor = null;
try {
procVersion = Class.forName("org.apache.xalan.processor.XSLProcessorVersion");
executor = new Xalan2Executor();
executor = (XalanExecutor) Class.forName(
"org.apache.tools.ant.taskdefs.optional.junit.Xalan2Executor").newInstance();
} catch (Exception xalan2missing){
try {
procVersion = Class.forName("org.apache.xalan.xslt.XSLProcessorVersion");


Loading…
Cancel
Save