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 2017/10/22 20:05:46 UTC

[sling-org-apache-sling-pipes] branch master updated: SLING-7172 introduce find pipe

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 8114899  SLING-7172 introduce find pipe
8114899 is described below

commit 8114899ed5cbf8e35c14c33522b91676567f1671
Author: npeltier <np...@adobe.com>
AuthorDate: Sun Oct 22 22:05:35 2017 +0200

    SLING-7172 introduce find pipe
---
 pom.xml                                            |  2 +-
 .../java/org/apache/sling/pipes/PipeBuilder.java   |  7 +++++
 .../sling/pipes/internal/PipeBuilderImpl.java      |  6 ++++
 .../apache/sling/pipes/internal/PlumberImpl.java   |  2 ++
 .../pipes/internal/slingQuery/ClosestPipe.java     | 16 ++++++++++
 .../sling/pipes/internal/slingQuery/FindPipe.java  | 36 ++++++++++++++++++++++
 .../pipes/internal/slingQuery/ClosestPipeTest.java | 16 ++++++++++
 .../org/apache/sling/pipes/it/PipeBuilderIT.java   |  4 ++-
 8 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8428c13..df7fbec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,7 +41,7 @@
   </properties>
 
   <scm>
-    <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git</conncetion>
+    <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git</connection>
     <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git</developerConnection>
     <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-pipes.git</url>
   </scm>
diff --git a/src/main/java/org/apache/sling/pipes/PipeBuilder.java b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
index b3357f4..51135bf 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBuilder.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
@@ -148,6 +148,13 @@ public interface PipeBuilder {
     PipeBuilder closest(String expr);
 
     /**
+     * attach a sling query find pipe to the current context
+     * @param expr expression
+     * @return updated instance of PipeBuilder
+     */
+    PipeBuilder $(String expr);
+
+    /**
      * attach a reference pipe to the current context
      * @param expr reference
      * @return updated instance of PipeBuilder
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 2319c7b..2f7a5fb 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
@@ -25,6 +25,7 @@ import org.apache.sling.event.jobs.Job;
 import org.apache.sling.pipes.*;
 import org.apache.sling.pipes.internal.slingQuery.ChildrenPipe;
 import org.apache.sling.pipes.internal.slingQuery.ClosestPipe;
+import org.apache.sling.pipes.internal.slingQuery.FindPipe;
 import org.apache.sling.pipes.internal.slingQuery.ParentPipe;
 import org.apache.sling.pipes.internal.slingQuery.ParentsPipe;
 import org.apache.sling.pipes.internal.slingQuery.SiblingsPipe;
@@ -182,6 +183,11 @@ public class PipeBuilderImpl implements PipeBuilder {
     }
 
     @Override
+    public PipeBuilder $(String expr) {
+        return pipeWithExpr(FindPipe.RESOURCE_TYPE, expr);
+    }
+
+    @Override
     public PipeBuilder ref(String expr) {
         return pipeWithExpr(ReferencePipe.RESOURCE_TYPE, expr);
     }
diff --git a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
index e2e6da2..7135a42 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
@@ -55,6 +55,7 @@ import org.apache.sling.event.jobs.consumer.JobConsumer;
 import org.apache.sling.pipes.*;
 import org.apache.sling.pipes.internal.slingQuery.ChildrenPipe;
 import org.apache.sling.pipes.internal.slingQuery.ClosestPipe;
+import org.apache.sling.pipes.internal.slingQuery.FindPipe;
 import org.apache.sling.pipes.internal.slingQuery.ParentPipe;
 import org.apache.sling.pipes.internal.slingQuery.ParentsPipe;
 import org.apache.sling.pipes.internal.slingQuery.SiblingsPipe;
@@ -128,6 +129,7 @@ public class PlumberImpl implements Plumber, JobConsumer {
         registerPipe(ParentPipe.RESOURCE_TYPE, ParentPipe.class);
         registerPipe(SiblingsPipe.RESOURCE_TYPE, SiblingsPipe.class);
         registerPipe(ClosestPipe.RESOURCE_TYPE, ClosestPipe.class);
+        registerPipe(FindPipe.RESOURCE_TYPE, FindPipe.class);
     }
 
     @Reference(policy= ReferencePolicy.DYNAMIC, cardinality= ReferenceCardinality.OPTIONAL)
diff --git a/src/main/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipe.java b/src/main/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipe.java
index 51f18a2..9b90633 100644
--- a/src/main/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipe.java
+++ b/src/main/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipe.java
@@ -1,3 +1,19 @@
+/*
+ * 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.slingQuery;
 
 import org.apache.sling.api.resource.Resource;
diff --git a/src/main/java/org/apache/sling/pipes/internal/slingQuery/FindPipe.java b/src/main/java/org/apache/sling/pipes/internal/slingQuery/FindPipe.java
new file mode 100644
index 0000000..9d2bef1
--- /dev/null
+++ b/src/main/java/org/apache/sling/pipes/internal/slingQuery/FindPipe.java
@@ -0,0 +1,36 @@
+/*
+ * 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.slingQuery;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.pipes.Plumber;
+import org.apache.sling.query.SlingQuery;
+
+import static org.apache.sling.query.SlingQuery.$;
+
+public class FindPipe extends AbstractExpressionSlingQueryPipe {
+    public static final String RESOURCE_TYPE = RT_PREFIX + "find";
+
+    public FindPipe(Plumber plumber, Resource resource) throws Exception {
+        super(plumber, resource);
+    }
+
+    @Override
+    protected SlingQuery getQuery(Resource resource, String expression) {
+        return $(resource).find(expression);
+    }
+}
diff --git a/src/test/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipeTest.java b/src/test/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipeTest.java
index 070cbfb..24e4cd6 100644
--- a/src/test/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/slingQuery/ClosestPipeTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.slingQuery;
 
 import org.apache.sling.pipes.AbstractPipeTest;
diff --git a/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java b/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
index 758110e..ec7b8eb 100644
--- a/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
+++ b/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
@@ -76,8 +76,10 @@ public class PipeBuilderIT extends PipesTestSupport {
                 plumber.newPipe(resolver).mkdir(path).write("xpathTestStatus", "testing").run();
             }
             final String query = String.format("/jcr:root%s//element(*,nt:base)[@xpathTestStatus]", ROOT);
-            final Set<String> results = plumber.newPipe(resolver).xpath(query).run();
+            Set<String> results = plumber.newPipe(resolver).xpath(query).run();
             assertEquals("xpath query should return as many items as we wrote", NB_ITEMS, results.size());
+            results = plumber.newPipe(resolver).echo(ROOT).$("nt:base[xpathTestStatus=testing]").run();
+            assertEquals("sling query should return as many items as we wrote", NB_ITEMS, results.size());
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].