[maven-repo-helper] 01/01: Updated POMOptions to support the --relocate option

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Wed Jun 29 22:29:31 UTC 2016


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to branch master
in repository maven-repo-helper.

commit fb00f2bd6976b2cbce7936202a2e1382e5589cfc
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Thu Jun 30 00:29:22 2016 +0200

    Updated POMOptions to support the --relocate option
---
 .../java/org/debian/maven/repo/POMOptions.java     | 39 ++++++++++++++++++++++
 .../java/org/debian/maven/repo/POMOptionsTest.java | 22 ++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/src/main/java/org/debian/maven/repo/POMOptions.java b/src/main/java/org/debian/maven/repo/POMOptions.java
index d0e9657..e55f247 100644
--- a/src/main/java/org/debian/maven/repo/POMOptions.java
+++ b/src/main/java/org/debian/maven/repo/POMOptions.java
@@ -16,6 +16,8 @@
 
 package org.debian.maven.repo;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.StringTokenizer;
 
 /**
@@ -38,6 +40,12 @@ public class POMOptions {
     private String classifier;
     private String siteXml;
 
+    /**
+     * Comma separated list of Maven coordinates relocated to this artifact.
+     * Example: foo:bar:1.x,org.foo:bar-core:debian
+     */
+    private String relocate;
+
     public boolean isIgnore() {
         return ignore;
     }
@@ -150,6 +158,32 @@ public class POMOptions {
         this.siteXml = siteXml;
     }
 
+    public String getRelocate() {
+        return relocate;
+    }
+
+    public void setRelocate(String relocate) {
+        this.relocate = relocate;
+    }
+
+    public List<Dependency> getRelocatedArtifacts() {
+        List<Dependency> artifacts = new ArrayList<Dependency>();
+        if (relocate != null) {
+            for (String element : relocate.split(",")) {
+                String[] coordinates = element.split(":");
+                if (coordinates.length < 2) {
+                    throw new IllegalArgumentException("Malformed relocated artifact: " + element);
+                }
+                String groupId = coordinates[0];
+                String artifactId = coordinates[1];
+                String version = coordinates.length >= 3 ? coordinates[2] : "debian";
+                artifacts.add(new Dependency(groupId, artifactId, null, version));
+            }
+        }
+        
+        return artifacts;
+    }
+
     public static POMOptions parse(String line) {
         StringTokenizer st = new StringTokenizer(line, " \t");
         
@@ -185,6 +219,8 @@ public class POMOptions {
                 options.setClassifier(option.substring("--classifier=".length()));
             } else if (option.startsWith("--site-xml=")) {
                 options.setSiteXml(option.substring("--site-xml=".length()));
+            } else if (option.startsWith("--relocate=")) {
+                options.setRelocate(option.substring("--relocate=".length()));
             } else if ("--ignore-pom".equals(option)) {
                 options.setIgnorePOM(true);
             }
@@ -234,6 +270,9 @@ public class POMOptions {
         if (siteXml != null) {
             options += " --site-xml=" + siteXml;
         }
+        if (relocate != null) {
+            options += " --relocate=" + relocate;
+        }
         if (ignorePOM) {
             options += " --ignore-pom";
         }
diff --git a/src/test/java/org/debian/maven/repo/POMOptionsTest.java b/src/test/java/org/debian/maven/repo/POMOptionsTest.java
index 0c0dc7b..51826c9 100644
--- a/src/test/java/org/debian/maven/repo/POMOptionsTest.java
+++ b/src/test/java/org/debian/maven/repo/POMOptionsTest.java
@@ -16,6 +16,8 @@
 
 package org.debian.maven.repo;
 
+import java.util.List;
+
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -37,6 +39,26 @@ public class POMOptionsTest {
     }
 
     @Test
+    public void testParseRelocate() {
+        POMOptions options = POMOptions.parse("--relocate=foo:bar:1.x,org.foo:bar-core");
+        assertNotNull("relocate is null", options.getRelocate());
+
+        List<Dependency> relocatedArtifacts = options.getRelocatedArtifacts();
+        assertNotNull("relocated artifacts is null", relocatedArtifacts);
+        assertEquals("number of artifacts", 2, relocatedArtifacts.size());
+        
+        Dependency dependency = relocatedArtifacts.get(0);
+        assertEquals("relocated artifact 1 groupId", "foo", dependency.getGroupId());
+        assertEquals("relocated artifact 1 artifactId", "bar", dependency.getArtifactId());
+        assertEquals("relocated artifact 1 version", "1.x", dependency.getVersion());
+        
+        dependency = relocatedArtifacts.get(1);
+        assertEquals("relocated artifact 2 groupId", "org.foo", dependency.getGroupId());
+        assertEquals("relocated artifact 2 artifactId", "bar-core", dependency.getArtifactId());
+        assertEquals("relocated artifact 2 version", "debian", dependency.getVersion());
+    }
+
+    @Test
     public void testOptionsToString() {
         POMOptions options = new POMOptions();
         options.setIgnore(true);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/maven-repo-helper.git



More information about the pkg-java-commits mailing list