ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1086741 - in /ant/core/trunk: WHATSNEW src/etc/testcases/taskdefs/java.xml src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
Date Tue, 29 Mar 2011 20:59:05 GMT
Author: hibou
Date: Tue Mar 29 20:59:05 2011
New Revision: 1086741

URL: http://svn.apache.org/viewvc?rev=1086741&view=rev
Log:
BR 50960. Use autoflush so that content get pushed to the forked application

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/etc/testcases/taskdefs/java.xml
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1086741&r1=1086740&r2=1086741&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Mar 29 20:59:05 2011
@@ -29,6 +29,9 @@ Fixed bugs:
    files.
    Bugzilla Report 50866.
 
+ * Read on System.in hangs for forked java task.
+   Bugzilla Report 50960.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/etc/testcases/taskdefs/java.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/java.xml?rev=1086741&r1=1086740&r2=1086741&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/java.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/java.xml Tue Mar 29 20:59:05 2011
@@ -387,6 +387,11 @@ redirect.err="${redirect.err}"
 
     </target>
 
+    <target name="flushedInput">
+        <java classname="org.apache.tools.ant.taskdefs.JavaTest$$ReadPoint" fork="true"
+            classpath="${tests-classpath.value}" failonerror="true" timeout="2000" />
+    </target>
+
     <target name="cleanup">
         <delete>
             <fileset file="${logFile}" />
@@ -395,4 +400,5 @@ redirect.err=&quot;${redirect.err}&quot;
     </target>
 
     <target name="foo" />
+
 </project>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java?rev=1086741&r1=1086740&r2=1086741&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java Tue Mar 29
20:59:05 2011
@@ -273,10 +273,9 @@ public class PumpStreamHandler implement
      */
     protected Thread createPump(InputStream is, OutputStream os,
                                 boolean closeWhenExhausted, boolean nonBlockingIO) {
-        final Thread result
-            = new ThreadWithPumper(new StreamPumper(is, os,
-                                                    closeWhenExhausted,
-                                                    nonBlockingIO));
+        StreamPumper pumper = new StreamPumper(is, os, closeWhenExhausted, nonBlockingIO);
+        pumper.setAutoflush(true);
+        final Thread result = new ThreadWithPumper(pumper);
         result.setDaemon(true);
         return result;
     }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java?rev=1086741&r1=1086740&r2=1086741&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java Tue Mar 29
20:59:05 2011
@@ -18,10 +18,12 @@
 
 package org.apache.tools.ant.taskdefs;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PipedInputStream;
@@ -260,6 +262,40 @@ public class JavaTest extends BuildFileT
         assertEquals("foo", project.getProperty("input.value"));
     }
 
+    public void testFlushedInput() throws Exception {
+        final PipedOutputStream out = new PipedOutputStream();
+        final PipedInputStream in = new PipedInputStream(out);
+        project.setInputHandler(new DefaultInputHandler() {
+            protected InputStream getInputStream() {
+                return in;
+            }
+        });
+        project.setDefaultInputStream(in);
+
+        final boolean[] timeout = new boolean[1];
+        timeout[0] = false;
+
+        Thread writingThread = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    // wait a little bit to have the target executed
+                    Thread.sleep(500);
+                } catch (InterruptedException e) {
+                    // don't care
+                }
+                try {
+                    out.write("foo-FlushedInput\n".getBytes());
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+        writingThread.setDaemon(true);
+
+        writingThread.start();
+        executeTarget("flushedInput");
+    }
+
     /**
      * entry point class with no dependencies other
      * than normal JRE runtime
@@ -372,4 +408,12 @@ public class JavaTest extends BuildFileT
             }
         }
     }
+
+    public static class ReadPoint {
+        public static void main(String[] args) throws IOException {
+            String line = new BufferedReader(new InputStreamReader(System.in)).readLine();
+            System.out.println(line);
+        }
+    }
+
 }



Mime
View raw message