ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r732010 - in /ant/core/trunk/src/main/org/apache/tools/ant: taskdefs/SQLExec.java taskdefs/optional/junit/FormatterElement.java taskdefs/optional/ssh/SSHExec.java util/KeepAliveInputStream.java util/KeepAliveOutputStream.java
Date Tue, 06 Jan 2009 17:27:02 GMT
Author: bodewig
Date: Tue Jan  6 09:27:01 2009
New Revision: 732010

URL: http://svn.apache.org/viewvc?rev=732010&view=rev
Log:
tiny refactoring.  Allow JUnit task to be less concerned about formatters (right now formatters
could close System.out/err unless they guard against it).

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java?rev=732010&r1=732009&r2=732010&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java Tue Jan  6 09:27:01
2009
@@ -567,8 +567,7 @@
             }
 
             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);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java?rev=732010&r1=732009&r2=732010&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
Tue Jan  6 09:27:01 2009
@@ -29,6 +29,7 @@
 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 @@
 
     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 @@
      * @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;
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java?rev=732010&r1=732009&r2=732010&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java Tue Jan
 6 09:27:01 2009
@@ -224,7 +224,9 @@
     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) {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java?rev=732010&r1=732009&r2=732010&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveInputStream.java Tue Jan  6
09:27:01 2009
@@ -54,4 +54,14 @@
     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);
+    }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java?rev=732010&r1=732009&r2=732010&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/KeepAliveOutputStream.java Tue Jan 
6 09:27:01 2009
@@ -20,6 +20,7 @@
 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 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));
+    }
 }



Mime
View raw message