This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new a5f616c SLING-10934 - Bundled scripts in the form of
<resourceLabel>.<METHOD>.<extension> override the Sling POST Servlet
a5f616c is described below
commit a5f616c66c785da82aefa3bed906b4d17ca0465c
Author: Karl Pauls <[email protected]>
AuthorDate: Mon Nov 22 12:01:23 2021 +0100
SLING-10934 - Bundled scripts in the form of
<resourceLabel>.<METHOD>.<extension> override the Sling POST Servlet
---
.../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");