You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2021/11/21 23:44:43 UTC
[sling-scriptingbundle-maven-plugin] branch issues/SLING-10934 created (now 91fee55)
This is an automated email from the ASF dual-hosted git repository.
pauls pushed a change to branch issues/SLING-10934
in repository https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git.
at 91fee55 SLING-10934: add the resourcelabel as a selector if it is the main script and has a method.
This branch includes the following new commits:
new 91fee55 SLING-10934: add the resourcelabel as a selector if it is the main script and has a method.
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-10934: add the resourcelabel as a selector if it is the main script and has a method.
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch issues/SLING-10934
in repository https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git
commit 91fee55c414df1a3df6307c3ce53b52e41076572
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Mon Nov 22 00:44:29 2021 +0100
SLING-10934: add the resourcelabel as a selector if it is the main script and has a method.
---
.../plugin/processor/FileProcessor.java | 7 +++--
.../plugin/processor/FileProcessorTest.java | 33 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
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 514b681..d7d1dbf 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
@@ -188,8 +188,11 @@ public class FileProcessor {
if (scriptEngine != null) {
String scriptName = script.getName();
Set<String> searchPathProcessesResourceTypes = processSearchPathResourceTypes(resourceType);
- if (scriptName != null && !resourceType.getResourceLabel().equals(scriptName)) {
- selectors.add(script.getName());
+ if (scriptName != null) {
+ if (!resourceType.getResourceLabel().equals(scriptName)
+ || script.getRequestMethod() != null) {
+ selectors.add(script.getName());
+ }
}
Optional<ProvidedResourceTypeCapability> extendsCapability = Optional.empty();
if (selectors.isEmpty() && StringUtils.isEmpty(script.getRequestExtension()) &&
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 fc1c57e..6b38dfe 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
@@ -125,6 +125,39 @@ public class FileProcessorTest {
}
@Test
+ public void testMainScriptSelector() {
+ Path resourceTypeFolder = Paths.get("apps", "my", "resource", "test");
+ Path script = Paths.get("apps", "my", "resource", "test", "test.POST.html");
+ processor.processScriptFile(resourceTypeFolder, script, MY_RESOURCE_TYPE, providedCapabilities, false);
+
+ Assert.assertEquals(1, providedCapabilities.size());
+
+ ProvidedResourceTypeCapability expectedProvidedCapability1 = ProvidedResourceTypeCapability.builder()
+ .withResourceTypes(new HashSet<>(Arrays.asList("my/resource", "/apps/my/resource")))
+ .withRequestMethod("POST")
+ .withSelectors(Arrays.asList("test"))
+ .withScriptEngine("htl")
+ .withScriptExtension("html")
+ .build();
+
+ Assert.assertEquals(new HashSet<>(Arrays.asList(expectedProvidedCapability1)), providedCapabilities);
+
+ Path script2 = Paths.get("apps", "my", "resource", "test", "POST.html");
+ processor.processScriptFile(resourceTypeFolder, script2, MY_RESOURCE_TYPE, providedCapabilities, false);
+
+ Assert.assertEquals(2, providedCapabilities.size());
+
+ ProvidedResourceTypeCapability expectedProvidedCapability2 = ProvidedResourceTypeCapability.builder()
+ .withResourceTypes(new HashSet<>(Arrays.asList("my/resource", "/apps/my/resource")))
+ .withRequestMethod("POST")
+ .withScriptEngine("htl")
+ .withScriptExtension("html")
+ .build();
+
+ Assert.assertEquals(new HashSet<>(Arrays.asList(expectedProvidedCapability1, expectedProvidedCapability2)), providedCapabilities);
+ }
+
+ @Test
public void testScriptUnknownExtension() {
Path resourceTypeFolder = Paths.get("scripts", "apps", "my", "resource", "2.0");
Path script = Paths.get("scripts", "apps", "my", "resource", "2.0", "selectorb", "selectora.POST.abc");