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

[sling-scriptingbundle-maven-plugin] branch issue/SLING-10815 created (now 89eff7d)

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

radu pushed a change to branch issue/SLING-10815
in repository https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git.


      at 89eff7d  SLING-10815 - Do not require the presence of a similarly named script as the resource type label to create a capability

This branch includes the following new commits:

     new 89eff7d  SLING-10815 - Do not require the presence of a similarly named script as the resource type label to create a capability

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-10815 - Do not require the presence of a similarly named script as the resource type label to create a capability

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

radu pushed a commit to branch issue/SLING-10815
in repository https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git

commit 89eff7db38a0925e6f57f5db9e22c83f5f6666a7
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Sep 15 18:19:12 2021 +0200

    SLING-10815 - Do not require the presence of a similarly named script as the resource type label to create a capability
    
    * removed the artificial restriction
---
 .../processor/ResourceTypeFolderAnalyser.java      |  5 +--
 .../processor/ResourceTypeFolderPredicate.java     | 24 +---------
 .../scriptingbundle/plugin/AbstractPluginTest.java | 52 +++++++++++++++++++---
 3 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java
index b7b6820..b3b73b8 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java
@@ -70,13 +70,10 @@ public class ResourceTypeFolderAnalyser {
                                 fileProcessor.processScriptFile(resourceTypeDirectory, entry, resourceType, providedCapabilities);
                             }
                         }
