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:31:29 UTC

[sling-org-apache-sling-scripting-spi] 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-scripting-spi.git


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

commit eb8ea1c747f55415ec45ba1669fe8baf688da573
Author: Radu Cotescu <co...@adobe.com>
AuthorDate: Thu Apr 15 12:30:17 2021 +0200

    SLING-9999 - Remove cyclic dependency between scripting and servlets features
    
    * moved ResourceType to o.a.s.api.resource.type
---
 .../bundle => api/resource/type}/ResourceType.java | 12 ++++++------
 .../sling/api/resource/type/package-info.java      | 22 ++++++++++++++++++++++
 .../spi/bundle/BundledRenderUnitCapability.java    |  1 +
 .../spi/bundle/BundledRenderUnitFinder.java        |  1 +
 .../resource/type}/ResourceTypeTest.java           | 10 ++++++----
 5 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/spi/bundle/ResourceType.java b/src/main/java/org/apache/sling/api/resource/type/ResourceType.java
similarity index 96%
rename from src/main/java/org/apache/sling/scripting/spi/bundle/ResourceType.java
rename to src/main/java/org/apache/sling/api/resource/type/ResourceType.java
index de65928..7d974ef 100644
--- a/src/main/java/org/apache/sling/scripting/spi/bundle/ResourceType.java
+++ b/src/main/java/org/apache/sling/api/resource/type/ResourceType.java
@@ -16,7 +16,7 @@
  ~ specific language governing permissions and limitations
  ~ under the License.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.scripting.spi.bundle;
+package org.apache.sling.api.resource.type;
 
 import java.util.Objects;
 import java.util.regex.Pattern;
@@ -43,11 +43,11 @@ public final class ResourceType {
     private static final Pattern versionPattern = Pattern.compile("[\\d\\.]+(-.*)*$");
 
     private final String type;
-    private final String version;
+    private final Version version;
     private final String resourceLabel;
     private final String toString;
 
-    private ResourceType(@NotNull String type, @Nullable String version) {
+    private ResourceType(@NotNull String type, @Nullable Version version) {
         this.type = type;
         this.version = version;
         if (type.lastIndexOf('/') != -1) {
@@ -89,7 +89,7 @@ public final class ResourceType {
      * @return the version, if available; {@code null} otherwise
      */
     @Nullable
-    public String getVersion() {
+    public Version getVersion() {
         return version;
     }
 
@@ -116,14 +116,14 @@ public final class ResourceType {
     @NotNull
     public static ResourceType parseResourceType(@NotNull String resourceTypeString) {
         String type = StringUtils.EMPTY;
-        String version = null;
+        Version version = null;
         if (StringUtils.isNotEmpty(resourceTypeString)) {
             int lastSlash = resourceTypeString.lastIndexOf('/');
             if (lastSlash != -1 && !resourceTypeString.endsWith("/")) {
                 String versionString = resourceTypeString.substring(lastSlash + 1);
                 if (versionPattern.matcher(versionString).matches()) {
                     try {
-                        version = Version.parseVersion(versionString).toString();
+                        version = Version.parseVersion(versionString);
                         type = resourceTypeString.substring(0, lastSlash);
                     } catch (IllegalArgumentException e) {
                         type = resourceTypeString;
diff --git a/src/main/java/org/apache/sling/api/resource/type/package-info.java b/src/main/java/org/apache/sling/api/resource/type/package-info.java
new file mode 100644
index 0000000..515d14d
--- /dev/null
+++ b/src/main/java/org/apache/sling/api/resource/type/package-info.java
@@ -0,0 +1,22 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+@Version("1.0.0")
+package org.apache.sling.api.resource.type;
+
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitCapability.java b/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitCapability.java
index 079646a..8fd5788 100644
--- a/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitCapability.java
+++ b/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitCapability.java
@@ -21,6 +21,7 @@ package org.apache.sling.scripting.spi.bundle;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.sling.api.resource.type.ResourceType;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.osgi.annotation.versioning.ProviderType;
diff --git a/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitFinder.java b/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitFinder.java
index 0b0cffc..800c33d 100644
--- a/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitFinder.java
+++ b/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnitFinder.java
@@ -20,6 +20,7 @@ package org.apache.sling.scripting.spi.bundle;
 
 import java.util.Set;
 
+import org.apache.sling.api.resource.type.ResourceType;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.osgi.annotation.versioning.ConsumerType;
diff --git a/src/test/java/org/apache/sling/scripting/spi/bundle/ResourceTypeTest.java b/src/test/java/org/apache/sling/api/resource/type/ResourceTypeTest.java
similarity index 90%
rename from src/test/java/org/apache/sling/scripting/spi/bundle/ResourceTypeTest.java
rename to src/test/java/org/apache/sling/api/resource/type/ResourceTypeTest.java
index 149e2f2..6465105 100644
--- a/src/test/java/org/apache/sling/scripting/spi/bundle/ResourceTypeTest.java
+++ b/src/test/java/org/apache/sling/api/resource/type/ResourceTypeTest.java
@@ -16,10 +16,12 @@
  ~ specific language governing permissions and limitations
  ~ under the License.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.scripting.spi.bundle;
+package org.apache.sling.api.resource.type;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.type.ResourceType;
 import org.junit.Test;
+import org.osgi.framework.Version;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -39,7 +41,7 @@ public class ResourceTypeTest {
         ResourceType t1 = ResourceType.parseResourceType("a/b/c/1.0.0");
         assertEquals("a/b/c", t1.getType());
         assertEquals("c", t1.getResourceLabel());
-        assertEquals("1.0.0", t1.getVersion());
+        assertEquals(new Version("1.0.0"), t1.getVersion());
     }
 
     @Test
@@ -55,7 +57,7 @@ public class ResourceTypeTest {
         ResourceType t1 = ResourceType.parseResourceType("a/1.2.3");
         assertEquals("a", t1.getType());
         assertEquals("a", t1.getResourceLabel());
-        assertEquals("1.2.3", t1.getVersion());
+        assertEquals(new Version("1.2.3"), t1.getVersion());
     }
 
     @Test
@@ -71,7 +73,7 @@ public class ResourceTypeTest {
         ResourceType t1 = ResourceType.parseResourceType("a.b.c/42.0.0");
         assertEquals("a.b.c", t1.getType());
         assertEquals("c", t1.getResourceLabel());
-        assertEquals("42.0.0", t1.getVersion());
+        assertEquals(new Version("42.0.0"), t1.getVersion());
     }
 
     @Test(expected = IllegalArgumentException.class)