You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2019/05/29 16:20:29 UTC

[sling-maven-plugin] branch master updated: SLING-8449 sling-maven-plugin: Update to fsresource 2.1.16

This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 264caf5  SLING-8449 sling-maven-plugin: Update to fsresource 2.1.16
264caf5 is described below

commit 264caf56109e603a1b23cc18cf241a69159e0401
Author: sseifert <ss...@pro-vision.de>
AuthorDate: Wed May 29 18:20:17 2019 +0200

    SLING-8449 sling-maven-plugin: Update to fsresource 2.1.16
---
 sling-maven-plugin/pom.xml                         |  5 +++
 .../maven/bundlesupport/BundlePrerequisite.java    | 21 +++++++++
 .../sling/maven/bundlesupport/FsMountMojo.java     | 44 +++++++++++++-----
 .../bundlesupport/BundlePrerequisiteTest.java      | 52 ++++++++++++++++++++++
 4 files changed, 111 insertions(+), 11 deletions(-)

diff --git a/sling-maven-plugin/pom.xml b/sling-maven-plugin/pom.xml
index b79041c..58265ee 100644
--- a/sling-maven-plugin/pom.xml
+++ b/sling-maven-plugin/pom.xml
@@ -165,6 +165,11 @@
         </dependency>
 
         <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.osgi</artifactId>
             <version>2.4.0</version>
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundlePrerequisite.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundlePrerequisite.java
index d986a97..a6afbef 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundlePrerequisite.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundlePrerequisite.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
+import org.osgi.framework.Version;
 
 /**
  * Bundles that have to be installed as prerequisites to execute a goal.
@@ -77,6 +78,13 @@ public final class BundlePrerequisite {
             this.version = version;
         }
         
+        public Bundle(String groupId, String artifactId, String version, String symbolicName) {
+            this.groupId = groupId;
+            this.artifactId = artifactId;
+            this.version = version;
+            this.symbolicName = symbolicName;
+        }
+        
         public String getGroupId() {
             return groupId;
         }
@@ -109,6 +117,19 @@ public final class BundlePrerequisite {
             this.version = version;
         }
         
+        public String getOsgiVersion() {
+            if (this.version == null) {
+                return null;
+            }
+            // convert to three digit osgi version number
+            try {
+                return Version.parseVersion(this.version).toString();
+            }
+            catch (IllegalArgumentException ex) {
+                return this.version;
+            }
+        }
+        
     }
 
 }
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java
index 971f8ad..48c39b3 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java
@@ -56,14 +56,22 @@ import org.apache.sling.maven.bundlesupport.fsresource.SlingInitialContentMounte
 @Mojo(name = "fsmount", requiresProject = true)
 public class FsMountMojo extends AbstractFsMountMojo {
     
-    private static final String BUNDLE_GROUP_ID = "org.apache.sling"; 
+    private static final String BUNDLE_GROUP_ID = "org.apache.sling";
 
-    private static final String FS_BUNDLE_ARTIFACT_ID = "org.apache.sling.fsresource"; 
-    private static final String FS_BUNDLE_DEFAULT_VERSION = "2.1.14"; 
-    private static final String FS_BUNDLE_LEGACY_DEFAULT_VERSION = "1.4.8"; 
+    private static final String FS_BUNDLE_ARTIFACT_ID = "org.apache.sling.fsresource";
+    private static final String FS_BUNDLE_DEFAULT_VERSION = "2.1.15-SNAPSHOT";
+    private static final String FS_BUNDLE_LEGACY_DEFAULT_VERSION = "1.4.8";
     
-    private static final String RESOURCE_RESOLVER_BUNDLE_ARTIFACT_ID = "org.apache.sling.resourceresolver"; 
-    private static final String RESOURCE_RESOLVER_BUNDLE_MIN_VERSION = "1.5.18"; 
+    private static final String RESOURCE_RESOLVER_BUNDLE_ARTIFACT_ID = "org.apache.sling.resourceresolver";
+    private static final String RESOURCE_RESOLVER_BUNDLE_MIN_VERSION = "1.5.18";
+
+    private static final String JOHNZON_BUNDLE_ARTIFACT_ID = "org.apache.sling.commons.johnzon";
+    private static final String JOHNZON_BUNDLE_MIN_VERSION = "1.0.0";
+
+    private static final String COMMONS_COLLECTIONS4_BUNDLE_GROUP_ID = "org.apache.commons";
+    private static final String COMMONS_COLLECTIONS4_BUNDLE_ARTIFACT_ID = "commons-collections4";
+    private static final String COMMONS_COLLECTIONS4_BUNDLE_MIN_VERSION = "4.1";
+    private static final String COMMONS_COLLECTIONS4_BUNDLE_SYMBOLICNAME = "org.apache.commons.collections4";
 
     /**
      * Bundle deployment method. One of the following three values are allowed
@@ -102,8 +110,19 @@ public class FsMountMojo extends AbstractFsMountMojo {
      *     &lt;bundles&gt;
      *       &lt;bundle&gt;
      *         &lt;groupId&gt;org.apache.sling&lt;/groupId&gt;
+     *         &lt;artifactId&gt;org.apache.sling.commons.johnzon&lt;/artifactId&gt;
+     *         &lt;version&gt;1.0.0&lt;/version&gt;
+     *       &lt;/bundle&gt;
+     *       &lt;bundle&gt;
+     *         &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
+     *         &lt;artifactId&gt;commons-collections4&lt;/artifactId&gt;
+     *         &lt;version&gt;4.1&lt;/version&gt;
+     *         &lt;symbolicName&gt;org.apache.commons.collections4&lt;/symbolicName&gt;
+     *       &lt;/bundle&gt;
+     *       &lt;bundle&gt;
+     *         &lt;groupId&gt;org.apache.sling&lt;/groupId&gt;
      *         &lt;artifactId&gt;org.apache.sling.fsresource&lt;/artifactId&gt;
-     *         &lt;version&gt;2.1.14&lt;/version&gt;
+     *         &lt;version&gt;2.1.15-SNAPSHOT&lt;/version&gt;
      *       &lt;/bundle&gt;
      *     &lt;/bundles&gt;
      *     &lt;preconditions&gt;
@@ -162,6 +181,9 @@ public class FsMountMojo extends AbstractFsMountMojo {
         
         if (deployFsResourceBundlePrerequisites == null) {
             BundlePrerequisite latest = new BundlePrerequisite();
+            latest.addBundle(new Bundle(BUNDLE_GROUP_ID, JOHNZON_BUNDLE_ARTIFACT_ID, JOHNZON_BUNDLE_MIN_VERSION));
+            latest.addBundle(new Bundle(COMMONS_COLLECTIONS4_BUNDLE_GROUP_ID, COMMONS_COLLECTIONS4_BUNDLE_ARTIFACT_ID, 
+                    COMMONS_COLLECTIONS4_BUNDLE_MIN_VERSION, COMMONS_COLLECTIONS4_BUNDLE_SYMBOLICNAME));
             latest.addBundle(new Bundle(BUNDLE_GROUP_ID, FS_BUNDLE_ARTIFACT_ID, FS_BUNDLE_DEFAULT_VERSION));
             latest.addPrecondition(new Bundle(BUNDLE_GROUP_ID, RESOURCE_RESOLVER_BUNDLE_ARTIFACT_ID, RESOURCE_RESOLVER_BUNDLE_MIN_VERSION));
             addDeployFsResourceBundlePrerequisite(latest);
@@ -183,11 +205,11 @@ public class FsMountMojo extends AbstractFsMountMojo {
     
     private void deployBundle(Bundle bundle, String targetUrl) throws MojoExecutionException {
         if (isBundleInstalled(bundle, targetUrl)) {
-            getLog().debug("Bundle " + bundle.getSymbolicName() + " " + bundle.getVersion() + " (or higher) already installed.");
+            getLog().debug("Bundle " + bundle.getSymbolicName() + " " + bundle.getOsgiVersion() + " (or higher) already installed.");
             return;
         }
         
-        getLog().info("Installing Bundle " + bundle.getSymbolicName() + " " + bundle.getVersion() + " to "
+        getLog().info("Installing Bundle " + bundle.getSymbolicName() + " " + bundle.getOsgiVersion() + " to "
                     + targetUrl + " via " + deploymentMethod);
         
         File file = getArtifactFile(bundle, "jar");
@@ -200,7 +222,7 @@ public class FsMountMojo extends AbstractFsMountMojo {
     private boolean isBundlePrerequisitesPreconditionsMet(BundlePrerequisite bundlePrerequisite, String targetUrl) throws MojoExecutionException {
         for (Bundle precondition : bundlePrerequisite.getPreconditions()) {
             if (!isBundleInstalled(precondition, targetUrl)) {
-                getLog().debug("Bundle " + precondition.getSymbolicName() + " " + precondition.getVersion() + " (or higher) is not installed.");
+                getLog().debug("Bundle " + precondition.getSymbolicName() + " " + precondition.getOsgiVersion() + " (or higher) is not installed.");
                 return false;
             }
         }
@@ -213,7 +235,7 @@ public class FsMountMojo extends AbstractFsMountMojo {
             return false;
         }
         DefaultArtifactVersion installedVersion = new DefaultArtifactVersion(installedVersionString);
-        DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(bundle.getVersion());
+        DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(bundle.getOsgiVersion());
         return (installedVersion.compareTo(requiredVersion) >= 0);
     }
 
diff --git a/sling-maven-plugin/src/test/java/org/apache/sling/maven/bundlesupport/BundlePrerequisiteTest.java b/sling-maven-plugin/src/test/java/org/apache/sling/maven/bundlesupport/BundlePrerequisiteTest.java
new file mode 100644
index 0000000..08b6e76
--- /dev/null
+++ b/sling-maven-plugin/src/test/java/org/apache/sling/maven/bundlesupport/BundlePrerequisiteTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+package org.apache.sling.maven.bundlesupport;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.sling.maven.bundlesupport.BundlePrerequisite.Bundle;
+import org.junit.Test;
+
+public class BundlePrerequisiteTest {
+
+    @Test
+    public void testGetOsgiVersion() {
+        Bundle bundle1 = new Bundle();
+        bundle1.setVersion("1.2.3");
+        assertEquals("1.2.3", bundle1.getVersion());
+        assertEquals("1.2.3", bundle1.getOsgiVersion());
+    }
+
+    @Test
+    public void testGetOsgiVersion_ShortVersion() {
+        Bundle bundle1 = new Bundle();
+        bundle1.setVersion("1.2");
+        assertEquals("1.2", bundle1.getVersion());
+        assertEquals("1.2.0", bundle1.getOsgiVersion());
+    }
+
+    @Test
+    public void testGetOsgiVersion_SnapshotVersion() {
+        Bundle bundle1 = new Bundle();
+        bundle1.setVersion("1.2.3-SNAPSHOT");
+        assertEquals("1.2.3-SNAPSHOT", bundle1.getVersion());
+        assertEquals("1.2.3-SNAPSHOT", bundle1.getOsgiVersion());
+    }
+
+}