[maven-repo-helper] 01/01: Allow rules like s/foo// to remove an element of the Maven coordinates

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Wed Sep 3 10:50:16 UTC 2014


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 e2d8918cf934ac3763a3eaa46ee4e1a673103022
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Wed Sep 3 12:49:57 2014 +0200

    Allow rules like s/foo// to remove an element of the Maven coordinates
---
 debian/changelog                                  |  6 ++++++
 src/main/java/org/debian/maven/repo/Rule.java     | 18 ++++++++++++------
 src/test/java/org/debian/maven/repo/RuleTest.java |  6 ++++++
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index ae17af0..4aa0bee 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+maven-repo-helper (1.8.9) UNRELEASED; urgency=medium
+
+  * Allow rules like s/foo// to remove an element of the Maven coordinates
+
+ -- Emmanuel Bourg <ebourg at apache.org>  Wed, 03 Sep 2014 12:46:24 +0200
+
 maven-repo-helper (1.8.8) unstable; urgency=medium
 
   * Parse and transform the module elements declared in profiles
diff --git a/src/main/java/org/debian/maven/repo/Rule.java b/src/main/java/org/debian/maven/repo/Rule.java
index 2ac3650..9414b40 100644
--- a/src/main/java/org/debian/maven/repo/Rule.java
+++ b/src/main/java/org/debian/maven/repo/Rule.java
@@ -24,8 +24,14 @@ import java.util.regex.Pattern;
  * @author Ludovic Claude <ludovicc at users.sourceforge.net>
  */
 public class Rule {
+
+    /** Regexp looking for characters found in regular expressions like '[', '?', '*', '+', '|' */
+    private static final Pattern GENERIC_PATTERN = Pattern.compile("([\\[\\?\\+\\*\\|])|([^\\\\]\\.)"); // ([\[\?\+\*\|])|([^\\]\.)
     private static Pattern generic = Pattern.compile("([\\[\\?\\+\\*\\|])|([^\\\\]\\.)");
 
+    /** Regexp matching a substitution expression like s/foo/bar/ */
+    private static final Pattern SUBSTITUTION_PATTERN = Pattern.compile("s/([^/]*)/([^/]*)/?");
+
     private final Pattern pattern;
     private final String replace;
     private final String rule;
@@ -38,11 +44,11 @@ public class Rule {
     public Rule(String rule, String description) {
         this.rule = rule;
         this.description = description;
-        if (rule.startsWith("s/")) {
-            StringTokenizer st = new StringTokenizer(rule, "/");
-            st.nextToken();
-            pattern = Pattern.compile(st.nextToken());
-            replace = st.nextToken();
+        
+        Matcher matcher;
+        if ((matcher = SUBSTITUTION_PATTERN.matcher(rule)).matches()) {
+            pattern = Pattern.compile(matcher.group(1));
+            replace = matcher.group(2);
         } else {
             String pat = escapeParameters(rule.replace(".", "\\.").replace("*", "(.*)"));
             pattern = Pattern.compile(pat);
@@ -77,7 +83,7 @@ public class Rule {
     }
 
     public boolean isGeneric() {
-        return matchesNull() || generic.matcher(pattern.pattern()).find();
+        return matchesNull() || GENERIC_PATTERN.matcher(pattern.pattern()).find();
     }
 
     public boolean matchesNull() {
diff --git a/src/test/java/org/debian/maven/repo/RuleTest.java b/src/test/java/org/debian/maven/repo/RuleTest.java
index 3b90e83..28cafa9 100644
--- a/src/test/java/org/debian/maven/repo/RuleTest.java
+++ b/src/test/java/org/debian/maven/repo/RuleTest.java
@@ -72,6 +72,12 @@ public class RuleTest {
         Rule simpleReplace = new Rule("s/test/foo/");
         assertEquals("foo", simpleReplace.apply("test"));
 
+        Rule simpleReplace2 = new Rule("s/test/foo");
+        assertEquals("foo", simpleReplace2.apply("test"));
+        
+        Rule erase = new Rule("s/test//");
+        assertEquals("", erase.apply("test"));
+
         Rule complexReplace = new Rule("s/test(.*)/foo$1/");
         assertEquals("foo", complexReplace.apply("test"));
         assertEquals("foo2", complexReplace.apply("test2"));

-- 
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