-                    } else if (Files.isDirectory(entry) && !resourceTypeFolderPredicate.test(entry)) {
+                    } else if (Files.isDirectory(entry)) {
                         try (Stream<Path> selectorFilesStream = Files.walk(entry).filter(Files::isRegularFile).filter(file -> {
                             Path fileParent = file.getParent();
                             while (!resourceTypeDirectory.equals(fileParent)) {
-                                if (resourceTypeFolderPredicate.test(fileParent)) {
-                                    return false;
-                                }
                                 fileParent = fileParent.getParent();
                             }
                             return true;
diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java
index 684c685..e485f2d 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderPredicate.java
@@ -52,36 +52,14 @@ public class ResourceTypeFolderPredicate implements Predicate<Path> {
         } catch (IllegalArgumentException ignored) {
             // last segment does not denote a version
         }
-        String resourceTypeLabel;
         if (lastSegment != null) {
-            String lastSegmentString = lastSegment.toString();
-            int lastDotIndex = lastSegmentString.lastIndexOf('.');
-            if (lastDotIndex != -1 && lastDotIndex < lastSegmentString.length() - 1) {
-                resourceTypeLabel = lastSegmentString.substring(++lastDotIndex);
-            } else {
-                resourceTypeLabel = lastSegmentString;
-            }
             try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(folder, Files::isRegularFile)) {
                 for (Path path : directoryStream) {
                     Path fileName = path.getFileName();
                     if (fileName != null) {
                         String childName = fileName.toString();
                         Script script = Script.parseScript(childName);
-                        if (
-                            Constants.EXTENDS_FILE.equals(childName) ||
-                            (
-                                script != null &&
-                                (
-                                    resourceTypeLabel.equals(script.getName()) ||
-                                    (
-                                        script.getName() == null &&
-                                        (
-                                            "html".equals(script.getRequestExtension()) || "GET".equals(script.getRequestMethod())
-                                        )
-                                    )
-                                )
-                            )
-                        ) {
+                        if (Constants.EXTENDS_FILE.equals(childName) || script != null) {
                             return true;
                         }
                     }
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 9a96b9b..323a069 100644
--- a/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java
+++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/AbstractPluginTest.java
@@ -61,6 +61,12 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
                             .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
                             , "depth2", "100")).build(),
+
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar/1.0.0/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar/1.0.0/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("200").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar/1.0.0/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth2", "100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar/1.0.0/depth1/depth2").withScriptEngine("htl").withScriptExtension("html").withSelectors("100").build(),
+
     
                     // org/apache/sling/foo
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
@@ -78,7 +84,19 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl")
                             .withScriptExtension("html").withSelectors(Arrays.asList("depth1"
                             , "depth2", "100")).build(),
-    
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth1", "depth2", "depth3", "depth3-selector").build(),
+
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("200").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth1", "depth3").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth2", "100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth2", "depth3", "depth3-selector").build(),
+
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth3").build(),
+
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2").withScriptEngine("htl").withScriptExtension("html").withSelectors("100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth3", "depth3-selector").build(),
+
                     // org/apache/sling/foo/depth1/depth2/depth3
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/foo/depth1/depth2/depth3")
                             .withExtendsResourceType("org" +
@@ -99,6 +117,16 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
                             .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(Arrays.asList("depth1"
                             , "depth2", "100")).build(),
+
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/1.0.0/depth1").withScriptEngine(
+                            "htl").withScriptExtension("html").withSelectors("100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/1.0.0/depth1").withScriptEngine(
+                            "htl").withScriptExtension("html").withSelectors("200").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/1.0.0/depth1").withScriptEngine(
+                            "htl").withScriptExtension("html").withSelectors("depth2", "100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/1.0.0/depth1/depth2").withScriptEngine(
+                            "htl").withScriptExtension("html").withSelectors("100").build(),
+
     
                     // org.apache.sling.foobar
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar")
@@ -123,6 +151,15 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
                             .withScriptExtension("html").withSelectors(Arrays.asList("test"))
                             .withRequestExtension("txt").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors("1.0.0").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors("1.0.0", "depth1", "depth2", "100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors("1.0.0", "depth1", "100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl").withScriptExtension("html").withSelectors("1.0.0", "depth1", "200").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("200").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/depth1").withScriptEngine("htl").withScriptExtension("html").withSelectors("depth2", "100").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar/depth1/depth2").withScriptEngine("htl").withScriptExtension("html").withSelectors("100").build(),
+
     
                     // sling
                     ProvidedResourceTypeCapability.builder().withResourceType("sling").withScriptEngine("htl").withScriptExtension("html")
@@ -162,17 +199,17 @@ public abstract class AbstractPluginTest {
                     ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test").withScriptEngine("rhino")
                             .withScriptExtension("js").withSelectors(Arrays.asList("merged")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/test2").withScriptEngine("jsp")
-                            .withScriptExtension("jsp").withRequestExtension("html").build()
-            ));
-            Set<ProvidedScriptCapability> expectedScriptCapabilities = new HashSet<>(Arrays.asList(
-                    ProvidedScriptCapability.builder(scriptEngineMappings).withPath("/libs/sling/commons/template.html").build(),
-                    ProvidedScriptCapability.builder(scriptEngineMappings).withPath("/libs/sling/utils/initialiseWarpDrive.html").build()
+                            .withScriptExtension("jsp").withRequestExtension("html").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/commons").withScriptEngine("thymeleaf")
+                            .withScriptExtension("html").withSelectors("template").build(),
+                    ProvidedResourceTypeCapability.builder().withResourceType("libs/sling/utils").withScriptEngine("thymeleaf")
+                            .withScriptExtension("html").withSelectors("initialiseWarpDrive").build()
             ));
             Set<RequiredResourceTypeCapability> expectedRequired = new HashSet<>(Arrays.asList(
                     RequiredResourceTypeCapability.builder().withResourceType("sling/scripting/warpDrive")
                             .withVersionRange(VersionRange.valueOf("[1.0.0,2.0.0)")).withIsOptional().build()
             ));
-            verifyCapabilities(capabilities, pExpected, expectedRequired, expectedScriptCapabilities);
+            verifyCapabilities(capabilities, pExpected, expectedRequired, Collections.emptySet());
         } finally {
             cleanUp("project-2");
         }
@@ -273,5 +310,6 @@ public abstract class AbstractPluginTest {
         if (extraProvidedScripts.length() > 0) {
             fail(extraProvidedScripts.toString());
         }
+
     }
 }