[maven-debian-helper] 06/07: The version rule selected by default is now the symbolic 'debian' version The choices for the version rule are no longer reordered but the previous choice is still selected by default

Emmanuel Bourg ebourg-guest at alioth.debian.org
Sat Aug 31 11:48:17 UTC 2013


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

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

commit d8015cd57c452c70960a147d87083f5d1b794c25
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Sat Aug 31 13:44:26 2013 +0200

    The version rule selected by default is now the symbolic 'debian' version
    The choices for the version rule are no longer reordered but the previous choice is still selected by default
---
 debian/changelog                                   |    3 +
 .../debian/maven/packager/DependenciesSolver.java  |   81 +++++++++++++++++---
 .../maven/packager/util/UserInteraction.java       |   46 -----------
 3 files changed, 72 insertions(+), 58 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 38a818e..a5bee16 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,8 @@
 maven-debian-helper (1.6.6) UNRELEASED; urgency=low
 
+  * The version rule selected by default is now the symbolic 'debian' version
+  * The choices for the version rule are no longer reordered but the previous
+    choice is still selected by default
   * Added com.github.github:site-maven-plugin to the ignored plugins
   * Added org.codehaus.mojo:ianal-maven-plugin to the ignored plugins
   * Added com.mycila.maven-license-plugin:maven-license-plugin
diff --git a/maven-packager-utils/src/main/java/org/debian/maven/packager/DependenciesSolver.java b/maven-packager-utils/src/main/java/org/debian/maven/packager/DependenciesSolver.java
index 59488f4..295fbc3 100644
--- a/maven-packager-utils/src/main/java/org/debian/maven/packager/DependenciesSolver.java
+++ b/maven-packager-utils/src/main/java/org/debian/maven/packager/DependenciesSolver.java
@@ -25,6 +25,8 @@ import java.io.LineNumberReader;
 import java.util.*;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.xml.stream.XMLStreamException;
 
