Support for here-string

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1736056 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java
index c9fbd19..e98acf1 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Parser.java
@@ -307,7 +307,7 @@
     }
 
     private static final Pattern redirNoArg = Pattern.compile("[0-9]?>&[0-9-]|[0-9-]?<&[0-9-]");
-    private static final Pattern redirArg = Pattern.compile("[0-9&]?>|[0-9]?>>|[0-9]?<|[0-9]?<>");
+    private static final Pattern redirArg = Pattern.compile("[0-9&]?>|[0-9]?>>|[0-9]?<|[0-9]?<>|<<<");
 
     public Statement statement()
     {
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java
index 143a0e7..d3222f4 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Pipe.java
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.gogo.runtime;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -325,6 +326,14 @@
                         setStream(ch, fd, READ + (output ? WRITE : 0));
                     }
                 }
+                else if (Token.eq("<<<", t))
+                {
+                    Token word = tokens.get(++i);
+                    Object val = Expander.expand("\"" + word + "\"", closure);
+                    String str = val != null ? String.valueOf(val) : "";
+                    Channel ch = Channels.newChannel(new ByteArrayInputStream(str.getBytes()));
+                    setStream(ch, 0, READ);
+                }
             }
 
             for (int i = 0; i < streams.length; i++) {
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
index 427dce1..558b2d9 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
@@ -23,7 +23,7 @@
 public class Tokenizer extends BaseTokenizer
 {
 
-    private final Pattern redir = Pattern.compile("[0-9&]?>|[0-9]?>>|[0-9]?>&|[0-9]?<|[0-9]?<>");
+    private final Pattern redir = Pattern.compile("[0-9&]?>|[0-9]?>>|[0-9]?>&|[0-9]?<|[0-9]?<>|<<<");
 
     protected boolean inArray;
     protected int word = 0;
diff --git a/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java b/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java
index 07c82f9..7980014 100644
--- a/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java
+++ b/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser4.java
@@ -135,6 +135,21 @@
         assertEquals("bar\nbar\n", c.execute("cat <$c | tac"));
     }
 
+    @Test
+    public void testHereString() throws Exception
+    {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        c.addCommand("tac", this);
+        c.addCommand("cat", this);
+
+        c.execute("a=foo");
+        assertEquals("foo\n", c.execute("cat <<< $a | tac"));
+
+        c.execute("c = [ ar1 ar2 ]");
+        assertEquals("ar1 ar2\n", c.execute("cat <<<$c | tac"));
+    }
+
     public void echo(String msg)
     {
         System.out.println(msg);