You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Antoine L�vy-Lambert <le...@tiscali-dsl.de> on 2003/01/05 23:39:42 UTC

[Patch] P4Handler.java

While testing a Perforce function, I have had the problem that ant has
hung. The reason was that I was trying to access files which were not
mapped in my Perforce client, therefore, the only output of p4 was on
standard error, nothing coming on standard out. This made ant hang.
I am suggesting to change the P4HandlerAdapter.java which is used by
most Perforce tasks, so that it starts two threads, to listen to both
standard in and standard out.
It seems that SequenceInputStream hangs when a process only outputs to
standard error.

Antoine

Index: P4HandlerAdapter.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java,v
retrieving revision 1.7
diff -u -r1.7 P4HandlerAdapter.java
--- P4HandlerAdapter.java	30 Jul 2002 09:12:11 -0000	1.7
+++ P4HandlerAdapter.java	5 Jan 2003 22:23:47 -0000
@@ -86,18 +86,10 @@
             }
 
             //Now read any input and process
-
-            BufferedReader input = new BufferedReader(
-                    new InputStreamReader(
-                            new SequenceInputStream(is, es)));
-
-            String line;
-            while ((line = input.readLine()) != null) {
-                process(line);
-            }
-
-            input.close();
-
+            Thread output = new Thread(new Reader(is));
+            Thread error = new Thread(new Reader(es));
+            output.start();
+            error.start();
 
         } catch (Exception e) {
             throw new BuildException(e);
@@ -122,4 +114,32 @@
 
     public void stop() {
     }
+    public class Reader implements Runnable {
+        protected InputStream mystream;
+        public Reader(InputStream is)
+        {
+            mystream=is;
+        }
+        public void setStream(InputStream is) {
+            mystream=is;
+        }
+        public void run() {
+            BufferedReader input = new BufferedReader(
+                    new InputStreamReader(mystream));
+
+            String line;
+            try {
+                while ((line = input.readLine()) != null) {
+                    synchronized (this){
+                        process(line);
+                    }
+                }
+            }
+            catch (Exception e) {
+                throw new BuildException(e);
+            }
+        }
+
+    }
 }
+


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>