You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by np...@apache.org on 2021/09/15 17:44:26 UTC

[sling-org-apache-sling-pipes] branch master updated (5f4ec49 -> f2e054b)

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

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


    from 5f4ec49  SLING-10809 adding parsed command and result
     new a1b3a61  SLING-10419 remove useless imports
     new f9f8289  SLING-10419 add context in log (and test)
     new 5125ac1  SLING-10816 fixing left token of parsed expr
     new f2e054b  SLING-10817 extend whitespace definition

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/main/java/org/apache/sling/pipes/BasePipe.java |  4 +--
 .../java/org/apache/sling/pipes/PipeBindings.java  |  2 +-
 .../sling/pipes/internal/CommandExecutorImpl.java  |  2 +-
 .../apache/sling/pipes/internal/CommandUtil.java   | 29 +++++++++++-----------
 .../sling/pipes/internal/bindings/JxltEngine.java  |  2 --
 .../sling/pipes/internal/bindings/TimeUtil.java    |  3 ---
 .../java/org/apache/sling/pipes/package-info.java  |  2 +-
 .../java/org/apache/sling/pipes/BasePipeTest.java  |  1 -
 .../org/apache/sling/pipes/PipeBindingsTest.java   | 12 +++++++++
 .../pipes/internal/CommandExecutorImplTest.java    | 17 ++++++++++---
 .../sling/pipes/internal/CommandUtilTest.java      | 25 +++++++++++++++++++
 .../sling/pipes/internal/FilterPipeTest.java       |  2 +-
 .../sling/pipes/internal/JCRWritePipeTest.java     |  1 -
 .../sling/pipes/internal/PlumberServletTest.java   | 16 +++++-------
 14 files changed, 77 insertions(+), 41 deletions(-)

[sling-org-apache-sling-pipes] 04/04: SLING-10817 extend whitespace definition

Posted by np...@apache.org.
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

commit f2e054bde0654eabc4291a0dd4b9f00997242ed5
Author: Nicolas Peltier <np...@apache.org>
AuthorDate: Wed Sep 15 19:43:48 2021 +0200

    SLING-10817 extend whitespace definition
---
 .../java/org/apache/sling/pipes/internal/CommandExecutorImpl.java  | 2 +-
 .../org/apache/sling/pipes/internal/CommandExecutorImplTest.java   | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

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 7438989..29c849d 100644
--- a/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
@@ -84,7 +84,7 @@ public class CommandExecutorImpl extends AbstractPlumberServlet implements Comma
     static final String REQ_PARAM_HELP = "pipe_help";
     static final String CMD_LINE_PREFIX = "cmd_line_";
     static final String PN_DESCRIPTION = "commandParsed";
-    static final String WHITE_SPACE_SEPARATOR = "\\s";
+    static final String WHITE_SPACE_SEPARATOR = "[\\s\\h]";
     static final String COMMENT_PREFIX = "#";
     static final String SEPARATOR = "|";
     static final String PIPE_SEPARATOR = WHITE_SPACE_SEPARATOR + "*\\" + SEPARATOR + WHITE_SPACE_SEPARATOR + "*";
diff --git a/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java b/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java
index 31021f1..753e833 100644
--- a/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java
@@ -32,6 +32,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -165,6 +166,12 @@ public class CommandExecutorImplTest extends AbstractPipeTest {
     }
 
     @Test
