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 2018/06/11 12:07:08 UTC
[sling-org-apache-sling-pipes] branch master updated: SLING-7722
fix container cut
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 e8681bc SLING-7722 fix container cut
e8681bc is described below
commit e8681bc84d19e56243c0debd10959906ec9d72db
Author: Nicolas Peltier <pe...@gmail.com>
AuthorDate: Mon Jun 11 14:06:39 2018 +0200
SLING-7722 fix container cut
- remove getConfiguredInput API (and implementation),
- changed to getComputedPath: either there is one in getInput and there better be a corresponding resource, either there is no and we can try getPrevious resource,
- add unit test
---
src/main/java/org/apache/sling/pipes/BasePipe.java | 50 +++++++++++++---------
src/main/java/org/apache/sling/pipes/Pipe.java | 6 ---
.../org/apache/sling/pipes/ContainerPipeTest.java | 14 ++++++
.../org/apache/sling/pipes/PipeBuilderTest.java | 5 ++-
4 files changed, 46 insertions(+), 29 deletions(-)
diff --git a/src/main/java/org/apache/sling/pipes/BasePipe.java b/src/main/java/org/apache/sling/pipes/BasePipe.java
index d797e9b..97f2e59 100644
--- a/src/main/java/org/apache/sling/pipes/BasePipe.java
+++ b/src/main/java/org/apache/sling/pipes/BasePipe.java
@@ -156,20 +156,18 @@ public class BasePipe implements Pipe {
return bindings.instantiateExpression(rawPath);
}
- @Override
- public Resource getConfiguredInput() throws ScriptException {
- Resource configuredInput = null;
+ /**
+ * @return computed path: getPath, with relative path taken in account
+ * @throws ScriptException
+ */
+ protected String getComputedPath() throws ScriptException {
String path = getPath();
- if (StringUtils.isNotBlank(path)){
- if (!isRootPath(path) && getPreviousResource() != null){
+ if (StringUtils.isNotBlank(path)) {
+ if (!isRootPath(path) && getPreviousResource() != null) {
path = getPreviousResource().getPath() + SLASH + path;
}
- configuredInput = resolver.getResource(path);
- if (configuredInput == null) {
- logger.warn("configured path {} is not found, expect some troubles...", path);
- }
}
- return configuredInput;
+ return path;
}
/**
@@ -203,20 +201,30 @@ public class BasePipe implements Pipe {
@Override
public Resource getInput() throws ScriptException {
- Resource resource = getConfiguredInput();
- if (resource == null) {
- resource = getPreviousResource();
+ String path = getComputedPath();
+ Resource input = null;
+ if (StringUtils.isNotBlank(path)){
+ input = resolver.getResource(path);
+ if (input == null) {
+ logger.warn("configured path {} is not found, expect some troubles...", path);
+ }
+ } else {
+ //no input has been configured: we explicitly expect input to come from previouse resource
+ input = getPreviousResource();
+ if (input == null) {
+ logger.warn("no path has been configured, and no previous resource to bind on, expect some troubles...");
+ }
}
- logger.debug("input for this pipe is {}", resource != null ? resource.getPath() : null);
- return resource;
+ logger.debug("input for this pipe is {}", input != null ? input.getPath() : null);
+ return input;
}
@Override
public Object getOutputBinding() {
if (parent != null){
- Resource resource = bindings.getExecutedResource(getName());
- if (resource != null) {
- return resource.adaptTo(ValueMap.class);
+ Resource output = bindings.getExecutedResource(getName());
+ if (output != null) {
+ return output.adaptTo(ValueMap.class);
}
}
return null;
@@ -254,9 +262,9 @@ public class BasePipe implements Pipe {
* @throws ScriptException
*/
protected Iterator<Resource> computeOutput() throws Exception {
- Resource resource = getInput();
- if (resource != null) {
- return Collections.singleton(resource).iterator();
+ Resource input = getInput();
+ if (input != null) {
+ return Collections.singleton(input).iterator();
}
return EMPTY_ITERATOR;
}
diff --git a/src/main/java/org/apache/sling/pipes/Pipe.java b/src/main/java/org/apache/sling/pipes/Pipe.java
index 652814d..a4d8940 100644
--- a/src/main/java/org/apache/sling/pipes/Pipe.java
+++ b/src/main/java/org/apache/sling/pipes/Pipe.java
@@ -83,12 +83,6 @@ public interface Pipe {
ContainerPipe getParent();
/**
- * Get the pipe's optional configured resource or null
- * @return input if configured
- */
- Resource getConfiguredInput() throws ScriptException;
-
- /**
* Get pipe current's resource *before* next execution, meaning either the
* configured resource, either previous' pipe output resource
* @return input, configured or previous pipe
diff --git a/src/test/java/org/apache/sling/pipes/ContainerPipeTest.java b/src/test/java/org/apache/sling/pipes/ContainerPipeTest.java
index 25486ed..acd991d 100644
--- a/src/test/java/org/apache/sling/pipes/ContainerPipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/ContainerPipeTest.java
@@ -103,6 +103,20 @@ public class ContainerPipeTest extends AbstractPipeTest {
assertTrue("There should be children", getOutput(PATH_PIPE + "/" + NN_ONEPIPE).hasNext());
}
+ /**
+ * one "empty" sub pipe in the middle of the execution should cut the pipe
+ */
+ @Test
+ public void testContainerCut() throws PersistenceException {
+ Pipe pipe = plumber.newPipe(context.resourceResolver())
+ .echo(PATH_FRUITS) //should return fruit root
+ .echo("nonexisting") // /content/fruits/nonexisting does not exist
+ .echo(PATH_APPLE) // existing apple
+ .build();
+ assertFalse("there should be no output to that pipe because some empty pipe is in the middle",
+ pipe.getOutput().hasNext());
+ }
+
@Test
public void testSleep() throws Exception {
long interval = 100L;
diff --git a/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java b/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
index 45f8a43..80b5924 100644
--- a/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
+++ b/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
@@ -37,8 +37,9 @@ import static org.junit.Assert.assertTrue;
public class PipeBuilderTest extends AbstractPipeTest {
@Test
public void simpleBuild() throws Exception {
- PipeBuilder rmBuilder = plumber.newPipe(context.resourceResolver());
- Pipe rmPipe = rmBuilder.echo(PATH_APPLE).rm().build();
+ Pipe rmPipe = plumber.newPipe(context.resourceResolver())
+ .echo(PATH_APPLE)
+ .rm().build();
assertNotNull(" a basePipe should be built", rmPipe);
//we rebuild basePipe out of created basePipe path, execute it, and test correct output (= correct basePipe built)
testOneResource(rmPipe.getResource().getPath(), PATH_FRUITS);
--
To stop receiving notification emails like this one, please contact
npeltier@apache.org.