felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1772855 - in /felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime: Closure.java Pipe.java
Date Tue, 06 Dec 2016 10:10:10 GMT
Author: gnodet
Date: Tue Dec  6 10:10:09 2016
New Revision: 1772855

URL: http://svn.apache.org/viewvc?rev=1772855&view=rev
Log:
[FELIX-5440] [gogo] Do not print results at end of pipe

Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java?rev=1772855&r1=1772854&r2=1772855&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java Tue
Dec  6 10:10:09 2016
@@ -237,9 +237,11 @@ public class Closure implements Function
                     Operator op = i < exec.size() - 1 ? (Operator) exec.get(++i) : null;
                     Channel[] nstreams;
                     boolean[] ntoclose;
+                    boolean endOfPipe;
                     if (i == exec.size() - 1) {
                         nstreams = streams;
                         ntoclose = toclose;
+                        endOfPipe = true;
                     } else if (Token.eq("|", op)) {
                         PipedInputStream pis = new PipedInputStream();
                         PipedOutputStream pos = new PipedOutputStream(pis);
@@ -249,6 +251,7 @@ public class Closure implements Function
                         ntoclose[1] = true;
                         streams[0] = Channels.newChannel(pis);
                         toclose[0] = true;
+                        endOfPipe = false;
                     } else if (Token.eq("|&", op)) {
                         PipedInputStream pis = new PipedInputStream();
                         PipedOutputStream pos = new PipedOutputStream(pis);
@@ -258,15 +261,16 @@ public class Closure implements Function
                         ntoclose[1] = ntoclose[2] = true;
                         streams[0] = Channels.newChannel(pis);
                         toclose[0] = true;
+                        endOfPipe = false;
                     } else {
                         throw new IllegalStateException("Unrecognized pipe operator: '" +
op + "'");
                     }
-                    Pipe pipe = new Pipe(this, job, ex, nstreams, ntoclose);
+                    Pipe pipe = new Pipe(this, job, ex, nstreams, ntoclose, endOfPipe);
                     job.addPipe(pipe);
                 }
             } else {
                 job = session().createJob(executable);
-                Pipe pipe = new Pipe(this, job, (Statement) executable, streams, toclose);
+                Pipe pipe = new Pipe(this, job, (Statement) executable, streams, toclose,
true);
                 job.addPipe(pipe);
             }
 

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java?rev=1772855&r1=1772854&r2=1772855&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java Tue Dec
 6 10:10:09 2016
@@ -118,19 +118,21 @@ public class Pipe implements Callable<Re
     final Statement statement;
     final Channel[] streams;
     final boolean[] toclose;
+    final boolean endOfPipe;
     int error;
 
     InputStream in;
     PrintStream out;
     PrintStream err;
 
-    public Pipe(Closure closure, JobImpl job, Statement statement, Channel[] streams, boolean[]
toclose)
+    public Pipe(Closure closure, JobImpl job, Statement statement, Channel[] streams, boolean[]
toclose, boolean endOfPipe)
     {
         this.closure = closure;
         this.job = job;
         this.statement = statement;
         this.streams = streams;
         this.toclose = toclose;
+        this.endOfPipe = endOfPipe;
     }
 
     public String toString()
@@ -239,8 +241,6 @@ public class Pipe implements Callable<Re
         // will be effective just before actually running the command.
         WritableByteChannel errChannel = (WritableByteChannel) streams[2];
 
-        boolean endOfPipe = !toclose[1];
-
         ThreadIO threadIo = closure.session().threadIO();
 
         try
@@ -436,14 +436,17 @@ public class Pipe implements Callable<Re
         }
         catch (Exception e)
         {
-            String msg = "gogo: " + e.getClass().getSimpleName() + ": " + e.getMessage()
+ "\n";
-            try
-            {
-                errChannel.write(ByteBuffer.wrap(msg.getBytes()));
-            }
-            catch (IOException ioe)
+            if (!endOfPipe)
             {
-                e.addSuppressed(ioe);
+                String msg = "gogo: " + e.getClass().getSimpleName() + ": " + e.getMessage()
+ "\n";
+                try
+                {
+                    errChannel.write(ByteBuffer.wrap(msg.getBytes()));
+                }
+                catch (IOException ioe)
+                {
+                    e.addSuppressed(ioe);
+                }
             }
             return new Result(e);
         }



Mime
View raw message