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:33:40 UTC

[sling-scriptingbundle-maven-plugin] 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-scriptingbundle-maven-plugin.git


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

commit 32852c81b2dbeb8d9addb313b4b7d3b36a81536f
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Apr 15 12:33:19 2021 +0200

    SLING-9999 - Remove cyclic dependency between scripting and servlets features
    
    * moved ResourceType to o.a.s.api.resource.type
---
 pom.xml                                                 | 15 +++++++--------
 .../capability/ProvidedResourceTypeCapability.java      | 11 ++++++-----
 .../capability/RequiredResourceTypeCapability.java      |  6 +++---
 .../scriptingbundle/plugin/processor/FileProcessor.java | 10 +++++-----
 .../plugin/processor/ResourceTypeFolderAnalyser.java    |  2 +-
 .../plugin/bnd/BundledScriptsScannerPluginTest.java     | 17 +++++++++--------
 .../scriptingbundle/plugin/maven/MetadataMojoTest.java  | 17 +++++++++--------
 7 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/pom.xml b/pom.xml
index d840690..3623940 100644
--- a/pom.xml
+++ b/pom.xml
@@ -198,10 +198,16 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.framework</artifactId>
+            <version>1.8.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.spi</artifactId>
             <scope>compile</scope>
-            <version>1.0.0-SNAPSHOT</version>
+            <version>1.0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
@@ -211,13 +217,6 @@
         </dependency>
 
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.core</artifactId>
-            <version>7.0.0</version>
-            <scope>compile</scope>
-        </dependency>
-
-        <dependency>
             <groupId>biz.aQute.bnd</groupId>
             <artifactId>biz.aQute.bndlib</artifactId>
             <version>5.3.0</version>
diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java
index b8dac58..2b425c7 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/ProvidedResourceTypeCapability.java
@@ -26,20 +26,21 @@ import java.util.Set;
 import org.apache.commons.lang3.StringUtils;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.Version;
 
 public class ProvidedResourceTypeCapability {
     private final Set<String> resourceTypes;
     private final String scriptEngine;
     private final String scriptExtension;
     private final String extendsResourceType;
-    private final String version;
+    private final Version version;
     private final String requestExtension;
     private final String requestMethod;
     private final Set<String> selectors;
 
     private ProvidedResourceTypeCapability(@NotNull Set<String> resourceTypes, @Nullable String scriptEngine,
                                            @Nullable String scriptExtension, @Nullable String extendsResourceType,
-                                           @Nullable String version, @Nullable String requestExtension, @Nullable String requestMethod,
+                                           @Nullable Version version, @Nullable String requestExtension, @Nullable String requestMethod,
                                            @NotNull Set<String> selectors) {
         this.resourceTypes = resourceTypes;
         this.scriptEngine = scriptEngine;
@@ -71,7 +72,7 @@ public class ProvidedResourceTypeCapability {
     }
 
     @Nullable
-    public String getVersion() {
+    public Version getVersion() {
         return version;
     }
 
@@ -134,7 +135,7 @@ public class ProvidedResourceTypeCapability {
         private String scriptEngine;
         private String scriptExtension;
         private String extendsResourceType;
-        private String version;
+        private Version version;
         private String requestExtension;
         private String requestMethod;
         private Set<String> selectors = Collections.emptySet();
@@ -170,7 +171,7 @@ public class ProvidedResourceTypeCapability {
             return this;
         }
 
-        public Builder withVersion(String version) {
+        public Builder withVersion(Version version) {
             this.version = version;
             return this;
         }
diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java
index 5e97ddc..54243ac 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/capability/RequiredResourceTypeCapability.java
@@ -59,9 +59,9 @@ public class RequiredResourceTypeCapability {
                     if (versionRange == null) {
                         return true;
                     } else {
-                        String providedVersion = providedResourceTypeCapability.getVersion();
-                        if (StringUtils.isNotEmpty(providedVersion)) {
-                            return versionRange.includes(Version.parseVersion(providedVersion));
+                        Version providedVersion = providedResourceTypeCapability.getVersion();
+                        if (providedVersion != null) {
+                            return versionRange.includes(providedVersion);
                         }
                     }
                 }
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 740a70f..d3d9a85 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
@@ -31,7 +31,7 @@ import java.util.Set;
 
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.sling.scripting.spi.bundle.ResourceType;
+import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.scriptingbundle.plugin.capability.ProvidedResourceTypeCapability;
 import org.apache.sling.scriptingbundle.plugin.capability.RequiredResourceTypeCapability;
 import org.jetbrains.annotations.NotNull;
@@ -163,13 +163,13 @@ public class FileProcessor {
                         );
                         providedCapabilities.add(builder.build());
                     } else {
-                        log.warn(String.format("Cannot find a script engine mapping for script %s.", scriptPath.toString()));
+                        log.warn(String.format("Cannot find a script engine mapping for script %s.", scriptPath));
                     }
                 } else {
-                    log.warn(String.format("File %s does not denote a script.", scriptPath.toString()));
+                    log.warn(String.format("File %s does not denote a script.", scriptPath));
                 }
             } else {
-                log.warn(String.format("Skipping path %s since it has 0 elements.", scriptPath.toString()));
+                log.warn(String.format("Skipping path %s since it has 0 elements.", scriptPath));
             }
         }
     }
@@ -199,7 +199,7 @@ public class FileProcessor {
                 requiredBuilder.withVersionRange(VersionRange.valueOf(version.substring(version.indexOf('=') + 1)));
             }
         } catch (IllegalArgumentException ignored) {
-            log.warn(String.format("Invalid version range format %s in file %s.", version, requiresFile.toString()));
+            log.warn(String.format("Invalid version range format %s in file %s.", version, requiresFile));
         }
     }
 }
diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java
index c135a3b..8eff945 100644
--- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java
+++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java
@@ -28,7 +28,7 @@ import java.util.Set;
 import java.util.stream.Stream;
 
 import org.apache.commons.io.FilenameUtils;
-import org.apache.sling.scripting.spi.bundle.ResourceType;
+import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.scriptingbundle.plugin.capability.Capabilities;
 import org.apache.sling.scriptingbundle.plugin.capability.ProvidedResourceTypeCapability;
 import org.apache.sling.scriptingbundle.plugin.capability.RequiredResourceTypeCapability;
diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java
index f8ea64a..05b2033 100644
--- a/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java
+++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPluginTest.java
@@ -38,6 +38,7 @@ import org.apache.sling.scriptingbundle.plugin.capability.ProvidedScriptCapabili
 import org.apache.sling.scriptingbundle.plugin.capability.RequiredResourceTypeCapability;
 import org.apache.sling.scriptingbundle.plugin.bnd.BundledScriptsScannerPlugin;
 import org.junit.Test;
+import org.osgi.framework.Version;
 import org.osgi.framework.VersionRange;
 
 import aQute.bnd.osgi.Builder;
@@ -60,15 +61,15 @@ public class BundledScriptsScannerPluginTest {
             Set<ProvidedResourceTypeCapability> pExpected = new HashSet<>(Arrays.asList(
                     // org/apache/sling/bar/1.0.0
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "100"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "200"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "depth2", "100"))).build(),
 
                     // org/apache/sling/foo
@@ -94,15 +95,15 @@ public class BundledScriptsScannerPluginTest {
 
                     // org.apache.sling.foobar/1.0.0
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withExtendsResourceType("org/apache/sling/bar").build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withExtendsResourceType("org/apache/sling/bar").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "100"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "200"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "depth2", "100"))).build(),
 
                     // org.apache.sling.foobar
diff --git a/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java b/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java
index b943c45..911ecbc 100644
--- a/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java
+++ b/src/test/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojoTest.java
@@ -39,6 +39,7 @@ import org.apache.sling.scriptingbundle.plugin.capability.RequiredResourceTypeCa
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
+import org.osgi.framework.Version;
 import org.osgi.framework.VersionRange;
 
 import static org.junit.Assert.assertEquals;
@@ -63,15 +64,15 @@ public class MetadataMojoTest {
             Set<ProvidedResourceTypeCapability> pExpected = new HashSet<>(Arrays.asList(
                     // org/apache/sling/bar/1.0.0
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "100"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "200"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org/apache/sling/bar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "depth2", "100"))).build(),
 
                     // org/apache/sling/foo
@@ -97,15 +98,15 @@ public class MetadataMojoTest {
 
                     // org.apache.sling.foobar/1.0.0
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withExtendsResourceType("org/apache/sling/bar").build(),
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withExtendsResourceType("org/apache/sling/bar").build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "100"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "200"))).build(),
                     ProvidedResourceTypeCapability.builder().withResourceType("org.apache.sling.foobar").withScriptEngine("htl")
-                            .withScriptExtension("html").withVersion("1.0.0").withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
+                            .withScriptExtension("html").withVersion(new Version("1.0.0")).withSelectors(new LinkedHashSet<>(Arrays.asList("depth1"
                             , "depth2", "100"))).build(),
 
                     // org.apache.sling.foobar