This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git
The following commit(s) were added to refs/heads/master by this push:
new 6bed827 SLING-12643 : Support Jakarta ServletAPI in Scripting
(Initial support)
6bed827 is described below
commit 6bed827cfc452ec5f344794f5455eeb62921db3b
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Thu Apr 24 07:26:36 2025 +0200
SLING-12643 : Support Jakarta ServletAPI in Scripting (Initial support)
---
pom.xml | 65 ++++++++++------------
.../impl/bundled/BundleRenderUnitFinderImpl.java | 23 ++++----
.../core/impl/bundled/PrecompiledScript.java | 3 +-
.../sling/scripting/core/it/HtmlScriptingIT.java | 6 +-
4 files changed, 44 insertions(+), 53 deletions(-)
diff --git a/pom.xml b/pom.xml
index 43388b1..ad39458 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,12 +53,6 @@
<version>2.0.17</version>
<scope>provided</scope>
</dependency>
- <!-- javax -->
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@@ -121,12 +115,6 @@
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.17.0</version>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
@@ -139,24 +127,12 @@
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.resource.presence</artifactId>
- <version>0.0.2</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.serviceusermapper</artifactId>
<version>1.5.8</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>4.1.1-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
<!-- OSGi -->
<dependency>
<groupId>org.osgi</groupId>
@@ -203,41 +179,65 @@
<scope>provided</scope>
</dependency>
+ <!-- Testing -->
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.17.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.resource.presence</artifactId>
+ <version>0.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.paxexam</artifactId>
+ <version>4.1.2</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.17</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.testing</artifactId>
<version>2.1.2</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>7.0.5</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-osgi</artifactId>
<version>4.5.8</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
<version>3.2.2</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
@@ -250,7 +250,6 @@
</exclusion>
</exclusions>
</dependency>
-
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@@ -264,12 +263,6 @@
<version>1.15.3</version>
<scope>test</scope>
</dependency>
- <!-- testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
diff --git
a/src/main/java/org/apache/sling/scripting/core/impl/bundled/BundleRenderUnitFinderImpl.java
b/src/main/java/org/apache/sling/scripting/core/impl/bundled/BundleRenderUnitFinderImpl.java
index 3ba8327..9ebb8f4 100644
---
a/src/main/java/org/apache/sling/scripting/core/impl/bundled/BundleRenderUnitFinderImpl.java
+++
b/src/main/java/org/apache/sling/scripting/core/impl/bundled/BundleRenderUnitFinderImpl.java
@@ -27,7 +27,6 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.type.ResourceType;
import org.apache.sling.commons.compiler.source.JavaEscapeHelper;
import org.apache.sling.scripting.core.impl.ServiceCache;
@@ -73,7 +72,7 @@ public class BundleRenderUnitFinderImpl implements
BundledRenderUnitFinder, Bund
capability.getExtension())) {
String scriptExtension = capability.getScriptExtension();
String scriptEngineName = capability.getScriptEngineName();
- if (StringUtils.isNotEmpty(scriptExtension) &&
StringUtils.isNotEmpty(scriptEngineName)) {
+ if (scriptExtension != null && scriptEngineName != null) {
BundledRenderUnit executable = getExecutable(
context, provider.getBundle(), match,
scriptEngineName, scriptExtension, allProviders);
if (executable != null) {
@@ -93,9 +92,7 @@ public class BundleRenderUnitFinderImpl implements
BundledRenderUnitFinder, Bund
String path = capability.getPath();
String scriptEngineName = capability.getScriptEngineName();
String scriptExtension = capability.getScriptExtension();
- if (StringUtils.isNotEmpty(path)
- && StringUtils.isNotEmpty(scriptEngineName)
- && StringUtils.isNotEmpty(scriptExtension)) {
+ if (path != null && scriptEngineName != null && scriptExtension !=
null) {
return findUnit(context, provider.getBundle(), path,
scriptEngineName, scriptExtension, providers);
}
return null;
@@ -168,13 +165,13 @@ public class BundleRenderUnitFinderImpl implements
BundledRenderUnitFinder, Bund
String base = resourceType.getType()
+ (resourceType.getVersion() != null ? SLASH +
resourceType.getVersion() + SLASH : SLASH)
+ String.join(SLASH, Arrays.copyOf(selectors, i +
1));
- if (StringUtils.isNotEmpty(extension)) {
- if (StringUtils.isNotEmpty(method)) {
+ if (extension != null) {
+ if (method != null) {
matches.add(base + DOT + extension + DOT + method);
}
matches.add(base + DOT + extension);
}
- if (StringUtils.isNotEmpty(method)) {
+ if (method != null) {
matches.add(base + DOT + method);
matches.add(base + SLASH + method);
}
@@ -182,19 +179,19 @@ public class BundleRenderUnitFinderImpl implements
BundledRenderUnitFinder, Bund
}
}
String base = resourceType.getType()
- + (resourceType.getVersion() != null ? SLASH +
resourceType.getVersion() : StringUtils.EMPTY);
+ + (resourceType.getVersion() != null ? SLASH +
resourceType.getVersion() : "");
- if (StringUtils.isNotEmpty(extension)) {
- if (StringUtils.isNotEmpty(method)) {
+ if (extension != null) {
+ if (method != null) {
matches.add(base + SLASH + resourceType.getResourceLabel()
+ DOT + extension + DOT + method);
}
matches.add(base + SLASH + resourceType.getResourceLabel() +
DOT + extension);
}
- if (StringUtils.isNotEmpty(method)) {
+ if (method != null) {
matches.add(base + SLASH + method);
matches.add(base + SLASH + resourceType.getResourceLabel() +
DOT + method);
}
- if (StringUtils.isNotEmpty(extension)) {
+ if (extension != null) {
matches.add(base + SLASH + extension);
}
matches.add(base + SLASH + resourceType.getResourceLabel());
diff --git
a/src/main/java/org/apache/sling/scripting/core/impl/bundled/PrecompiledScript.java
b/src/main/java/org/apache/sling/scripting/core/impl/bundled/PrecompiledScript.java
index a87b696..81b5b4d 100644
---
a/src/main/java/org/apache/sling/scripting/core/impl/bundled/PrecompiledScript.java
+++
b/src/main/java/org/apache/sling/scripting/core/impl/bundled/PrecompiledScript.java
@@ -25,7 +25,6 @@ import javax.script.ScriptException;
import java.io.StringReader;
import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
import org.apache.sling.scripting.core.impl.ServiceCache;
import org.apache.sling.scripting.spi.bundle.TypeProvider;
import org.jetbrains.annotations.NotNull;
@@ -34,7 +33,7 @@ import org.osgi.framework.BundleContext;
class PrecompiledScript extends AbstractBundledRenderUnit {
- private static final StringReader EMPTY_READER = new
StringReader(StringUtils.EMPTY);
+ private static final StringReader EMPTY_READER = new StringReader("");
private final Class<?> clazz;
private volatile Object instance;
diff --git
a/src/test/java/org/apache/sling/scripting/core/it/HtmlScriptingIT.java
b/src/test/java/org/apache/sling/scripting/core/it/HtmlScriptingIT.java
index c24eb87..9628aa2 100644
--- a/src/test/java/org/apache/sling/scripting/core/it/HtmlScriptingIT.java
+++ b/src/test/java/org/apache/sling/scripting/core/it/HtmlScriptingIT.java
@@ -43,6 +43,7 @@ import org.ops4j.pax.exam.util.Filter;
import org.ops4j.pax.tinybundles.TinyBundle;
import org.osgi.service.http.HttpService;
+import static org.apache.sling.testing.paxexam.SlingOptions.spifly;
import static org.junit.Assert.assertEquals;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
@@ -663,6 +664,7 @@ public class HtmlScriptingIT extends
ScriptingCoreTestSupport {
final String workingDirectory = workingDirectory();
return options(composite(
super.baseConfiguration(),
+ spifly(),
mavenBundle()
.groupId("org.apache.sling")
.artifactId("org.apache.sling.commons.johnzon")
@@ -806,13 +808,13 @@ public class HtmlScriptingIT extends
ScriptingCoreTestSupport {
public void testHtlTitle() throws IOException {
final String url =
String.format("http://localhost:%s/scripting/htl.html", httpPort());
final Document document = Jsoup.connect(url).get();
- assertEquals(document.title(), "Sling Scripting HTL");
+ assertEquals("Sling Scripting HTL", document.title());
}
@Test
public void testThymeleafTitle() throws IOException {
final String url =
String.format("http://localhost:%s/scripting/thymeleaf.html", httpPort());
final Document document = Jsoup.connect(url).get();
- assertEquals(document.title(), "Sling Scripting Thymeleaf");
+ assertEquals("Sling Scripting Thymeleaf", document.title());
}
}