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/04/15 10:32:28 UTC

[sling-org-apache-sling-servlets-resolver] branch master updated: SLING-9999 - Remove cyclic dependency between scripting and servlets features

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-org-apache-sling-servlets-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 5a0d3fa  SLING-9999 - Remove cyclic dependency between scripting and servlets features
5a0d3fa is described below

commit 5a0d3fa2af7b05e4b0398d836c1546e59d6a8a7b
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Apr 15 12:32:01 2021 +0200

    SLING-9999 - Remove cyclic dependency between scripting and servlets features
    
    * moved ResourceType to o.a.s.api.resource.type
---
 pom.xml                                                |  2 +-
 .../bundle/BundledRenderUnitCapabilityImpl.java        |  4 ++--
 .../resolver/internal/bundle/BundledScriptServlet.java |  2 +-
 .../resolver/internal/bundle/BundledScriptTracker.java | 18 ++++++++++++------
 .../resolver/internal/bundle/RequestWrapper.java       |  2 +-
 5 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/pom.xml b/pom.xml
index 74d51bb..83cb8d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -182,7 +182,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.spi</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
+            <version>1.0.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
 
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledRenderUnitCapabilityImpl.java b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledRenderUnitCapabilityImpl.java
index b54c47d..04e0a53 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledRenderUnitCapabilityImpl.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledRenderUnitCapabilityImpl.java
@@ -27,10 +27,10 @@ import java.util.Objects;
 import java.util.Set;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.api.servlets.ServletResolverConstants;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.scripting.spi.bundle.BundledRenderUnitCapability;
-import org.apache.sling.scripting.spi.bundle.ResourceType;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.osgi.framework.Version;
@@ -173,7 +173,7 @@ class BundledRenderUnitCapabilityImpl  implements BundledRenderUnitCapability {
             if (version == null) {
                 resourceTypes.add(ResourceType.parseResourceType(rt));
             } else {
-                resourceTypes.add(ResourceType.parseResourceType(rt + "/" + version.toString()));
+                resourceTypes.add(ResourceType.parseResourceType(rt + "/" + version));
             }
         }
         return new BundledRenderUnitCapabilityImpl(
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptServlet.java b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptServlet.java
index fdfc308..4dfa0f2 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptServlet.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptServlet.java
@@ -33,8 +33,8 @@ import javax.servlet.ServletResponse;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.scripting.spi.bundle.BundledRenderUnit;
-import org.apache.sling.scripting.spi.bundle.ResourceType;
 import org.apache.sling.scripting.spi.bundle.TypeProvider;
 import org.jetbrains.annotations.NotNull;
 
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptTracker.java b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptTracker.java
index d785b76..0b71ba2 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptTracker.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/BundledScriptTracker.java
@@ -54,16 +54,17 @@ import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.request.RequestDispatcherOptions;
 import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.api.servlets.ServletResolverConstants;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.scripting.spi.bundle.BundledRenderUnit;
 import org.apache.sling.scripting.spi.bundle.BundledRenderUnitCapability;
 import org.apache.sling.scripting.spi.bundle.BundledRenderUnitFinder;
-import org.apache.sling.scripting.spi.bundle.ResourceType;
 import org.apache.sling.scripting.spi.bundle.TypeProvider;
 import org.apache.sling.servlets.resolver.internal.resource.ServletMounter;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.osgi.annotation.bundle.Capability;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -102,8 +103,6 @@ public class BundledScriptTracker implements BundleTrackerCustomizer<List<Servic
     public static final String AT_SCRIPT_ENGINE = "scriptEngine";
     public static final String AT_SCRIPT_EXTENSION = "scriptExtension";
     public static final String AT_EXTENDS = "extends";
-    private static final String[] DEFAULT_SERVLET_METHODS = {
-            HttpConstants.METHOD_GET, HttpConstants.METHOD_HEAD };
 
     @Reference
     private BundledRenderUnitFinder bundledRenderUnitFinder;
@@ -506,8 +505,15 @@ public class BundledScriptTracker implements BundleTrackerCustomizer<List<Servic
                                 .toStringArray(toProperties(right).get(ServletResolverConstants.SLING_SERVLET_SELECTORS), new String[0]))
                                 .containsAll(Arrays.asList(slingRequest.getRequestPathInfo().getSelectors()));
                         if ((la && ra) || (!la && !ra)) {
-                            return new Version(getResourceTypeVersion(right.getReference()))
-                                    .compareTo(new Version(getResourceTypeVersion(left.getReference())));
+                            Version rightVersion = getResourceTypeVersion(right.getReference());
+                            if (rightVersion == null) {
+                                rightVersion = Version.emptyVersion;
+                            }
+                            Version leftVersion = getResourceTypeVersion(left.getReference());
+                            if (leftVersion == null) {
+                                leftVersion = Version.emptyVersion;
+                            }
+                            return rightVersion.compareTo(leftVersion);
                         } else if (la) {
                             return -1;
                         } else {
@@ -548,7 +554,7 @@ public class BundledScriptTracker implements BundleTrackerCustomizer<List<Servic
         }
     }
 
-    private static String getResourceTypeVersion(ServiceReference<?> ref) {
+    private static @Nullable Version getResourceTypeVersion(ServiceReference<?> ref) {
         String[] values = PropertiesUtil.toStringArray(ref.getProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES));
         if (values != null) {
             String resourceTypeValue = values[0];
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/RequestWrapper.java b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/RequestWrapper.java
index 5b1e24a..d8d0b67 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/RequestWrapper.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/bundle/RequestWrapper.java
@@ -26,8 +26,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.request.RequestDispatcherOptions;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
-import org.apache.sling.scripting.spi.bundle.ResourceType;
 
 public class RequestWrapper extends SlingHttpServletRequestWrapper {