summaryrefslogtreecommitdiff
path: root/src/main/org/apache
diff options
context:
space:
mode:
authorStefan Bodewig <bodewig@apache.org>2009-01-06 17:27:01 +0000
committerStefan Bodewig <bodewig@apache.org>2009-01-06 17:27:01 +0000
commit8557fcb14481e120e8cd857ce225363b238574c9 (patch)
treef9367504b53629facaa33f42f2f602164ce4ccf9 /src/main/org/apache
parent2f46b6af935dc478c8ccbb6fff44540a6a8519b2 (diff)
downloadant-8557fcb14481e120e8cd857ce225363b238574c9.tar.gz
tiny refactoring. Allow JUnit task to be less concerned about formatters (right now formatters could close System.out/err unless they guard against it).
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@732010 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/org/apache')
-rw-r--r--src/main/org/apache/tools/ant/taskdefs/SQLExec.java3
-rw-r--r--src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java6
-rw-r--r--src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java4
-rw-r--r--src/main/org/apache/tools/ant/util/KeepAliveInputStream.java10
-rw-r--r--src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java28
5 files changed, 47 insertions, 4 deletions
diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
index 27371dace..3445d483a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
+++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
@@ -567,8 +567,7 @@ public class SQLExec extends JDBCTask {
}
try {
- PrintStream out =
- new PrintStream(new KeepAliveOutputStream(System.out));
+ PrintStream out = KeepAliveOutputStream.wrapSystemOut();
try {
if (output != null) {
log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE);
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
index 2a8a977ec..bed93335e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
@@ -29,6 +29,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.util.KeepAliveOutputStream;
/**
* <p> A wrapper for the implementations of <code>JUnitResultFormatter</code>.
@@ -57,7 +58,7 @@ public class FormatterElement {
private String classname;
private String extension;
- private OutputStream out = System.out;
+ private OutputStream out = new KeepAliveOutputStream(System.out);
private File outFile;
private boolean useFile = true;
private String ifProperty;
@@ -170,6 +171,9 @@ public class FormatterElement {
* @param out the output stream to use.
*/
public void setOutput(OutputStream out) {
+ if (out == System.out || out == System.err) {
+ out = new KeepAliveOutputStream(out);
+ }
this.out = out;
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
index 72aae2ba3..cb6174d31 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
@@ -224,7 +224,9 @@ public class SSHExec extends SSHBase {
private void executeCommand(Session session, String cmd, StringBuffer sb)
throws BuildException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
- TeeOutputStream tee = new TeeOutputStream(out, new KeepAliveOutputStream(System.out));
+ TeeOutputStream tee =
+ new TeeOutputStream(out,
+ KeepAliveOutputStream.wrapSystemOut());
InputStream istream = null ;
if (inputFile != null) {
diff --git a/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java b/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java
index cc79d6727..ac5919710 100644
--- a/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java
+++ b/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java
@@ -54,4 +54,14 @@ public class KeepAliveInputStream extends FilterInputStream {
public void close() throws IOException {
// do not close the stream
}
+
+ /**
+ * Convenience factory method that returns a non-closing
+ * InputStream around System.in.
+ *
+ * @since Ant 1.8.0
+ */
+ public static InputStream wrapSystemIn() {
+ return new KeepAliveInputStream(System.in);
+ }
}
diff --git a/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java b/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java
index 0437a1f04..4e437e906 100644
--- a/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java
+++ b/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java
@@ -20,6 +20,7 @@ package org.apache.tools.ant.util;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.PrintStream;
/**
* Class that can be used to wrap <tt>System.out</tt> and <tt>System.err</tt>
@@ -53,4 +54,31 @@ public class KeepAliveOutputStream extends FilterOutputStream {
public void close() throws IOException {
// do not close the stream
}
+
+ /**
+ * Convenience factory method that returns a non-closing
+ * PrintStream around System.out.
+ *
+ * @since Ant 1.8.0
+ */
+ public static PrintStream wrapSystemOut() {
+ return wrap(System.out);
+ }
+
+ /**
+ * Convenience factory method that returns a non-closing
+ * PrintStream around System.err.
+ *
+ * @since Ant 1.8.0
+ */
+ public static PrintStream wrapSystemErr() {
+ return wrap(System.err);
+ }
+
+ /**
+ * @since Ant 1.8.0
+ */
+ private static PrintStream wrap(PrintStream ps) {
+ return new PrintStream(new KeepAliveOutputStream(ps));
+ }
}