git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@732010 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -567,8 +567,7 @@ public class SQLExec extends JDBCTask { | |||||
| } | } | ||||
| try { | try { | ||||
| PrintStream out = | |||||
| new PrintStream(new KeepAliveOutputStream(System.out)); | |||||
| PrintStream out = KeepAliveOutputStream.wrapSystemOut(); | |||||
| try { | try { | ||||
| if (output != null) { | if (output != null) { | ||||
| log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE); | log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE); | ||||
| @@ -29,6 +29,7 @@ import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import org.apache.tools.ant.util.KeepAliveOutputStream; | |||||
| /** | /** | ||||
| * <p> A wrapper for the implementations of <code>JUnitResultFormatter</code>. | * <p> A wrapper for the implementations of <code>JUnitResultFormatter</code>. | ||||
| @@ -57,7 +58,7 @@ public class FormatterElement { | |||||
| private String classname; | private String classname; | ||||
| private String extension; | private String extension; | ||||
| private OutputStream out = System.out; | |||||
| private OutputStream out = new KeepAliveOutputStream(System.out); | |||||
| private File outFile; | private File outFile; | ||||
| private boolean useFile = true; | private boolean useFile = true; | ||||
| private String ifProperty; | private String ifProperty; | ||||
| @@ -170,6 +171,9 @@ public class FormatterElement { | |||||
| * @param out the output stream to use. | * @param out the output stream to use. | ||||
| */ | */ | ||||
| public void setOutput(OutputStream out) { | public void setOutput(OutputStream out) { | ||||
| if (out == System.out || out == System.err) { | |||||
| out = new KeepAliveOutputStream(out); | |||||
| } | |||||
| this.out = out; | this.out = out; | ||||
| } | } | ||||
| @@ -224,7 +224,9 @@ public class SSHExec extends SSHBase { | |||||
| private void executeCommand(Session session, String cmd, StringBuffer sb) | private void executeCommand(Session session, String cmd, StringBuffer sb) | ||||
| throws BuildException { | throws BuildException { | ||||
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||||
| TeeOutputStream tee = new TeeOutputStream(out, new KeepAliveOutputStream(System.out)); | |||||
| TeeOutputStream tee = | |||||
| new TeeOutputStream(out, | |||||
| KeepAliveOutputStream.wrapSystemOut()); | |||||
| InputStream istream = null ; | InputStream istream = null ; | ||||
| if (inputFile != null) { | if (inputFile != null) { | ||||
| @@ -54,4 +54,14 @@ public class KeepAliveInputStream extends FilterInputStream { | |||||
| public void close() throws IOException { | public void close() throws IOException { | ||||
| // do not close the stream | // 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); | |||||
| } | |||||
| } | } | ||||
| @@ -20,6 +20,7 @@ package org.apache.tools.ant.util; | |||||
| import java.io.FilterOutputStream; | import java.io.FilterOutputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.OutputStream; | import java.io.OutputStream; | ||||
| import java.io.PrintStream; | |||||
| /** | /** | ||||
| * Class that can be used to wrap <tt>System.out</tt> and <tt>System.err</tt> | * 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 { | public void close() throws IOException { | ||||
| // do not close the stream | // 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)); | |||||
| } | |||||
| } | } | ||||