You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/08/12 10:15:40 UTC

[sling-scriptingbundle-maven-plugin] branch bugfix/same-name-selectors created (now 29734ef)

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

kwin pushed a change to branch bugfix/same-name-selectors
in repository https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git.


      at 29734ef  SLING-10726 support same name selectors

This branch includes the following new commits:

     new 29734ef  SLING-10726 support same name selectors

The 1 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.


[sling-scriptingbundle-maven-plugin] 01/01: SLING-10726 support same name selectors

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch bugfix/same-name-selectors
in repository https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git

commit 29734ef56f9fc8ec64dbf9f3f514c18f0db2986e
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Aug 12 12:15:30 2021 +0200

    SLING-10726 support same name selectors
---
 .../plugin/capability/Capabilities.java            |  3 +-
 .../capability/ProvidedResourceTypeCapability.java | 13 +++--
 .../capability/RequiredResourceTypeCapability.java |  4 +-
 .../plugin/processor/FileProcessor.java            |  3 +-
 .../scriptingbundle/plugin/AbstractPluginTest.java | 65 +++++++++++-----------
 .../plugin/processor/FileProcessorTest.java        |  2 +-
 .../org/apache/sling/foo/depth1/depth1/depth3.html | 18 ++++++
 7 files changed, 66 insertions(+), 42 deletions(-)

diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java
index e332ac4..299f362 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/Capabilities.java
@@ -20,6 +20,7 @@ package org.apache.sling.scriptingbundle.plugin.capability;
 
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
@@ -177,7 +178,7 @@ public class Capabilities {
         return new Capabilities(providedResourceTypeCapabilities, providedScriptCapabilities, requiredResourceTypeCapabilities);
     }
 
-    private void processListAttribute(@NotNull String capabilityAttribute, @NotNull StringBuilder builder, @NotNull Set<String> values) {
+    private void processListAttribute(@NotNull String capabilityAttribute, @NotNull StringBuilder builder, @NotNull Collection<String> values) {
         builder.append(capabilityAttribute).append("=").append("\"");
         int valuesSize = values.size();
         int valueIndex = 0;
diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java
index 2b425c7..ce2b68f 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java
@@ -20,6 +20,7 @@ package org.apache.sling.scriptingbundle.plugin.capability;
 
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 
@@ -36,12 +37,12 @@ public class ProvidedResourceTypeCapability {
     private final Version version;
     private final String requestExtension;
     private final String requestMethod;
-    private final Set<String> selectors;
+    private final List<String> selectors;
 
     private ProvidedResourceTypeCapability(@NotNull Set<String> resourceTypes, @Nullable String scriptEngine,
                                            @Nullable String scriptExtension, @Nullable String extendsResourceType,
                                            @Nullable Version version, @Nullable String requestExtension, @Nullable String requestMethod,
-                                           @NotNull Set<String> selectors) {
+                                           @NotNull List<String> selectors) {
         this.resourceTypes = resourceTypes;
         this.scriptEngine = scriptEngine;
         this.scriptExtension = scriptExtension;
@@ -92,8 +93,8 @@ public class ProvidedResourceTypeCapability {
     }
 
     @NotNull
-    public Set<String> getSelectors() {
-        return Collections.unmodifiableSet(selectors);
+    public List<String> getSelectors() {
+        return Collections.unmodifiableList(selectors);
     }
 
     @Override
@@ -138,7 +139,7 @@ public class ProvidedResourceTypeCapability {
         private Version version;
         private String requestExtension;
         private String requestMethod;
-        private Set<String> selectors = Collections.emptySet();
+        private List<String> selectors = Collections.emptyList();
 
         public Builder withResourceTypes(@NotNull Set<String> resourceTypes) {
             if (resourceTypes.isEmpty()) {
@@ -186,7 +187,7 @@ public class ProvidedResourceTypeCapability {
             return this;
         }
 
-        public Builder withSelectors(@NotNull Set<String> selectors) {
+        public Builder withSelectors(@NotNull List<String> selectors) {
             this.selectors = selectors;
             return this;
         }
diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java
index f35e267..7fbab3b 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java
@@ -18,8 +18,8 @@
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 package org.apache.sling.scriptingbundle.plugin.capability;
 
+import java.util.List;
 import java.util.Objects;
-import java.util.Set;
 
 import org.apache.commons.lang3.StringUtils;
 import org.jetbrains.annotations.NotNull;
@@ -58,7 +58,7 @@ public class RequiredResourceTypeCapability {
     }
 
     public boolean isSatisfied(@NotNull ProvidedResourceTypeCapability providedResourceTypeCapability) {
-        Set<String> providedSelectors = providedResourceTypeCapability.getSelectors();
+        List<String> providedSelectors = providedResourceTypeCapability.getSelectors();
         if (providedSelectors.isEmpty()) {
             for (String providedResourceType : providedResourceTypeCapability.getResourceTypes()) {
                 if (resourceType.equals(providedResourceType)) {
diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java
index dab50f7..ca2c8ae 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessor.java
@@ -23,6 +23,7 @@ import java.io.UncheckedIOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
@@ -155,7 +156,7 @@ public class FileProcessor {
             if (scriptFile != null) {
                 Path relativeResourceTypeFolder = resourceTypeDirectory.relativize(scriptPath);
                 int pathSegments = relativeResourceTypeFolder.getNameCount();
-                LinkedHashSet<String> selectors = new LinkedHashSet<>();
+                List<String> selectors = new ArrayList<>();
                 if (pathSegments > 1) {
                     for (int i = 0; i < pathSegments - 1; i++) {
                         selectors.add(relativeResourceTypeFolder.getName(i).toString());
diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java
index 7a8e181..fa35391 100644
--- a/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java
+++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.fail;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -54,27 +53,31 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
                             .withScriptExtension("html").withVersion(new Version("1.0.0")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "100"))).build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
+                            , "100")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "200"))).build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
+                            , "200")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "depth2", "100"))).build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
+                            , "depth2", "100")).build(),
     
                     // org/apache/sling/foo
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
                             .withScriptExtension("html").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
-                            .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "100"))).build(),
+                            .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
+                            , "100")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
-                            .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "200"))).build(),
+                            .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
+                            , "200")).build(),
+                            
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
-                            .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "depth2", "100"))).build(),
+                            .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
+                            , "depth1", "depth3")).build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
+                            .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
+                            , "depth2", "100")).build(),
     
                     // org/apache/sling/foo/depth1/depth2/depth3
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2/depth3")
@@ -82,43 +85,43 @@ public abstract class AbstractPluginTest {
                                     "/apache/sling/bar").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2/depth3")
                             .withScriptEngine("htl").withScriptExtension("html")
