This is an automated email from the ASF dual-hosted git repository.

npeltier pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git


The following commit(s) were added to refs/heads/master by this push:
     new db2719b  SLING-9986 add bindings scripting ability
db2719b is described below

commit db2719b7792a31ccb2b7444d75fc684cb34cfdf1
Author: Nicolas Peltier <[email protected]>
AuthorDate: Wed Dec 9 15:52:13 2020 +0100

    SLING-9986 add bindings scripting ability
    
    - add the option in CommandExecutor,
    - add the method in pipe builder
---
 src/main/java/org/apache/sling/pipes/PipeBuilder.java        |  7 +++++++
 .../org/apache/sling/pipes/internal/CommandExecutorImpl.java |  8 ++++++++
 .../org/apache/sling/pipes/internal/PipeBuilderImpl.java     | 12 +++++++++---
 .../org/apache/sling/pipes/internal/PipeBuilderImplTest.java | 10 ++++++++++
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/pipes/PipeBuilder.java 
b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
index 254bcb3..74f948c 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBuilder.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
@@ -332,6 +332,13 @@ public interface PipeBuilder {
      */
     PipeBuilder conf(Object... properties) throws IllegalAccessException;
 
+    /**
+     * Adds binding to current pipe
+     * @param bindings bindings key value
+     * @return updated instance of PipeBuilder
+     * @throws IllegalAccessException
+     */
+    PipeBuilder bindings(Object... bindings) throws IllegalAccessException;
 
     /**
      * add outputs passed key
diff --git 
a/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java 
b/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
index 8121d53..df9e48b 100644
--- a/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
@@ -267,6 +267,7 @@ public class CommandExecutorImpl extends 
SlingAllMethodsServlet implements Comma
         String path;
         String expr;
         String[] with;
+        String[] bindings;
         OutputWriter writer;
 
         @Override
@@ -276,6 +277,7 @@ public class CommandExecutorImpl extends 
SlingAllMethodsServlet implements Comma
                 ", path='" + path + '\'' +
                 ", expr='" + expr + '\'' +
                 ", with=" + Arrays.toString(with) +
+                ", bindings=" + Arrays.toString(bindings) +
                 ", writer=" + writer +
                 '}';
         }
@@ -324,6 +326,9 @@ public class CommandExecutorImpl extends 
SlingAllMethodsServlet implements Comma
                     case "with" :
                         this.with = 
keyValuesToArray((List<String>)entry.getValue());
                         break;
+                    case "bindings" :
+                        this.bindings = keyValuesToArray((List<String>) 
entry.getValue());
+                        break;
                     case "outputs" :
                         setOutputs((List<String>)entry.getValue());
                         break;
@@ -368,6 +373,9 @@ public class CommandExecutorImpl extends 
SlingAllMethodsServlet implements Comma
             if (with != null){
                 builder.with(with);
             }
+            if (bindings != null){
+                builder.bindings(bindings);
+            }
         }
     }
 
diff --git a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java 
b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
index 7db39ab..a7f6546 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
@@ -27,6 +27,7 @@ import org.apache.sling.pipes.BasePipe;
 import org.apache.sling.pipes.ExecutionResult;
 import org.apache.sling.pipes.OutputWriter;
 import org.apache.sling.pipes.Pipe;
+import org.apache.sling.pipes.PipeBindings;
 import org.apache.sling.pipes.PipeBuilder;
 import org.apache.sling.pipes.Plumber;
 import org.apache.sling.pipes.internal.inputstream.CsvPipe;
@@ -258,7 +259,12 @@ public class PipeBuilderImpl implements PipeBuilder {
     }
 
     @Override
-    public PipeBuilder acls() throws IllegalAccessException{
+    public PipeBuilder bindings(Object... bindings) throws 
IllegalAccessException {
+        return writeToCurrentStep(PipeBindings.NN_ADDITIONALBINDINGS, 
bindings);
+    }
+
+    @Override
+    public PipeBuilder acls() {
         return pipe(ACLPipe.RESOURCE_TYPE);
     }
 
@@ -277,9 +283,8 @@ public class PipeBuilderImpl implements PipeBuilder {
      * @param name name of the configuration node, can be null in which case 
it's the subpipe itself
      * @param params key/value pair list of configuration
      * @return updated instance of PipeBuilder
-     * @throws IllegalAccessException in case configuration is wrong
      */
-    PipeBuilder writeToCurrentStep(String name, Object... params) throws 
IllegalAccessException {
+    PipeBuilder writeToCurrentStep(String name, Object... params) {
         checkArguments(params);
         Map<String, Object> props = name != null ? currentStep.confs.get(name) 
: currentStep.properties;
         if (props == null){
@@ -446,6 +451,7 @@ public class PipeBuilderImpl implements PipeBuilder {
      */
     public class Step {
         String name;
+        Map<String, Object> bindings;
         Map<String, Object> properties;
         Map<String, Map<String, Object>> confs = new HashMap<>();
         Step(String type){
diff --git 
a/src/test/java/org/apache/sling/pipes/internal/PipeBuilderImplTest.java 
b/src/test/java/org/apache/sling/pipes/internal/PipeBuilderImplTest.java
index bd6475a..c0dd0ab 100644
--- a/src/test/java/org/apache/sling/pipes/internal/PipeBuilderImplTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/PipeBuilderImplTest.java
@@ -21,12 +21,14 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.pipes.AbstractPipeTest;
+import org.apache.sling.pipes.ExecutionResult;
 import org.junit.Test;
 
 public class PipeBuilderImplTest extends AbstractPipeTest {
@@ -65,4 +67,12 @@ public class PipeBuilderImplTest extends AbstractPipeTest {
         assertTrue(fetchBooleanResource(rootPath + "/one/levelDepth"));
         assertTrue(fetchBooleanResource(rootPath + "/one/anotherLevel/depth"));
     }
+
+    @Test
+    public void testLocalBindings() throws PersistenceException, 
InvocationTargetException, IllegalAccessException {
+        
plumber.newPipe(context.resourceResolver()).echo("/content/fruits/${fruit}").build("/some/reference");
+        ExecutionResult result = execute("ref /some/reference @ bindings 
fruit=apple");
+        assertEquals(1, result.size());
+        assertEquals("/content/fruits/apple", 
result.getCurrentPathSet().iterator().next());
+    }
 }

Reply via email to