You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by db...@apache.org on 2009/07/23 17:46:06 UTC

svn commit: r797111 - in /felix/trunk/gogo/runtime/src: main/java/org/apache/felix/gogo/runtime/shell/Closure.java main/java/org/apache/felix/gogo/runtime/shell/Pipe.java test/java/org/apache/felix/gogo/runtime/shell/TestParser.java

Author: dbaum
Date: Thu Jul 23 15:46:05 2009
New Revision: 797111

URL: http://svn.apache.org/viewvc?rev=797111&view=rev
Log:
fix for FELIX-1403

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

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java?rev=797111&r1=797110&r2=797111&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java Thu Jul 23 15:46:05 2009
@@ -54,9 +54,12 @@
 
             if (pipes.isEmpty())
             {
-                current.setIn(session.in);
-                current.setOut(session.out);
-                current.setErr(session.err);    // XXX: derek.baum@paremus.com
+		if (current.out == null)
+		{
+		    current.setIn(session.in);
+		    current.setOut(session.out);
+		    current.setErr(session.err);
+		}
             }
             else
             {

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java?rev=797111&r1=797110&r2=797111&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java Thu Jul 23 15:46:05 2009
@@ -16,19 +16,25 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-// DWB16: redirect System.err when creating pipe
 package org.apache.felix.gogo.runtime.shell;
 
-import org.osgi.service.command.Converter;
-
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.PrintStream;
 import java.util.List;
 
+import org.osgi.service.command.Converter;
+
 public class Pipe extends Thread
 {
+    static final ThreadLocal<InputStream> tIn = new ThreadLocal<InputStream>();
+    static final ThreadLocal<PrintStream> tOut = new ThreadLocal<PrintStream>();
+    static final ThreadLocal<PrintStream> tErr = new ThreadLocal<PrintStream>();
     InputStream in;
     PrintStream out;
-    PrintStream err;    // derek
+    PrintStream err;
     PipedOutputStream pout;
     Closure closure;
     Exception exception;
@@ -40,6 +46,10 @@
         super("pipe-" + statements);
         this.closure = closure;
         this.statements = statements;
+
+        in = tIn.get();
+        out = tOut.get();
+        err = tErr.get();
     }
 
     public void setIn(InputStream in)
@@ -65,13 +75,15 @@
         next.setIn(new PipedInputStream(pout));
         out = new PrintStream(pout);
         return next;
-
     }
 
     public void run()
     {
-        //closure.session.service.threadIO.setStreams(in, out, System.err);
-        closure.session.service.threadIO.setStreams(in, out, err);    // derek
+        tIn.set(in);
+        tOut.set(out);
+        tErr.set(err);
+        closure.session.service.threadIO.setStreams(in, out, err);
+
         try
         {
             for (List<CharSequence> statement : statements)
@@ -91,6 +103,10 @@
         {
             out.flush();
             closure.session.service.threadIO.close();
+            tIn.set(in);
+            tOut.set(out);
+            tErr.set(err);
+
             try
             {
                 if (in instanceof PipedInputStream)

Modified: felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java?rev=797111&r1=797110&r2=797111&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java (original)
+++ felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java Thu Jul 23 15:46:05 2009
@@ -85,7 +85,11 @@
         c.addCommand("echo", this);
         c.addCommand("capture", this);
         c.addCommand("grep", this);
+        c.addCommand("echoout", this);
+        c.execute("myecho = { echoout $args }");
         assertEquals("def", c.execute("echo def|grep (d.*)|capture"));
+        assertEquals("def", c.execute("echoout def|grep (d.*)|capture"));
+        assertEquals("def", c.execute("myecho def|grep (d.*)|capture"));
         assertEquals("def", c.execute("echo abc; echo def; echo ghi|grep (d.*)|capture"));
         assertEquals("hello world", c.execute("echo hello world|capture"));
         assertEquals("defghi", c.execute("echo abc; echo def; echo ghi|grep (def|ghi)|capture"));
@@ -241,6 +245,11 @@
         return sb;
     }
 
+    public void echoout(Object args[])
+    {
+        System.out.println(echo(args));
+    }
+
     public void testContext() throws Exception
     {
         Context c = new Context();



Re: svn commit: r797111 - in /felix/trunk/gogo/runtime/src: main/java/org/apache/felix/gogo/runtime/shell/Closure.java main/java/org/apache/felix/gogo/runtime/shell/Pipe.java test/java/org/apache/felix/gogo/runtime/shell/TestParser.java

Posted by "Richard S. Hall" <he...@ungoverned.org>.

On 7/23/09 8:46 AM, dbaum@apache.org wrote:
> Author: dbaum
> Date: Thu Jul 23 15:46:05 2009
> New Revision: 797111
>
> URL: http://svn.apache.org/viewvc?rev=797111&view=rev
> Log:
> fix for FELIX-1403
>    

It is definitely a good idea to include the JIRA issue number in our 
commit messages, since JIRA will link the commits up to the issue, but 
it would be nice to have a little more description than this in the 
commit message so the logs are more useful and we are not forced to go 
to JIRA to have any idea of what is going on.

My $0.02. Thanks.

-> richard

> Modified:
>      felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
>      felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java
>      felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
>
> Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
> URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java?rev=797111&r1=797110&r2=797111&view=diff
> ==============================================================================
> --- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java (original)
> +++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java Thu Jul 23 15:46:05 2009
> @@ -54,9 +54,12 @@
>
>               if (pipes.isEmpty())
>               {
> -                current.setIn(session.in);
> -                current.setOut(session.out);
> -                current.setErr(session.err);    // XXX: derek.baum@paremus.com
> +		if (current.out == null)
> +		{
> +		    current.setIn(session.in);
> +		    current.setOut(session.out);
> +		    current.setErr(session.err);
> +		}
>               }
>               else
>               {
>
> Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java
> URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java?rev=797111&r1=797110&r2=797111&view=diff
> ==============================================================================
> --- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java (original)
> +++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Pipe.java Thu Jul 23 15:46:05 2009
> @@ -16,19 +16,25 @@
>    * specific language governing permissions and limitations
>    * under the License.
>    */
> -// DWB16: redirect System.err when creating pipe
>   package org.apache.felix.gogo.runtime.shell;
>
> -import org.osgi.service.command.Converter;
> -
> -import java.io.*;
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.io.PipedInputStream;
> +import java.io.PipedOutputStream;
> +import java.io.PrintStream;
>   import java.util.List;
>
> +import org.osgi.service.command.Converter;
> +
>   public class Pipe extends Thread
>   {
> +    static final ThreadLocal<InputStream>  tIn = new ThreadLocal<InputStream>();
> +    static final ThreadLocal<PrintStream>  tOut = new ThreadLocal<PrintStream>();
> +    static final ThreadLocal<PrintStream>  tErr = new ThreadLocal<PrintStream>();
>       InputStream in;
>       PrintStream out;
> -    PrintStream err;    // derek
> +    PrintStream err;
>       PipedOutputStream pout;
>       Closure closure;
>       Exception exception;
> @@ -40,6 +46,10 @@
>           super("pipe-" + statements);
>           this.closure = closure;
>           this.statements = statements;
> +
> +        in = tIn.get();
> +        out = tOut.get();
> +        err = tErr.get();
>       }
>
>       public void setIn(InputStream in)
> @@ -65,13 +75,15 @@
>           next.setIn(new PipedInputStream(pout));
>           out = new PrintStream(pout);
>           return next;
> -
>       }
>
>       public void run()
>       {
> -        //closure.session.service.threadIO.setStreams(in, out, System.err);
> -        closure.session.service.threadIO.setStreams(in, out, err);    // derek
> +        tIn.set(in);
> +        tOut.set(out);
> +        tErr.set(err);
> +        closure.session.service.threadIO.setStreams(in, out, err);
> +
>           try
>           {
>               for (List<CharSequence>  statement : statements)
> @@ -91,6 +103,10 @@
>           {
>               out.flush();
>               closure.session.service.threadIO.close();
> +            tIn.set(in);
> +            tOut.set(out);
> +            tErr.set(err);
> +
>               try
>               {
>                   if (in instanceof PipedInputStream)
>
> Modified: felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
> URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java?rev=797111&r1=797110&r2=797111&view=diff
> ==============================================================================
> --- felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java (original)
> +++ felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java Thu Jul 23 15:46:05 2009
> @@ -85,7 +85,11 @@
>           c.addCommand("echo", this);
>           c.addCommand("capture", this);
>           c.addCommand("grep", this);
> +        c.addCommand("echoout", this);
> +        c.execute("myecho = { echoout $args }");
>           assertEquals("def", c.execute("echo def|grep (d.*)|capture"));
> +        assertEquals("def", c.execute("echoout def|grep (d.*)|capture"));
> +        assertEquals("def", c.execute("myecho def|grep (d.*)|capture"));
>           assertEquals("def", c.execute("echo abc; echo def; echo ghi|grep (d.*)|capture"));
>           assertEquals("hello world", c.execute("echo hello world|capture"));
>           assertEquals("defghi", c.execute("echo abc; echo def; echo ghi|grep (def|ghi)|capture"));
> @@ -241,6 +245,11 @@
>           return sb;
>       }
>
> +    public void echoout(Object args[])
> +    {
> +        System.out.println(echo(args));
> +    }
> +
>       public void testContext() throws Exception
>       {
>           Context c = new Context();
>
>
>