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 409b728 SLING-9540 shallow reference pipes
new 368325b Merge branch 'master' of
github.com:apache/sling-org-apache-sling-pipes
409b728 is described below
commit 409b7281919899244216a618c962156e9ee99b95
Author: Nicolas Peltier <[email protected]>
AuthorDate: Mon Jun 22 17:37:58 2020 +0200
SLING-9540 shallow reference pipes
some improvements in logs too
---
pom.xml | 4 +-
src/main/java/org/apache/sling/pipes/BasePipe.java | 7 ++-
.../java/org/apache/sling/pipes/PipeBuilder.java | 10 ++++
.../java/org/apache/sling/pipes/SuperPipe.java | 4 ++
.../sling/pipes/internal/PipeBuilderImpl.java | 5 ++
.../apache/sling/pipes/internal/ReferencePipe.java | 11 -----
.../sling/pipes/internal/ShallowReferencePipe.java | 46 ++++++++++++++++++
.../java/org/apache/sling/pipes/package-info.java | 2 +-
.../sling/pipes/internal/ReferencePipeTest.java | 18 +-------
...PipeTest.java => ShallowReferencePipeTest.java} | 54 ++++------------------
10 files changed, 85 insertions(+), 76 deletions(-)
diff --git a/pom.xml b/pom.xml
index ec7267a..d4afc07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,14 +29,14 @@
</parent>
<artifactId>org.apache.sling.pipes</artifactId>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.2.0-SNAPSHOT</version>
<name>Apache Sling Pipes</name>
<description>bulk content changes tool</description>
<properties>
<sling.java.version>8</sling.java.version>
- <org.ops4j.pax.exam.version>4.13.2</org.ops4j.pax.exam.version>
+ <org.ops4j.pax.exam.version>4.13.3</org.ops4j.pax.exam.version>
</properties>
<scm>
diff --git a/src/main/java/org/apache/sling/pipes/BasePipe.java
b/src/main/java/org/apache/sling/pipes/BasePipe.java
index d0fb576..732b164 100644
--- a/src/main/java/org/apache/sling/pipes/BasePipe.java
+++ b/src/main/java/org/apache/sling/pipes/BasePipe.java
@@ -35,6 +35,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.sling.pipes.PipeBindings.NN_ADDITIONALBINDINGS;
import static org.apache.sling.pipes.PipeBindings.NN_PROVIDERS;
import static org.apache.sling.pipes.PipeBindings.PN_ADDITIONALSCRIPTS;
@@ -154,6 +155,7 @@ public class BasePipe implements Pipe {
}
}
}
+ bindings.addBinding(getName(), EMPTY);
}
@Override
@@ -275,13 +277,14 @@ public class BasePipe implements Pipe {
if (StringUtils.isNotBlank(path)){
input = resolver.getResource(path);
if (input == null) {
- logger.warn("configured path {} is not found, expect some
troubles...", path);
+ logger.warn("configured path {} for {} is not found, expect
some troubles...", path, getName());
}
} else {
//no input has been configured: we explicitly expect input to come
from previous resource
input = getPreviousResource();
if (input == null) {
- logger.warn("no path has been configured, and no previous
resource to bind on, expect some troubles...");
+ logger.warn("no valid path has been configured for {}, and no
previous resource to bind on, expect some troubles...",
+ getName());
}
}
logger.debug("input for this pipe is {}", input != null ?
input.getPath() : null);
diff --git a/src/main/java/org/apache/sling/pipes/PipeBuilder.java
b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
index 8607bef..811a319 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBuilder.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
@@ -28,6 +28,7 @@ import org.apache.sling.pipes.internal.PackagePipe;
import org.apache.sling.pipes.internal.PathPipe;
import org.apache.sling.pipes.internal.ReferencePipe;
import org.apache.sling.pipes.internal.RemovePipe;
+import org.apache.sling.pipes.internal.ShallowReferencePipe;
import org.apache.sling.pipes.internal.TraversePipe;
import org.apache.sling.pipes.internal.WritePipe;
import org.apache.sling.pipes.internal.XPathPipe;
@@ -228,6 +229,15 @@ public interface PipeBuilder {
PipeBuilder ref(String expr);
/**
+ * attach a shallow reference pipe to the current context
+ * @param expr reference
+ * @return updated instance of PipeBuilder
+ */
+ @PipeExecutor(command = "shallowRef", resourceType =
ShallowReferencePipe.RESOURCE_TYPE, pipeClass = ShallowReferencePipe.class,
+ description = "shallow reference passed pipe, to be used for recursive
usage")
+ PipeBuilder shallowRef(String expr);
+
+ /**
* attach a package pipe, in filter collection mode as default
* @param expr path of the pipe
* @return updated instance of PipeBuilder
diff --git a/src/main/java/org/apache/sling/pipes/SuperPipe.java
b/src/main/java/org/apache/sling/pipes/SuperPipe.java
index 022fbcf..ef951b9 100644
--- a/src/main/java/org/apache/sling/pipes/SuperPipe.java
+++ b/src/main/java/org/apache/sling/pipes/SuperPipe.java
@@ -131,19 +131,23 @@ public abstract class SuperPipe extends BasePipe {
@Override
public void before() throws Exception {
+ LOG.debug("entering {} before", getName());
super.before();
if (subpipes.size() == 0){
buildChildren();
}
for (Pipe pipe : subpipes){
+ LOG.debug("calling {} before", getName());
pipe.before();
}
}
@Override
public void after() throws Exception {
+ LOG.debug("entering {} after", getName());
super.after();
for (Pipe pipe : subpipes){
+ LOG.debug("calling {} after", pipe.getName());
pipe.after();
}
}
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 7bf391b..3d092ec 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
@@ -216,6 +216,11 @@ public class PipeBuilderImpl implements PipeBuilder {
}
@Override
+ public PipeBuilder shallowRef(String expr) {
+ return pipeWithExpr(ShallowReferencePipe.RESOURCE_TYPE, expr);
+ }
+
+ @Override
public PipeBuilder mp() {
return pipe(MultiPropertyPipe.RESOURCE_TYPE);
}
diff --git a/src/main/java/org/apache/sling/pipes/internal/ReferencePipe.java
b/src/main/java/org/apache/sling/pipes/internal/ReferencePipe.java
index 1680c7d..2e18198 100644
--- a/src/main/java/org/apache/sling/pipes/internal/ReferencePipe.java
+++ b/src/main/java/org/apache/sling/pipes/internal/ReferencePipe.java
@@ -73,15 +73,4 @@ public class ReferencePipe extends SuperPipe {
log.debug("getting {} output", reference);
return reference.getOutput();
}
-
- @Override
- public void before() throws Exception {
- if (bindings.isPlainString(getRawExpression())){
- //we only support raw references, as there are good chances
- //compute fails at that stage
- super.before();
- } else {
- log.warn("before hook configured for this pipe's reference (and
descendants) will be ignored as we can't figure them out right now");
- }
- }
}
\ No newline at end of file
diff --git
a/src/main/java/org/apache/sling/pipes/internal/ShallowReferencePipe.java
b/src/main/java/org/apache/sling/pipes/internal/ShallowReferencePipe.java
new file mode 100644
index 0000000..bc80e5b
--- /dev/null
+++ b/src/main/java/org/apache/sling/pipes/internal/ShallowReferencePipe.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.pipes.internal;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.pipes.PipeBindings;
+import org.apache.sling.pipes.Plumber;
+
+/**
+ * specific reference pipe, to be used with dynamic reference usage,
specifically recursive ones
+ */
+public class ShallowReferencePipe extends ReferencePipe {
+ public static final String RESOURCE_TYPE = "slingPipes/shallow";
+
+ public ShallowReferencePipe(Plumber plumber, Resource resource,
PipeBindings upperBindings) throws Exception {
+ super(plumber, resource, upperBindings);
+ }
+
+ @Override
+ public boolean modifiesContent() {
+ //we assume some other pipes will take care of that status
+ return false;
+ }
+
+ @Override
+ public void before() throws Exception {
+ }
+
+ @Override
+ public void after() throws Exception {
+ }
+}
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 73d60cd..c9fb34c 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("3.1.0")
+@Version("3.2.0")
package org.apache.sling.pipes;
import org.osgi.annotation.versioning.Version;
diff --git
a/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
b/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
index d1a6eba..7d95805 100644
--- a/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
@@ -70,22 +70,8 @@ public class ReferencePipeTest extends AbstractPipeTest {
bindings.put("fruit", newFruit);
Pipe pipe =
plumber.newPipe(context.resourceResolver()).echo(PATH_FRUITS +
"/${fruit}").build();
Collection<String> paths = plumber.newPipe(context.resourceResolver())
- .ref(pipe.getResource().getPath())
- .run(bindings).getCurrentPathSet();
+ .ref(pipe.getResource().getPath())
+ .run(bindings).getCurrentPathSet();
assertTrue("paths should contain new path", paths.contains(newPath));
}
-
- @Test
- public void testDynamicBinding() throws Exception {
- plumber.newPipe(context.resourceResolver()).echo(PATH_FRUITS +
"/apple").build(PATH_PIPE + "/applePipe");
- plumber.newPipe(context.resourceResolver()).echo(PATH_FRUITS +
"/banana").build(PATH_PIPE + "/bananaPipe");
-
- ExecutionResult result = plumber.newPipe(context.resourceResolver())
- .json("['apple','banana']").name("fruit")
- .ref(PATH_PIPE + "/${fruit}Pipe")
- .run();
- assertEquals("there should be two outputs", 2, result.size());
- assertTrue("apple should be returned",
result.getCurrentPathSet().contains(PATH_FRUITS + "/apple"));
- assertTrue("banana should be returned",
result.getCurrentPathSet().contains(PATH_FRUITS + "/banana"));
- }
}
\ No newline at end of file
diff --git
a/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
b/src/test/java/org/apache/sling/pipes/internal/ShallowReferencePipeTest.java
similarity index 59%
copy from src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
copy to
src/test/java/org/apache/sling/pipes/internal/ShallowReferencePipeTest.java
index d1a6eba..801f8e8 100644
--- a/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
+++
b/src/test/java/org/apache/sling/pipes/internal/ShallowReferencePipeTest.java
@@ -16,6 +16,14 @@
*/
package org.apache.sling.pipes.internal;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.pipes.AbstractPipeTest;
import org.apache.sling.pipes.ExecutionResult;
@@ -23,18 +31,10 @@ import org.apache.sling.pipes.Pipe;
import org.junit.Before;
import org.junit.Test;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
/**
* testing references
*/
-public class ReferencePipeTest extends AbstractPipeTest {
+public class ShallowReferencePipeTest extends AbstractPipeTest {
@Before
public void setUp() throws Exception {
@@ -42,47 +42,13 @@ public class ReferencePipeTest extends AbstractPipeTest {
}
@Test
- public void testSimple() throws Exception {
- testOneResource(PATH_PIPE + "/" + NN_SIMPLE, PATH_APPLE);
- }
-
- @Test
- public void testRefersFailure() throws Exception {
- assertFalse("Reference a pipe with no result shouldn't have any
result", getOutput(PATH_PIPE + "/refersfailure").hasNext());
- }
-
- @Test
- public void testPathBinding() throws Exception {
- testOneResource(PATH_PIPE + "/testPathBinding", PATH_APPLE +
"/isnota/carrot");
- }
-
- @Test
- public void testValueBinding() throws Exception {
- testOneResource(PATH_PIPE + "/isAppleWormy", PATH_APPLE);
- }
-
- @Test
- public void testBuilderWithAdditionalBinding() throws Exception {
- String newFruit = "watermelon";
- String newPath = PATH_FRUITS + "/" + newFruit;
- ResourceUtil.getOrCreateResource(context.resourceResolver(), newPath,
"nt:unstructured", "nt:unstructured", true);
- Map bindings = new HashMap();
- bindings.put("fruit", newFruit);
- Pipe pipe =
plumber.newPipe(context.resourceResolver()).echo(PATH_FRUITS +
"/${fruit}").build();
- Collection<String> paths = plumber.newPipe(context.resourceResolver())
- .ref(pipe.getResource().getPath())
- .run(bindings).getCurrentPathSet();
- assertTrue("paths should contain new path", paths.contains(newPath));
- }
-
- @Test
public void testDynamicBinding() throws Exception {
plumber.newPipe(context.resourceResolver()).echo(PATH_FRUITS +
"/apple").build(PATH_PIPE + "/applePipe");
plumber.newPipe(context.resourceResolver()).echo(PATH_FRUITS +
"/banana").build(PATH_PIPE + "/bananaPipe");
ExecutionResult result = plumber.newPipe(context.resourceResolver())
.json("['apple','banana']").name("fruit")
- .ref(PATH_PIPE + "/${fruit}Pipe")
+ .shallowRef(PATH_PIPE + "/${fruit}Pipe")
.run();
assertEquals("there should be two outputs", 2, result.size());
assertTrue("apple should be returned",
result.getCurrentPathSet().contains(PATH_FRUITS + "/apple"));