-                            .withSelectors(new LinkedHashSet<>(Arrays.asList("depth3-selector"))).build(),
+                            .withSelectors(Arrays.asList("depth3-selector")).build(),
     
                     // org.apache.sling.foobar/1.0.0
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
                             .withScriptExtension("html").withVersion(new Version("1.0.0")).withExtendsResourceType("org/apache/sling/bar").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "100"))).build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
+                            , "100")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "200"))).build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
+                            , "200")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "depth2", "100"))).build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
+                            , "depth2", "100")).build(),
     
                     // org.apache.sling.foobar
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar")
                             .withExtendsResourceType("org/apache/sling/bar").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "100"))).build(),
+                            .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
+                            , "100")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "200"))).build(),
+                            .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
+                            , "200")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
-                            , "depth2", "100"))).build(),
+                            .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
+                            , "depth2", "100")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
                             .withScriptExtension("html").withRequestMethod("GET").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withRequestMethod("GET").withSelectors(new LinkedHashSet<>(Arrays.asList("test")))
+                            .withScriptExtension("html").withRequestMethod("GET").withSelectors(Arrays.asList("test"))
                             .build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withRequestMethod("GET").withSelectors(new LinkedHashSet<>(Arrays.asList("test")))
+                            .withScriptExtension("html").withRequestMethod("GET").withSelectors(Arrays.asList("test"))
                             .withRequestExtension("txt").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withSelectors(new LinkedHashSet<>(Arrays.asList("test")))
+                            .withScriptExtension("html").withSelectors(Arrays.asList("test"))
                             .withRequestExtension("txt").build(),
     
                     // sling
@@ -161,7 +164,7 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test").withScriptEngine("thymeleaf")
                             .withScriptExtension("html").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test").withScriptEngine("rhino")
-                            .withScriptExtension("js").withSelectors(new HashSet<>(Arrays.asList("merged"))).build(),
+                            .withScriptExtension("js").withSelectors(Arrays.asList("merged")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test2").withScriptEngine("jsp")
                             .withScriptExtension("jsp").withRequestExtension("html").build()
             ));
@@ -192,7 +195,7 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("sling/scriptingbundle/includeexclude")
                             .withScriptEngine("htl").withScriptExtension("html").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("sling/scriptingbundle/includeexclude")
-                            .withSelectors(new HashSet<>(Arrays.asList("selector"))).withScriptEngine("htl").withScriptExtension("html")
+                            .withSelectors(Arrays.asList("selector")).withScriptEngine("htl").withScriptExtension("html")
                             .build()
             ));
             verifyCapabilities(capabilities, pExpected, Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java
index f692ee2..55e074c 100644
--- a/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java
+++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/processor/FileProcessorTest.java
@@ -117,7 +117,7 @@ public class FileProcessorTest {
                 .withResourceTypes(new HashSet<>(Arrays.asList("my/resource", "/apps/my/resource")))
                 .withVersion(MY_RESOURCE_TYPE.getVersion())
                 .withRequestMethod("POST")
-                .withSelectors(new HashSet<>(Arrays.asList("selectorb", "selectora")))
+                .withSelectors(Arrays.asList("selectorb", "selectora"))
                 .withScriptEngine("htl")
                 .withScriptExtension("html")
                 .build();
diff --git a/src/test/resources/project-1/src/main/scripts/org/apache/sling/foo/depth1/depth1/depth3.html b/src/test/resources/project-1/src/main/scripts/org/apache/sling/foo/depth1/depth1/depth3.html
new file mode 100644
index 0000000..2853663
--- /dev/null
+++ b/src/test/resources/project-1/src/main/scripts/org/apache/sling/foo/depth1/depth1/depth3.html
@@ -0,0 +1,18 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ 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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->