@@ -83,12 +85,16 @@ public class DependenciesSolver {
     private boolean filterModules = false;
     boolean verbose = false;
     private Map<String, POMInfo> pomInfoCache = new HashMap<String, POMInfo>();
-    // Keep the original POMs for reference
+
+    /** The original POMs for reference */
     private Map<String, POMInfo> originalPomInfoCache = new HashMap<String, POMInfo>();
-    // Keep the previous selected rule for a given version
+
+    /** Map of the previously selected rule for a given version */
     private Map<String, Rule> versionToRules = new HashMap<String, Rule>();
-    // Keep the list of packages and dependencies
+
+    /** List of packages and dependencies */
     private Map<DebianDependency, Dependency> versionedPackagesAndDependencies = new HashMap<DebianDependency, Dependency>();
+
     private List<Rule> defaultRules = new ArrayList<Rule>();
     private PackageScanner scanner;
 
@@ -101,12 +107,9 @@ public class DependenciesSolver {
         pomTransformer.setFixVersions(false);
         pomTransformer.setRulesFiles(initDependencyRuleSetFiles(outputDirectory, verbose));
 
-        Rule toDebianRule = new Rule("s/.*/debian/", "Change the version to the symbolic 'debian' version");
-        Rule keepVersionRule = new Rule("*", "Keep the version");
-        Rule customRule = new Rule("CUSTOM", "Custom rule");
-        defaultRules.add(toDebianRule);
-        defaultRules.add(keepVersionRule);
-        defaultRules.add(customRule);
+        defaultRules.add(new Rule("s/.*/debian/", "Change the version to the symbolic 'debian' version"));
+        defaultRules.add(new Rule("*", "Keep the version"));
+        defaultRules.add(new Rule("CUSTOM", "Custom rule"));
     }
 
     public static DependencyRuleSetFiles initDependencyRuleSetFiles(File outputDirectory, boolean verbose) {
@@ -357,12 +360,12 @@ public class DependenciesSolver {
             }
 
             if (interactive && !explicitlyMentionedInRules && !pom.getThisPom().isPlugin()) {
-                Rule selectedRule = userInteraction.askForVersionRule(pom.getThisPom(), versionToRules, defaultRules);
+                Rule selectedRule = askForVersionRule(pom.getThisPom());
                 versionToRules.put(pom.getThisPom().getVersion(), selectedRule);
                 if (selectedRule.getPattern().equals("CUSTOM")) {
-                    String s = userInteraction.ask("Enter the pattern for your custom rule (in the form s/regex/replace/)")
+                    String rule = userInteraction.ask("Enter the pattern for your custom rule (in the form s/regex/replace/)")
                                .toLowerCase();
-                    selectedRule = new Rule(s, "My custom rule " + s);
+                    selectedRule = new Rule(rule, "My custom rule " + rule);
                     defaultRules.add(selectedRule);
                 }
 
@@ -422,6 +425,60 @@ public class DependenciesSolver {
         }
     }
 
+    /**
+     * Asks the user to specify the substitution rule for the version.
+     * 
+     * @param dependency
+     * @return the version rule selected
+     */
+    public Rule askForVersionRule(Dependency dependency) {
+        String question = "\n"
+                + "Version of " + dependency.getGroupId() + ":"
+                + dependency.getArtifactId() + " is " + dependency.getVersion()
+                + "\nChoose how the version will be transformed:";
+
+        List<Rule> choices = getVersionRules(dependency.getVersion());       
+        
+        // select the default choice (either the previously selected rule or the 'debian' version rule)
+        int defaultChoice = 1; // the 'debian' version rule is the first one of the default rules
+        if (versionToRules.containsKey(dependency.getVersion())) {
+            Rule previouslySelectedRule = versionToRules.get(dependency.getVersion());
+            if (choices.contains(previouslySelectedRule)) {
+                defaultChoice = choices.indexOf(previouslySelectedRule);
+            }
+        }
+
+        List<String> choicesDescriptions = new ArrayList<String>();
+        for (Rule choice : choices) {
+            choicesDescriptions.add(choice.getDescription());
+        }
+
+        int choice = userInteraction.askChoices(question, defaultChoice, choicesDescriptions);
+        return choices.get(choice);
+    }
+
+    /**
+     * Returns the substitution rules for the specified version.
+     */
+    private List<Rule> getVersionRules(String version) {
+        List<Rule> rules = new ArrayList<Rule>();
+
+        // add the 1.0 -> 1.x rule
+        Pattern p = Pattern.compile("(\\d+)(\\..*)");
+        Matcher matcher = p.matcher(version);
+        if (matcher.matches()) {
+            String mainVersion = matcher.group(1);
+            Rule mainVersionRule = new Rule("s/" + mainVersion + "\\..*/" + mainVersion + ".x/",
+                    "Replace all versions starting by " + mainVersion + ". with " + mainVersion + ".x");
+            rules.add(mainVersionRule);
+        }
+        
+        // add the default rules
+        rules.addAll(defaultRules);
+        
+        return rules;
+    }
+
     private POMInfo getPOM(File projectPom) throws XMLStreamException, IOException {
         POMInfo info = pomInfoCache.get(projectPom.getAbsolutePath());
         if (info != null) {
diff --git a/maven-packager-utils/src/main/java/org/debian/maven/packager/util/UserInteraction.java b/maven-packager-utils/src/main/java/org/debian/maven/packager/util/UserInteraction.java
index e572044..2e24272 100644
--- a/maven-packager-utils/src/main/java/org/debian/maven/packager/util/UserInteraction.java
+++ b/maven-packager-utils/src/main/java/org/debian/maven/packager/util/UserInteraction.java
@@ -5,12 +5,6 @@ import java.io.InputStreamReader;
 import java.io.LineNumberReader;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.debian.maven.repo.Dependency;
-import org.debian.maven.repo.Rule;
 
 public class UserInteraction {
     private static final List<String> YESNO = new ArrayList<String>(2);
@@ -126,44 +120,4 @@ public class UserInteraction {
     public void print(String text) {
         System.out.print(text);
     }
-
-    // extracted from DependencySolver
-    // TODO can be simplified / cleaned up
-    public Rule askForVersionRule(Dependency dependency, Map<String, Rule> versionToRules, List<Rule> defaultRules) {
-        String question = "\n"
-                + "Version of " + dependency.getGroupId() + ":"
-                + dependency.getArtifactId() + " is " + dependency.getVersion()
-                + "\nChoose how it will be transformed:";
-
-        List<Rule> choices = new ArrayList<Rule>();
-
-        if (versionToRules.containsKey(dependency.getVersion())) {
-            choices.add(versionToRules.get(dependency.getVersion()));
-        }
-
-        Pattern p = Pattern.compile("(\\d+)(\\..*)");
-        Matcher matcher = p.matcher(dependency.getVersion());
-        if (matcher.matches()) {
-            String mainVersion = matcher.group(1);
-            Rule mainVersionRule = new Rule("s/" + mainVersion + "\\..*/" + mainVersion + ".x/",
-                    "Replace all versions starting by " + mainVersion + ". with " + mainVersion + ".x");
-            if (!choices.contains(mainVersionRule)) {
-                choices.add(mainVersionRule);
-            }
-        }
-        for (Rule rule : defaultRules) {
-            if (!choices.contains(rule)) {
-                choices.add(rule);
-            }
-        }
-
-        List<String> choicesDescriptions = new ArrayList<String>();
-        for (Rule choice : choices) {
-            choicesDescriptions.add(choice.getDescription());
-        }
-        int choice = askChoices(question, 0, choicesDescriptions);
-        Rule selectedRule = choices.get(choice);
-        return selectedRule;
-    }
-
 }

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



More information about the pkg-java-commits mailing list