+    public void testNonBreakingSpaces() throws InvocationTargetException, IllegalAccessException {
+        ExecutionResult result = execute("echo /content | mkdir test @ name child");
+        assertEquals(1, result.size());
+    }
+
+    @Test
     public void adaptToDemoTest() throws Exception {
         String url = "'http://99-bottles-of-beer.net/lyrics.html'";
         String cmd = "egrep " + url + " @ name bottles @ with pattern=(?<number>\\d(\\d)?) | mkdir /var/bottles/${bottles.number}";

[sling-org-apache-sling-pipes] 01/04: SLING-10419 remove useless imports

Posted by np...@apache.org.
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

commit a1b3a614240ac079725e1c6db6a595fba3d82071
Author: Nicolas Peltier <np...@apache.org>
AuthorDate: Wed Sep 15 12:58:04 2021 +0200

    SLING-10419 remove useless imports
---
 src/main/java/org/apache/sling/pipes/internal/bindings/JxltEngine.java | 2 --
 src/main/java/org/apache/sling/pipes/internal/bindings/TimeUtil.java   | 3 ---
 2 files changed, 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/pipes/internal/bindings/JxltEngine.java b/src/main/java/org/apache/sling/pipes/internal/bindings/JxltEngine.java
index 220d801..ffcca1a 100644
--- a/src/main/java/org/apache/sling/pipes/internal/bindings/JxltEngine.java
+++ b/src/main/java/org/apache/sling/pipes/internal/bindings/JxltEngine.java
@@ -16,8 +16,6 @@
  */
 package org.apache.sling.pipes.internal.bindings;
 
-import java.text.DateFormat;
-import java.util.Date;
 import java.util.Map;
 
 import org.apache.commons.jexl3.JexlBuilder;
diff --git a/src/main/java/org/apache/sling/pipes/internal/bindings/TimeUtil.java b/src/main/java/org/apache/sling/pipes/internal/bindings/TimeUtil.java
index 22455e6..2e4c58b 100644
--- a/src/main/java/org/apache/sling/pipes/internal/bindings/TimeUtil.java
+++ b/src/main/java/org/apache/sling/pipes/internal/bindings/TimeUtil.java
@@ -17,14 +17,11 @@
 package org.apache.sling.pipes.internal.bindings;
 
 import java.time.LocalDate;
-import java.time.LocalDateTime;
 import java.time.OffsetDateTime;
 import java.time.ZoneId;
-import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
-import java.util.Locale;
 
 /**
  * Utility class to be used in bindings

[sling-org-apache-sling-pipes] 03/04: SLING-10816 fixing left token of parsed expr

Posted by np...@apache.org.
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

commit 5125ac16e0355e328166bbe822a12a59431e193d
Author: Nicolas Peltier <np...@apache.org>
AuthorDate: Wed Sep 15 19:25:01 2021 +0200

    SLING-10816 fixing left token of parsed expr
---
 .../java/org/apache/sling/pipes/PipeBindings.java  |  2 +-
 .../apache/sling/pipes/internal/CommandUtil.java   | 29 +++++++++++-----------
 .../java/org/apache/sling/pipes/package-info.java  |  2 +-
 .../java/org/apache/sling/pipes/BasePipeTest.java  |  1 -
 .../pipes/internal/CommandExecutorImplTest.java    | 10 +++++---
 .../sling/pipes/internal/CommandUtilTest.java      | 25 +++++++++++++++++++
 .../sling/pipes/internal/FilterPipeTest.java       |  2 +-
 .../sling/pipes/internal/JCRWritePipeTest.java     |  1 -
 .../sling/pipes/internal/PlumberServletTest.java   | 16 +++++-------
 src/test/resources/simplelogger.properties         |  2 +-
 10 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/apache/sling/pipes/PipeBindings.java b/src/main/java/org/apache/sling/pipes/PipeBindings.java
index ebcaa78..3f120c2 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBindings.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBindings.java
@@ -69,7 +69,7 @@ public class PipeBindings {
      */
     public static final String NAME_BINDING = "name";
 
-    public static final String INJECTED_SCRIPT_REGEXP = "\\$\\{(([^\\{^\\}]+(\\{[0-9,]+\\})?)*)\\}";
+    public static final String INJECTED_SCRIPT_REGEXP = "\\$\\{(([^\\{^\\}]+(\\{[0-9,]+\\})?)+)\\}";
     private static final Pattern INJECTED_SCRIPT = Pattern.compile(INJECTED_SCRIPT_REGEXP);
     protected static final String IF_PREFIX = "$if";
     protected static final Pattern CONDITIONAL_STRING =  Pattern.compile("^\\" + IF_PREFIX + INJECTED_SCRIPT_REGEXP);
diff --git a/src/main/java/org/apache/sling/pipes/internal/CommandUtil.java b/src/main/java/org/apache/sling/pipes/internal/CommandUtil.java
index 8de164c..527e5d7 100644
--- a/src/main/java/org/apache/sling/pipes/internal/CommandUtil.java
+++ b/src/main/java/org/apache/sling/pipes/internal/CommandUtil.java
@@ -24,7 +24,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -37,19 +37,20 @@ import static org.apache.sling.pipes.PipeBindings.INJECTED_SCRIPT_REGEXP;
 public class CommandUtil {
     static final String PAIR_SEP = ",";
     static final String KEY_VALUE_SEP = "=";
-    static final String FIRST_TOKEN = "first";
-    static final String SECOND_TOKEN = "second";
+    static final String FIRST_KEY = "first";
+    static final String SECOND_KEY = "second";
     static final String PN_JCR_MIXIN = "jcr:mixinTypes";
     static final Pattern MIXINS_ARRAY_PATTERN = Pattern.compile("^\\s*\\[(.*)\\]\\s*$");
     private static final Pattern UNEMBEDDEDSCRIPT_PATTERN = Pattern.compile("^(\\d+(\\.\\d+)?)|" + //21.42
-            "(\\[.*]$)|" + //['one','two']
-            "(\\w[\\w_\\-\\d]+\\..+)|" + //map.field...
-            "(\\w[\\w_\\-\\d]+\\['.+'])|" + //map['field']
-            "(true$|false$)|" + //boolean
-            "(new .*)|" + //instantiation
+            "\\[.*]$|" + //['one','two']
+            "[\\w_\\-]+\\..+|" + //map.field...
+            "[\\w_\\-]+\\['.+']|" + //map['field']
+            "true$|false$|" + //boolean
+            "new .*|" + //instantiation
             "(.*'$)"); // 'string'
-    static final String CONFIGURATION_TOKEN = "(?<" + FIRST_TOKEN + ">[\\w/\\:]+)\\s*" + KEY_VALUE_SEP
-            + "(?<" + SECOND_TOKEN + ">[(\\w*)|" + INJECTED_SCRIPT_REGEXP + "]+)";
+    static final String EXPR_TOKEN = "([^=]+|" + INJECTED_SCRIPT_REGEXP + ")+";
+    static final String CONFIGURATION_TOKEN = "\\s*(?<" + FIRST_KEY + ">" + EXPR_TOKEN + ")\\s*" + KEY_VALUE_SEP
+            + "\\s*(?<" + SECOND_KEY + ">(" + EXPR_TOKEN + ")+)\\s*";
     public static final Pattern CONFIGURATION_PATTERN = Pattern.compile(CONFIGURATION_TOKEN);
 
     private CommandUtil() {
@@ -110,12 +111,12 @@ public class CommandUtil {
      * @param valueTransformer before adding it to the map, that function will be applied to found value
      * @return map of key and (transformed) value
      */
-    public static Map stringToMap(@NotNull String input, Function<String, String> valueTransformer) {
+    public static Map<String, Object> stringToMap(@NotNull String input, UnaryOperator<String> valueTransformer) {
         Map<String, Object> map = new HashMap<>();
         for (String pair : input.split(PAIR_SEP) ){
             Matcher matcher = CONFIGURATION_PATTERN.matcher(pair);
             if (matcher.find()) {
-                map.put(matcher.group(FIRST_TOKEN), valueTransformer.apply(matcher.group(SECOND_TOKEN)));
+                map.put(matcher.group(FIRST_KEY), valueTransformer.apply(matcher.group(SECOND_KEY)));
             }
         }
         return map;
@@ -131,8 +132,8 @@ public class CommandUtil {
             for (String pair : o) {
                 Matcher matcher = CONFIGURATION_PATTERN.matcher(pair.trim());
                 if (matcher.matches()) {
-                    args.add(matcher.group(FIRST_TOKEN));
-                    args.add(matcher.group(SECOND_TOKEN));
+                    args.add(matcher.group(FIRST_KEY));
+                    args.add(matcher.group(SECOND_KEY));
                 }
             }
         }
diff --git a/src/main/java/org/apache/sling/pipes/package-info.java b/src/main/java/org/apache/sling/pipes/package-info.java
index e892a88..711bf13 100644
--- a/src/main/java/org/apache/sling/pipes/package-info.java
+++ b/src/main/java/org/apache/sling/pipes/package-info.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("4.1.0")
+@Version("4.2.0")
 package org.apache.sling.pipes;
 
 import org.osgi.annotation.versioning.Version;
diff --git a/src/test/java/org/apache/sling/pipes/BasePipeTest.java b/src/test/java/org/apache/sling/pipes/BasePipeTest.java
index 833813a..a7adf13 100644
--- a/src/test/java/org/apache/sling/pipes/BasePipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/BasePipeTest.java
@@ -30,7 +30,6 @@ import java.util.ArrayList;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 public class BasePipeTest extends AbstractPipeTest {
diff --git a/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java b/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java
index 5b06d97..31021f1 100644
--- a/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/CommandExecutorImplTest.java
@@ -104,11 +104,13 @@ public class CommandExecutorImplTest extends AbstractPipeTest {
 
     @Test
     public void testKeyValueToArray() {
-        assertArrayEquals(new String[]{"one","two","three","four"}, keyValuesToArray(Arrays.asList("one=two","three=four")));
-        assertArrayEquals(new String[]{"one","two","three","${four}"}, keyValuesToArray(Arrays.asList("one=two","three=${four}")));
-        assertArrayEquals(new String[]{"one","two","three","${four == 'blah' ? 'five' : 'six'}"},
+        assertArrayEquals("1", new String[]{"one","two","three","four"}, keyValuesToArray(Arrays.asList("one=two","three=four")));
+        assertArrayEquals("2", new String[]{"one","two","three","${four}"}, keyValuesToArray(Arrays.asList("one=two","three=${four}")));
+        assertArrayEquals("3", new String[]{"${one == 'check'? 'three':'four'}","two"}, keyValuesToArray((Arrays.asList("${one == 'check'? 'three':'four'}=two"))));
+        assertArrayEquals("4", new String[]{"a_b-c","two"}, keyValuesToArray((Arrays.asList("a_b-c=two"))));
+        assertArrayEquals("5", new String[]{"one","two","three","${four == 'blah' ? 'five' : 'six'}"},
             keyValuesToArray(Arrays.asList("one=two","three=${four == 'blah' ? 'five' : 'six'}")));
-        assertArrayEquals(new String[]{"jcr:content/singer","${'ringo' == one ? false : true}"}, keyValuesToArray(Arrays.asList("jcr:content/singer=${'ringo' == one ? false : true}")));
+        assertArrayEquals("6", new String[]{"jcr:content/singer","${'ringo' == one ? false : true}"}, keyValuesToArray(Arrays.asList("jcr:content/singer=${'ringo' == one ? false : true}")));
     }
 
     @Test
diff --git a/src/test/java/org/apache/sling/pipes/internal/CommandUtilTest.java b/src/test/java/org/apache/sling/pipes/internal/CommandUtilTest.java
index 08dba0b..eaaf336 100644
--- a/src/test/java/org/apache/sling/pipes/internal/CommandUtilTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/CommandUtilTest.java
@@ -16,16 +16,41 @@
  */
 package org.apache.sling.pipes.internal;
 
+import static org.apache.sling.pipes.internal.CommandUtil.CONFIGURATION_PATTERN;
+import static org.apache.sling.pipes.internal.CommandUtil.FIRST_KEY;
+import static org.apache.sling.pipes.internal.CommandUtil.SECOND_KEY;
+
 import junit.framework.TestCase;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.junit.Assert;
 import org.junit.Test;
 
 public class CommandUtilTest extends TestCase {
 
+
+    private void assertMatch(Pattern pattern, String token, String first, String second) {
+        Matcher matcher = pattern.matcher(token);
+        assertTrue(pattern.toString() + " should match with " + token, matcher.matches());
+        assertEquals("first token should be " + first, first, matcher.group(FIRST_KEY));
+        assertEquals("second token should be " + second, second, matcher.group(SECOND_KEY));
+    }
+    @Test
+    public void testTokenMatch() {
+        assertMatch(CONFIGURATION_PATTERN, "foo=bar", "foo", "bar");
+        assertMatch(CONFIGURATION_PATTERN, "${foo}=bar", "${foo}", "bar");
+        assertMatch(CONFIGURATION_PATTERN, "foo=${bar}", "foo", "${bar}");
+        assertMatch(CONFIGURATION_PATTERN, "foo='bar'", "foo", "'bar'");
+        assertMatch(CONFIGURATION_PATTERN, "foo=${'bar'}", "foo", "${'bar'}");
+        assertMatch(CONFIGURATION_PATTERN, "${foo == bar ? 1 : 2}=bar", "${foo == bar ? 1 : 2}", "bar");
+        assertMatch(CONFIGURATION_PATTERN, "foo=${foo == bar ? 1 : 2}", "foo", "${foo == bar ? 1 : 2}");
+        assertMatch(CONFIGURATION_PATTERN, "foo/bar=check/some", "foo/bar", "check/some");
+        assertMatch(CONFIGURATION_PATTERN, "foo:bar='.+'", "foo:bar", "'.+'");
+    }
     @Test
     public void testEmbedIfNeeded() {
         assertEquals(2, CommandUtil.embedIfNeeded(2));
diff --git a/src/test/java/org/apache/sling/pipes/internal/FilterPipeTest.java b/src/test/java/org/apache/sling/pipes/internal/FilterPipeTest.java
index e8a86da..2151241 100644
--- a/src/test/java/org/apache/sling/pipes/internal/FilterPipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/FilterPipeTest.java
@@ -113,7 +113,7 @@ public class FilterPipeTest extends AbstractPipeTest {
 
     @Test
     public void testBadTestFails() throws InvocationTargetException, IllegalAccessException {
-        ExecutionResult result = execute("echo /content/fruits | grep slingPipesFilter_test=${'some string'}");
+        ExecutionResult result = execute("echo /content/fruits | grep slingPipesFilter_test=${'some string'}");
         assertEquals(0, result.size());
     }
 
diff --git a/src/test/java/org/apache/sling/pipes/internal/JCRWritePipeTest.java b/src/test/java/org/apache/sling/pipes/internal/JCRWritePipeTest.java
index 028e545..545efb5 100644
--- a/src/test/java/org/apache/sling/pipes/internal/JCRWritePipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/JCRWritePipeTest.java
@@ -35,7 +35,6 @@ import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
 import org.codehaus.plexus.util.CollectionUtils;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
diff --git a/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java b/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java
index 9fdb8a6..b5d5b9a 100644
--- a/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java
@@ -152,14 +152,10 @@ public class PlumberServletTest extends AbstractPipeTest {
 
     @Test
     public void testAdditionalBindingsAndWriter() throws Exception {
-        String testBinding = "testBinding";
-        String testBindingLength = testBinding + "Length";
-        String bindingValue = "testBindingValue";
-        String pathLengthParam = "pathLength";
-        String bindings = "{\"" + testBinding + "\":\"" + bindingValue + "\"}";
-        String respObject =  pathLengthParam + "=path.get(\"dummyGrandChild\").length()," + testBindingLength + "=" + testBinding + ".length()";
+        String bindings = "{\"testBinding\":\"testBindingValue\"}";
+        String respObject =  "pathLength=path.get(\"dummyGrandChild\").length(),testBindingValue=testBinding.length()";
         SlingHttpServletRequest request =
-                mockPlumberServletRequest(context.resourceResolver(), "json", dummyTreePath, null, bindings.toString(), respObject.toString(), null, null);
+                mockPlumberServletRequest(context.resourceResolver(), "json", dummyTreePath, null, bindings, respObject, null, null);
         servlet.execute(request, response, false);
         assertDummyTree();
         JsonObject response = Json.createReader(new StringReader(stringResponse.toString())).readObject();
@@ -169,13 +165,13 @@ public class PlumberServletTest extends AbstractPipeTest {
             assertNotNull("there should be an object returned at each time", object);
             String path = object.getString(OutputWriter.PATH_KEY);
             assertNotNull("the string path should be returned for each item, containing the path of the resource");
-            String pathLength = object.getString(pathLengthParam);
+            String pathLength = object.getString("pathLength");
             assertNotNull("there should be a pathLength param, as specified in the writer", pathLength);
             assertEquals("Pathlength should be the string representation of the path length", path.length() + "", pathLength);
-            String testBindingLengthValue = object.getString(testBindingLength);
+            String testBindingLengthValue = object.getString("testBindingValue", null);
             assertNotNull("testBindingLength should be there", testBindingLengthValue);
             assertEquals("testBindingLength should be the string representation of the additional binding length",
-                    bindingValue.length() + "", testBindingLengthValue);
+                    "testBindingValue".length() + "", testBindingLengthValue);
         }
     }
 
diff --git a/src/test/resources/simplelogger.properties b/src/test/resources/simplelogger.properties
index 0217e08..16018c4 100644
--- a/src/test/resources/simplelogger.properties
+++ b/src/test/resources/simplelogger.properties
@@ -15,7 +15,7 @@
 # limitations under the License.
 
 org.slf4j.simpleLogger.logFile=System.out
-org.slf4j.simpleLogger.defaultLogLevel=debug
+org.slf4j.simpleLogger.defaultLogLevel=off
 org.slf4j.simpleLogger.log.org.apache.jackrabbit.oak.plugins.index.IndexUpdate=warn
 org.slf4j.simpleLogger.log.org.apache.sling.scripting.core.impl.ScriptEngineManagerFactory=warn
 org.slf4j.simpleLogger.log.org.apache.sling.resourceresolver.impl.mapping.MapEntries=warn

[sling-org-apache-sling-pipes] 02/04: SLING-10419 add context in log (and test)

Posted by np...@apache.org.
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

commit f9f8289fb4225b933b9af7dc20b6fb9ac1c19318
Author: Nicolas Peltier <np...@apache.org>
AuthorDate: Wed Sep 15 15:35:54 2021 +0200

    SLING-10419 add context in log (and test)
---
 src/main/java/org/apache/sling/pipes/BasePipe.java         |  4 ++--
 src/test/java/org/apache/sling/pipes/PipeBindingsTest.java | 12 ++++++++++++
 src/test/resources/simplelogger.properties                 |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/pipes/BasePipe.java b/src/main/java/org/apache/sling/pipes/BasePipe.java
index 05a616c..09374c8 100644
--- a/src/main/java/org/apache/sling/pipes/BasePipe.java
+++ b/src/main/java/org/apache/sling/pipes/BasePipe.java
@@ -336,11 +336,11 @@ public class BasePipe implements Pipe {
             if (StringUtils.isBlank(path)){
                 Resource input = getPreviousResource();
                 if (input != null){
-                    path = resource.getPath();
+                    path = input.getPath();
                 }
             }
             bindings.setCurrentError(path);
-            logger.error("error with pipe execution from {}", path, e);
+            logger.error("error with pipe execution from {}, running on resource {}", resource.getPath(), path, e);
         }
         return EMPTY_ITERATOR;
     }
diff --git a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
index f6529ef..c669ed8 100644
--- a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
+++ b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
@@ -144,4 +144,16 @@ public class PipeBindingsTest extends AbstractPipeTest {
         assertTrue(result.size() > 0);
         assertEquals("/content/fruits/apple", result.currentPathSet.iterator().next());
     }
+
+    @Test
+    public void testContextualError() throws InvocationTargetException, IllegalAccessException {
+        ExecutionResult first = execute("json {'one':{'foo':'bar'},'two':{'another':'one'},'three':{'foo':'longer'}} | " +
+                "mkdir /content/context/${one.key} | " +
+                "write ${one.value.foo?'foo':'blah'}=one.value.foo");
+        //the following should fail for /content/context/two
+        ExecutionResult result = execute("echo /content/context " +
+                "| children sling:Folder @ name child " +
+                "| write foo=${child.foo?child.foo:nonexistingFunction(nonexistingVariable)}");
+        assertEquals(2, result.size());
+    }
 }
\ No newline at end of file
diff --git a/src/test/resources/simplelogger.properties b/src/test/resources/simplelogger.properties
index 16018c4..0217e08 100644
--- a/src/test/resources/simplelogger.properties
+++ b/src/test/resources/simplelogger.properties
@@ -15,7 +15,7 @@
 # limitations under the License.
 
 org.slf4j.simpleLogger.logFile=System.out
-org.slf4j.simpleLogger.defaultLogLevel=off
+org.slf4j.simpleLogger.defaultLogLevel=debug
 org.slf4j.simpleLogger.log.org.apache.jackrabbit.oak.plugins.index.IndexUpdate=warn
 org.slf4j.simpleLogger.log.org.apache.sling.scripting.core.impl.ScriptEngineManagerFactory=warn
 org.slf4j.simpleLogger.log.org.apache.sling.resourceresolver.impl.mapping.MapEntries=warn