You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2019/12/17 10:03:52 UTC

[sling-org-apache-sling-feature] branch master updated: SLING-8926 : Add ArtifactId.toMvnName

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-feature.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f0ec52  SLING-8926 : Add ArtifactId.toMvnName
3f0ec52 is described below

commit 3f0ec52aad081c76a9b4093d4ff2851044dd2b2e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Dec 17 11:03:07 2019 +0100

    SLING-8926 : Add ArtifactId.toMvnName
---
 .../java/org/apache/sling/feature/ArtifactId.java  | 39 ++++++++++++++++------
 .../org/apache/sling/feature/package-info.java     |  2 +-
 .../org/apache/sling/feature/ArtifactIdTest.java   | 20 ++++++++++-
 3 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/ArtifactId.java b/src/main/java/org/apache/sling/feature/ArtifactId.java
index 44f07a8..871e008 100644
--- a/src/main/java/org/apache/sling/feature/ArtifactId.java
+++ b/src/main/java/org/apache/sling/feature/ArtifactId.java
@@ -359,18 +359,16 @@ public class ArtifactId implements Comparable<ArtifactId> {
         return new Version(majorVersion, minorVersion, microVersion, qualifier);
     }
 
-    /**
-     * Create a Maven like relative repository path.
-     * @return A relative repository path. The path does not start with a slash.
-     */
-    public String toMvnPath() {
+    private String toMvnName(final boolean includePath) {
         final StringBuilder sb = new StringBuilder();
-        sb.append(groupId.replace('.', '/'));
-        sb.append('/');
-        sb.append(artifactId);
-        sb.append('/');
-        sb.append(version);
-        sb.append('/');
+        if (includePath) {
+            sb.append(groupId.replace('.', '/'));
+            sb.append('/');
+            sb.append(artifactId);
+            sb.append('/');
+            sb.append(version);
+            sb.append('/');
+        }
         sb.append(artifactId);
         sb.append('-');
         sb.append(version);
@@ -383,6 +381,25 @@ public class ArtifactId implements Comparable<ArtifactId> {
         return sb.toString();
     }
 
+    /**
+     * Create a Maven like relative repository path.
+     *
+     * @return A relative repository path. The path does not start with a slash.
+     */
+    public String toMvnPath() {
+        return toMvnName(true);
+    }
+
+    /**
+     * Create a Maven like repository name
+     *
+     * @return Just the name of the artifact (including version, classifier, type)
+     * @since 1.2
+     */
+    public String toMvnName() {
+        return toMvnName(false);
+    }
+
     @Override
     public int hashCode() {
         return toMvnUrl().hashCode();
diff --git a/src/main/java/org/apache/sling/feature/package-info.java b/src/main/java/org/apache/sling/feature/package-info.java
index 0d0b8c1..e3f3716 100644
--- a/src/main/java/org/apache/sling/feature/package-info.java
+++ b/src/main/java/org/apache/sling/feature/package-info.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@org.osgi.annotation.versioning.Version("1.1.0")
+@org.osgi.annotation.versioning.Version("1.2.0")
 package org.apache.sling.feature;
 
 
diff --git a/src/test/java/org/apache/sling/feature/ArtifactIdTest.java b/src/test/java/org/apache/sling/feature/ArtifactIdTest.java
index 7e0f9cc..cdcad78 100644
--- a/src/test/java/org/apache/sling/feature/ArtifactIdTest.java
+++ b/src/test/java/org/apache/sling/feature/ArtifactIdTest.java
@@ -146,7 +146,7 @@ public class ArtifactIdTest {
         final ArtifactId id = new ArtifactId("group.a", "artifact.b", "1.0", "foo", "zip");
         assertEquals("group.a:artifact.b:zip:foo:1.0", id.toMvnId());
     }
-    
+
     // --
 
     @Test public void testCoordinatesGAVfromUrl() {
@@ -180,4 +180,22 @@ public class ArtifactIdTest {
         final ArtifactId id = new ArtifactId("group.a", "artifact.b", "1.0", "foo", "zip");
         assertEquals("mvn:group.a/artifact.b/1.0/zip/foo", id.toMvnUrl());
     }
+
+    @Test
+    public void testToMvnPath() {
+        final ArtifactId a1 = new ArtifactId("group.a", "artifact.b", "1.0", "foo", "zip");
+        assertEquals("group/a/artifact.b/1.0/artifact.b-1.0-foo.zip", a1.toMvnPath());
+
+        final ArtifactId a2 = new ArtifactId("group.a", "artifact.b", "1.0", null, "zip");
+        assertEquals("group/a/artifact.b/1.0/artifact.b-1.0.zip", a2.toMvnPath());
+    }
+
+    @Test
+    public void testToMvnName() {
+        final ArtifactId a1 = new ArtifactId("group.a", "artifact.b", "1.0", "foo", "zip");
+        assertEquals("artifact.b-1.0-foo.zip", a1.toMvnName());
+
+        final ArtifactId a2 = new ArtifactId("group.a", "artifact.b", "1.0", null, "zip");
+        assertEquals("artifact.b-1.0.zip", a2.toMvnName());
+    }
 }