[pkg-java] r8615 - in trunk/maven-repo-helper: . src/main/bin src/main/java/org/debian/maven/repo src/test/java/org/debian/maven/repo src/test/resources

Ludovic Claude ludovicc-guest at alioth.debian.org
Fri Jun 26 19:37:05 UTC 2009


Author: ludovicc-guest
Date: 2009-06-26 19:37:04 +0000 (Fri, 26 Jun 2009)
New Revision: 8615

Added:
   trunk/maven-repo-helper/src/test/resources/plexus-active-collections.cleaned
   trunk/maven-repo-helper/src/test/resources/plexus-active-collections.pom
Modified:
   trunk/maven-repo-helper/pom.xml
   trunk/maven-repo-helper/src/main/bin/mh_cleanpom
   trunk/maven-repo-helper/src/main/bin/mh_lspoms
   trunk/maven-repo-helper/src/main/bin/mh_patchpoms
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Dependency.java
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/DependencyRule.java
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMInfo.java
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMReader.java
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMTransformer.java
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Repository.java
   trunk/maven-repo-helper/src/test/java/org/debian/maven/repo/POMCleanerTest.java
   trunk/maven-repo-helper/src/test/resources/plexus-container-default.cleaned
   trunk/maven-repo-helper/src/test/resources/plexus-container-default.transformed
Log:
* Improve the repository implementation,
* Better doc and options for the command line utilities

Modified: trunk/maven-repo-helper/pom.xml
===================================================================
--- trunk/maven-repo-helper/pom.xml	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/pom.xml	2009-06-26 19:37:04 UTC (rev 8615)
@@ -77,12 +77,6 @@
             <version>1.4</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-  <groupId>org.testng</groupId>
-  <artifactId>testng</artifactId>
-  <version>5.7</version>
-  <classifier>jdk15</classifier>
-</dependency>
     </dependencies>
 
 </project>

Modified: trunk/maven-repo-helper/src/main/bin/mh_cleanpom
===================================================================
--- trunk/maven-repo-helper/src/main/bin/mh_cleanpom	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/bin/mh_cleanpom	2009-06-26 19:37:04 UTC (rev 8615)
@@ -92,7 +92,7 @@
    exit 1
 }
 
-ARGS="p package o no-parent k keep-pom-version r rules i published-rules v verbose n no-act" parseargs "$@"
+ARGS="p package o no-parent k keep-pom-version r rules i published-rules s no-rules v verbose n no-act" parseargs "$@"
 
 if [ "$ARGC" -lt "1" ]; then
    syntax
@@ -102,6 +102,7 @@
 KEEPVERSION=$(getarg k keep-pom-version)
 RULES=$(getarg r rules)
 PUBLISHED_RULES=$(getarg i published-rules)
+NORULES=$(getarg s no-rules)
 PACKAGE=$(getarg p package)
 PACKAGE=${PACKAGE:?"Package parameter (-p) is mandatory"}
 VERBOSE=$(getarg v verbose)
@@ -119,7 +120,7 @@
 fi
 if [ -z "$PUBLISHED_RULES" ]; then
     if [ -f debian/maven.publishedRules ]; then
-        RULES="debian/maven.publishedRules"
+        PUBLISHED_RULES="debian/maven.publishedRules"
     fi
 fi
 
@@ -129,7 +130,7 @@
     fi
 fi
 
-CLEAN_ARGS="--package=${PACKAGE} ${VERBOSE:+--verbose} ${NOPARENT:+--no-parent} ${KEEPVERSION:+--keep-pom-version} ${RULES:+--rules=$RULES} ${PUBLISHED_RULES:+--published-rules=$PUBLISHED_RULES}"
+CLEAN_ARGS="--package=${PACKAGE} ${VERBOSE:+--verbose} ${NOPARENT:+--no-parent} ${KEEPVERSION:+--keep-pom-version} ${RULES:+--rules=$RULES} ${PUBLISHED_RULES:+--published-rules=$PUBLISHED_RULES} ${NORULES:+--no-rules}"
 
 if [ -z "$NOACT" ]; then
     java -cp /usr/share/java/maven-repo-helper.jar org.debian.maven.repo.POMCleaner $CLEAN_ARGS $POM $TARGET $POM_PROPS

Modified: trunk/maven-repo-helper/src/main/bin/mh_lspoms
===================================================================
--- trunk/maven-repo-helper/src/main/bin/mh_lspoms	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/bin/mh_lspoms	2009-06-26 19:37:04 UTC (rev 8615)
@@ -14,6 +14,7 @@
    echo -e "Options:"
    echo -e "\t-h --help: show this text"
    echo -e "\t-V --version: show the version"
+   echo -e "\t-p<package> --package=<package>: package to act on "
    echo -e ""
    echo -e "You need to execute it on the unpacked origial source tree, merged with the"
    echo -e "debian/ folder. It will create the file debian/<binary package>.poms which"
@@ -28,15 +29,18 @@
    exit 1
 }
 
-ARGS="" parseargs "$@"
+ARGS="p package" parseargs "$@"
 
-if [ "$ARGC" -gt "0" ]; then
-	PACKAGE="${ARGV[0]}"
-else
-	PACKAGE=$(dh_listpackages | head -1)
+PACKAGE=$(getarg p package)
+
+if [ -z "$PACKAGE" ]; then
+	if [ "$ARGC" -gt "0" ]; then
+		PACKAGE="${ARGV[0]}"
+	else
+		PACKAGE=$(dh_listpackages | head -1)
+	fi
 fi
 
-
 if [ -e debian/$PACKAGE.poms ]; then
   echo debian/$PACKAGE.poms already exist. Please delete it if you want to regenerate it.
 else

Modified: trunk/maven-repo-helper/src/main/bin/mh_patchpoms
===================================================================
--- trunk/maven-repo-helper/src/main/bin/mh_patchpoms	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/bin/mh_patchpoms	2009-06-26 19:37:04 UTC (rev 8615)
@@ -19,6 +19,11 @@
    echo -e "\t-r<rules> --rules=<rules>: gives the location of the rules file for"
    echo -e "\t  special properties. Optional, the default location is"
    echo -e "\t  debian/maven.rules"
+   echo -e "\t-i<rules> --published-rules=<rules>: path to the file containing the"
+   echo -e "\t  extra rules to publish in the property debian.mavenRules in the cleaned POM"
+   echo -e "\t  Optional, the default location is debian/maven.publishedRules"
+   echo -e "\t-s --no-rules: don't apply any rules for converting versions,"
+   echo -e "\t  do not even convert versions to the default 'debian' version"
    echo -e "\t-k --keep-pom-version: keep the original version of the POMs but, "
    echo -e "\t  convert all other versions in dependencies and plugins"
    echo -e "\t-v --verbose: show more information while running"
@@ -26,9 +31,11 @@
    exit 1
 }
 
-ARGS="p package r rules k keep-pom-version v verbose n no-act" parseargs "$@"
+ARGS="p package r rules i published-rules s no-rules k keep-pom-version v verbose n no-act" parseargs "$@"
 
 RULES=$(getarg r rules)
+PUBLISHED_RULES=$(getarg i published-rules)
+NORULES=$(getarg s no-rules)
 KEEP_POM_VERSION=$(getarg k keep-pom-version)
 PACKAGE=$(getarg p package)
 PACKAGE=${PACKAGE:?"Package parameter (-p) is mandatory"}
@@ -42,7 +49,7 @@
 fi
 
 DH_OPTS="${VERBOSE:+-v}"
-MH_ARGS="--package=${PACKAGE} ${RULES:+--rules=$RULES} ${KEEP_POM_VERSION:+--keep-pom-version}"
+MH_ARGS="--package=${PACKAGE} ${RULES:+--rules=$RULES} ${KEEP_POM_VERSION:+--keep-pom-version} ${PUBLISHED_RULES:+--published-rules=$PUBLISHED_RULES} ${NORULES:+--no-rules}"
 
 if [ -z "$NOACT" ]; then
     cat debian/$PACKAGE.poms | while read POM OPT1 OPT2; do

Modified: trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Dependency.java
===================================================================
--- trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Dependency.java	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Dependency.java	2009-06-26 19:37:04 UTC (rev 8615)
@@ -19,6 +19,8 @@
     private String artifactId;
     private String type;
     private String version;
+    private boolean optional;
+    private String scope;
 
     public Dependency() {
     }
@@ -62,6 +64,22 @@
         this.version = version;
     }
 
+    public boolean isOptional() {
+        return optional;
+    }
+
+    public void setOptional(boolean optional) {
+        this.optional = optional;
+    }
+
+    public String getScope() {
+        return scope;
+    }
+
+    public void setScope(String scope) {
+        this.scope = scope;
+    }
+
     public boolean equals(Object obj) {
         if (obj == null) {
             return false;
@@ -85,6 +103,26 @@
         return true;
     }
 
+    public boolean equalsIgnoreVersion(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final Dependency other = (Dependency) obj;
+        if ((this.groupId == null) ? (other.groupId != null) : !this.groupId.equals(other.groupId)) {
+            return false;
+        }
+        if ((this.artifactId == null) ? (other.artifactId != null) : !this.artifactId.equals(other.artifactId)) {
+            return false;
+        }
+        if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
+            return false;
+        }
+        return true;
+    }
+
     public int hashCode() {
         int hash = 7;
         hash = 31 * hash + (this.groupId != null ? this.groupId.hashCode() : 0);

Modified: trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/DependencyRule.java
===================================================================
--- trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/DependencyRule.java	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/DependencyRule.java	2009-06-26 19:37:04 UTC (rev 8615)
@@ -10,6 +10,7 @@
 
     public static DependencyRule TO_DEBIAN_VERSION_RULE = new DependencyRule("");
     public static DependencyRule MAVEN_PLUGINS_KEEP_VERSION_RULE = new DependencyRule("* * maven-plugin *");
+    public static DependencyRule NO_CHANGE_RULE = new DependencyRule("* * * *");
 
     private Rule groupRule;
     private Rule artifactRule;
@@ -51,6 +52,13 @@
                 versionRule.apply(dependency.getVersion()));
     }
 
+    /**
+     * Natural sort order: from the most specific rules to the most generic rules,
+     * a rule is more generic if a generic match appears on th egroup rule, then
+     * artifact rule, then type rule, then version rule.
+     * If 2 rules have the same order of genericity, then use an alphabetical
+     * sorting of the pattern strings.
+     */
     public int compareTo(Object o) {
         DependencyRule other = (DependencyRule) o;
         if (groupRule.isGeneric() && !other.groupRule.isGeneric()) {

Modified: trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMInfo.java
===================================================================
--- trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMInfo.java	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMInfo.java	2009-06-26 19:37:04 UTC (rev 8615)
@@ -4,12 +4,16 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
 
 public class POMInfo {
     private String originalParentVersion;
     private Dependency originalPom;
     private Dependency parent;
     private Dependency thisPom;
+    private List modules;
     private List dependencies;
     private List dependencyManagement;
     private List extensions;
@@ -70,6 +74,14 @@
         this.thisPom = thisPom;
     }
 
+    public List getModules() {
+        return modules;
+    }
+
+    public void setModules(List modules) {
+        this.modules = modules;
+    }
+
     /**
      * @return the dependencies
      */
@@ -146,6 +158,26 @@
         this.extensions = extensions;
     }
 
+    public Set getPublishedRules(boolean includeDefault) {
+        Set rules = new TreeSet();
+        if (includeDefault) {
+            rules.add(DependencyRule.MAVEN_PLUGINS_KEEP_VERSION_RULE);
+            rules.add(DependencyRule.TO_DEBIAN_VERSION_RULE);
+        }
+        if (getProperties() == null) {
+            return rules;
+        }
+        String mavenRules = (String) getProperties().get("debian.mavenRules");
+        if (mavenRules != null) {
+            StringTokenizer st = new StringTokenizer(mavenRules, ",");
+            while (st.hasMoreTokens()) {
+                String rule = st.nextToken().trim();
+                rules.add(new DependencyRule(rule));
+            }
+        }
+        return rules;
+    }
+
     public POMInfo applyRules(Collection rules) {
         if (rules.isEmpty()) {
             return this;

Modified: trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMReader.java
===================================================================
--- trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMReader.java	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMReader.java	2009-06-26 19:37:04 UTC (rev 8615)
@@ -4,6 +4,7 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -31,7 +32,11 @@
         if (! originalPom.exists()) {
             System.err.println("Cannot find pom file " + originalPom.getAbsolutePath());
         }
-        XMLStreamReader parser = factory.createXMLStreamReader(new BufferedReader(new FileReader(originalPom)));
+        return readPom(new FileReader(originalPom));
+    }
+
+    public POMInfo readPom(Reader originalPom) throws XMLStreamException {
+        XMLStreamReader parser = factory.createXMLStreamReader(new BufferedReader(originalPom));
         List path = new ArrayList();
         List dependencies = new ArrayList();
         List dependencyManagement = new ArrayList();
@@ -40,6 +45,7 @@
         List pluginManagement = new ArrayList();
         List profileDependencies = new ArrayList();
         List profileDependencyManagement = new ArrayList();
+        List modules = new ArrayList();
 
         Map properties = new TreeMap();
         Dependency thisPom = new Dependency(null, null, "jar", null);
@@ -47,6 +53,7 @@
         Dependency currentDependency = null;
         int inLevel = 0;
         int inIgnoredElement = 0;
+        int inModule = 0;
         int inDependency = 0;
         int inExtension = 0;
         int inPlugin = 0;
@@ -105,6 +112,10 @@
                             extensions.add(currentDependency);
                         } else if (inExtension > 0) {
                             inExtension++;
+                        } else if (inLevel == 2 && "modules".equals(element)) {
+                            inModule++;
+                        } else if (inModule > 0) {
+                            inModule++;
                         } else if (inLevel == 2 && "parent".equals(element)) {
                             inParent++;
                             parent = new Dependency();
@@ -132,6 +143,8 @@
                             inPlugin--;
                         } else if (inExtension > 0) {
                             inExtension--;
+                        } else if (inModule > 0) {
+                            inModule--;
                         } else if (inParent > 0) {
                             inParent--;
                         } else if (inProperties > 0) {
@@ -153,7 +166,13 @@
                             currentDependency.setType(value);
                         } else if ("version".equals(element)) {
                             currentDependency.setVersion(value);
+                        } else if ("optional".equals(element)) {
+                            currentDependency.setOptional("true".equals(value));
+                        } else if ("scope".equals(element)) {
+                            currentDependency.setScope(value);
                         }
+                    } else if (inModule > 1) {
+                        modules.add(value);
                     } else if (inParent > 1) {
                         if ("groupId".equals(element)) {
                             parent.setGroupId(value);
@@ -220,6 +239,7 @@
         }
         info.setThisPom(thisPom);
         info.setParent(parent);
+        info.setModules(modules);
         info.setDependencies(dependencies);
         info.setDependencyManagement(dependencyManagement);
         info.setExtensions(extensions);

Modified: trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMTransformer.java
===================================================================
--- trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMTransformer.java	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMTransformer.java	2009-06-26 19:37:04 UTC (rev 8615)
@@ -413,7 +413,7 @@
         }
         if (!publishedRules.isEmpty()) {
             indent(writer, inLevel + 1);
-            writer.writeStartElement("debian.mavenRule");
+            writer.writeStartElement("debian.mavenRules");
             StringWriter sw = new StringWriter();
             for (Iterator i = publishedRules.iterator(); i.hasNext();) {
                 DependencyRule dependencyRule = (DependencyRule) i.next();
@@ -439,7 +439,7 @@
         void handlePOM(File pomFile, boolean noParent) throws Exception;
     }
 
-    private void foreachPoms(File poms, POMHandler handler) {
+    private static void foreachPoms(File poms, POMHandler handler) {
         try {
             LineNumberReader reader = new LineNumberReader(new FileReader(poms));
             String line;
@@ -463,6 +463,22 @@
         }
     }
 
+    public static Map getPomOptions(File poms) {
+        final Map pomOptions = new HashMap();
+        foreachPoms(poms, new POMHandler() {
+
+            public void handlePOM(File pomFile, boolean noParent) throws Exception {
+                String option = "";
+                if (noParent) {
+                    option = "--no-parent";
+                }
+                pomOptions.put(pomFile, option);
+            }
+        });
+
+        return pomOptions;
+    }
+
     public static void main(String[] args) {
         if (args.length == 0 || "-h".equals(args[0]) || "--help".equals(args[0])) {
             System.out.println("Purpose: Transforms the POM files to use Debian versions.");
@@ -474,6 +490,8 @@
             System.out.println("    this library");
             System.out.println("  -r<rules>, --rules=<rules>: path to the file containing the");
             System.out.println("    extra rules to apply when cleaning the POM");
+            System.out.println("  -i<rules>, --published-rules=<rules>: path to the file containing the");
+            System.out.println("    extra rules to publish in the property debian.mavenRules in the cleaned POM");
             System.out.println("  --no-rules: don't apply any rules for converting versions, ");
             System.out.println("    do not even convert versions to the default 'debian' version");
             System.out.println("  --keep-pom-version: keep the original version of the POMs but, ");
@@ -513,6 +531,10 @@
                 rulesFile = new File(arg.substring(2));
             } else if (arg.startsWith("--rules=")) {
                 rulesFile = new File(arg.substring("--rules=".length()));
+            } else if (arg.startsWith("-i")) {
+                publishedRulesFile = new File(arg.substring(2));
+            } else if (arg.startsWith("--published-rules=")) {
+                publishedRulesFile = new File(arg.substring("--rules=".length()));
             }
             i = inc(i, args);
         }
@@ -525,7 +547,9 @@
             poms = new File("debian/" + debianPackage + ".poms");
         }
 
-        if (!noRules) {
+        if (noRules) {
+            transformer.addRule(DependencyRule.NO_CHANGE_RULE);
+        } else {
             transformer.addDefaultRules();
             if (rulesFile != null) {
                 if (!rulesFile.exists()) {

Modified: trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Repository.java
===================================================================
--- trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Repository.java	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/Repository.java	2009-06-26 19:37:04 UTC (rev 8615)
@@ -6,6 +6,7 @@
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -16,6 +17,8 @@
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.xml.stream.XMLStreamException;
 
 /**
@@ -24,25 +27,89 @@
  */
 public class Repository {
 
+    private static final Logger log = Logger.getLogger(Repository.class.getName());
     private File baseDir;
-    private Map poms = new HashMap();
+    private Map unresolvedPoms = new HashMap();
     private Map dep2info = new HashMap();
     private Map pomsWithMissingParent = new HashMap();
     private Map pomsWithMissingVersions = new HashMap();
     private Map resolvedPoms = new HashMap();
+    private POMInfo superPom;
+    private POMReader pomReader = new POMReader();
 
     public Repository(File baseDir) {
         this.baseDir = baseDir;
+        try {
+            superPom = pomReader.readPom(new InputStreamReader(getClass().getResourceAsStream("/org/apache/maven/project/pom-4.0.0.xml")));
+        } catch (XMLStreamException ex) {
+            log.log(Level.SEVERE, null, ex);
+        }
     }
 
     public File getBaseDir() {
         return baseDir;
     }
 
+    public POMInfo getSuperPOM() {
+        return superPom;
+    }
+
+    public POMInfo getPOM(Dependency dependency) {
+        return (POMInfo) dep2info.get(dependency);
+    }
+
+    /**
+     * Search the best match for a dependency
+     *
+     * @param dependency
+     * @return
+     */
+    public POMInfo searchMatchingPOM(Dependency dependency) {
+        POMInfo pom = getPOM(dependency);
+        if (pom != null) {
+            return pom;
+        }
+
+        // Map<DependencyRule,POMInfo>
+        Map potentialMatches = new TreeMap();
+        for (Iterator i = resolvedPoms.values().iterator(); i.hasNext();) {
+            POMInfo testPom = (POMInfo) i.next();
+            Set rules = testPom.getPublishedRules(true);
+            for (Iterator j = rules.iterator(); j.hasNext();) {
+                DependencyRule rule = (DependencyRule) j.next();
+                if (rule.matches(dependency) && rule.apply(dependency).equals(testPom.getThisPom())) {
+                    potentialMatches.put(rule, testPom);
+                }
+            }
+        }
+        if (!potentialMatches.isEmpty()) {
+            // Return the best match
+            return (POMInfo) potentialMatches.values().iterator().next();
+        }
+        return null;
+    }
+
+    public List searchMatchingPOMsIgnoreVersion(Dependency dependency) {
+        List result = new ArrayList();
+        POMInfo pom = searchMatchingPOM(dependency);
+        if (pom != null) {
+            result.add(pom);
+            return result;
+        }
+
+        for (Iterator i = resolvedPoms.values().iterator(); i.hasNext();) {
+            POMInfo testPom = (POMInfo) i.next();
+            if (testPom.getThisPom().equalsIgnoreVersion(dependency)) {
+                result.add(testPom);
+            }
+        }
+        return result;
+    }
+
     public void scan() {
         File[] files = baseDir.listFiles();
         scan(files);
-        resolveAll(poms);
+        resolveAll(unresolvedPoms);
         int unresolved = pomsWithMissingParent.size();
         while (unresolved > 0) {
             resolveAll(pomsWithMissingParent);
@@ -52,16 +119,19 @@
             }
             unresolved = pomsWithMissingParent.size();
         }
-        unresolved = poms.size();
+        unresolved = unresolvedPoms.size();
         while (unresolved > 0) {
-            resolveAll(poms);
-            if (poms.size() == unresolved) {
+            resolveAll(unresolvedPoms);
+            if (unresolvedPoms.size() == unresolved) {
                 // stale detection
                 break;
             }
-            unresolved = poms.size();
+            unresolved = unresolvedPoms.size();
         }
+    }
 
+    public void report() {
+
         if (pomsWithMissingParent.size() > 0) {
             System.out.println("POMs with missing parents:");
             for (Iterator i = pomsWithMissingParent.keySet().iterator(); i.hasNext();) {
@@ -77,13 +147,13 @@
                 POMInfo pomInfo = (POMInfo) entry.getValue();
                 System.out.println("\t" + pom.getAbsolutePath());
                 for (Iterator j = pomInfo.getDependencies().iterator(); j.hasNext();) {
-                    Dependency dependency = (Dependency)j.next();
+                    Dependency dependency = (Dependency) j.next();
                     if (dependency.getVersion() == null || dependency.getVersion().contains("$")) {
                         System.out.println("\t\t" + dependency);
                     }
                 }
                 for (Iterator j = pomInfo.getPlugins().iterator(); j.hasNext();) {
-                    Dependency dependency = (Dependency)j.next();
+                    Dependency dependency = (Dependency) j.next();
                     if (dependency.getVersion() == null || dependency.getVersion().contains("$")) {
                         System.out.println("\t\t" + dependency);
                     }
@@ -95,37 +165,37 @@
         Set issues = new TreeSet();
         Map pomsWithIssues = new HashMap();
         for (Iterator i = resolvedPoms.entrySet().iterator(); i.hasNext();) {
-                Entry entry = (Entry) i.next();
-                File pom = (File) entry.getKey();
-                POMInfo pomInfo = (POMInfo) entry.getValue();
-                for (Iterator j = pomInfo.getDependencies().iterator(); j.hasNext();) {
-                    Dependency dependency = (Dependency)j.next();
-                    if (!dep2info.containsKey(dependency)) {
-                        issues.add("Unpackaged dependency: " + dependency + " in " + pom);
-                        List pomIssues = (List) pomsWithIssues.get(pom);
-                        if (pomIssues == null) {
-                            pomIssues = new ArrayList();
-                            pomsWithIssues.put(pom, pomIssues);
-                        }
-                        pomIssues.add(dependency);
+            Entry entry = (Entry) i.next();
+            File pom = (File) entry.getKey();
+            POMInfo pomInfo = (POMInfo) entry.getValue();
+            for (Iterator j = pomInfo.getDependencies().iterator(); j.hasNext();) {
+                Dependency dependency = (Dependency) j.next();
+                if (!dep2info.containsKey(dependency)) {
+                    issues.add("Unpackaged dependency: " + dependency + " in " + pom);
+                    List pomIssues = (List) pomsWithIssues.get(pom);
+                    if (pomIssues == null) {
+                        pomIssues = new ArrayList();
+                        pomsWithIssues.put(pom, pomIssues);
                     }
+                    pomIssues.add(dependency);
                 }
-                for (Iterator j = pomInfo.getPlugins().iterator(); j.hasNext();) {
-                    Dependency dependency = (Dependency)j.next();
-                    if (!dep2info.containsKey(dependency)) {
-                        issues.add("Unpackaged plugin: " + dependency + " in " + pom);
-                        List pomIssues = (List) pomsWithIssues.get(pom);
-                        if (pomIssues == null) {
-                            pomIssues = new ArrayList();
-                            pomsWithIssues.put(pom, pomIssues);
-                        }
-                        pomIssues.add(dependency);
+            }
+            for (Iterator j = pomInfo.getPlugins().iterator(); j.hasNext();) {
+                Dependency dependency = (Dependency) j.next();
+                if (!dep2info.containsKey(dependency)) {
+                    issues.add("Unpackaged plugin: " + dependency + " in " + pom);
+                    List pomIssues = (List) pomsWithIssues.get(pom);
+                    if (pomIssues == null) {
+                        pomIssues = new ArrayList();
+                        pomsWithIssues.put(pom, pomIssues);
                     }
+                    pomIssues.add(dependency);
                 }
+            }
         }
 
         for (Iterator i = issues.iterator(); i.hasNext();) {
-            String issue = (String)i.next();
+            String issue = (String) i.next();
             System.out.println(issue);
         }
         System.out.println();
@@ -146,14 +216,14 @@
         }
         System.out.println("POM files with the most issues:");
         int count = 0;
-        for (Iterator i = pomsWithNumberOfIssues.values().iterator(); i.hasNext() && count < 10; ) {
+        for (Iterator i = pomsWithNumberOfIssues.values().iterator(); i.hasNext() && count < 10;) {
             List orderedPoms = (List) i.next();
             for (Iterator j = orderedPoms.iterator(); j.hasNext() && count < 10; count++) {
                 File pom = (File) j.next();
                 List missingDeps = (List) pomsWithIssues.get(pom);
                 System.out.println("Missing dependencies in " + pom);
                 for (Iterator k = missingDeps.iterator(); k.hasNext();) {
-                    Dependency dependency = (Dependency)k.next();
+                    Dependency dependency = (Dependency) k.next();
                     System.out.println("\t" + dependency);
                 }
             }
@@ -166,12 +236,11 @@
         Map copy = new HashMap(file2pom);
         for (Iterator i = copy.entrySet().iterator(); i.hasNext();) {
             Entry entry = (Entry) i.next();
-            resolveDependencies((File) entry.getKey(), (POMInfo) entry.getValue());
+            registerPom((File) entry.getKey(), (POMInfo) entry.getValue());
         }
     }
 
     private void scan(File[] files) {
-        POMReader pomReader = new POMReader();
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
             if (file.isDirectory()) {
@@ -179,7 +248,7 @@
             } else if (file.getName().endsWith(".pom")) {
                 try {
                     POMInfo pom = pomReader.readPom(file);
-                    poms.put(file, pom);
+                    registerPom(file, pom);
                 } catch (XMLStreamException ex) {
                     ex.printStackTrace();
                 } catch (FileNotFoundException ex) {
@@ -189,27 +258,36 @@
         }
     }
 
-    private void resolveDependencies(File file, POMInfo pomInfo) {
+    public void registerPom(File file, POMInfo pomInfo) {
         dep2info.put(pomInfo.getThisPom(), pomInfo);
-        POMInfo parentPOM = null;
-        if (pomInfo.getParent() != null) {
-            parentPOM = (POMInfo) dep2info.get(pomInfo.getParent());
-            if (parentPOM == null) {
-                pomsWithMissingParent.put(file, pomInfo);
-                return;
-            } else {
-                pomsWithMissingParent.remove(file);
+        unresolvedPoms.put(file, pomInfo);
+
+        POMInfo parentPOM = superPom;
+        try {
+            if (pomInfo.getParent() != null) {
+                POMInfo foundParent = getPOM(pomInfo.getParent());
+                if (foundParent == null) {
+                    pomsWithMissingParent.put(file, pomInfo);
+                    return;
+                } else {
+                    parentPOM = foundParent;
+                    pomsWithMissingParent.remove(file);
+                }
+                if (!resolvedPoms.values().contains(parentPOM)) {
+                    return;
+                }
             }
-            if (!resolvedPoms.values().contains(parentPOM)) {
-                return;
-            }
+        } finally {
+            // Always merge with the parent POM - which is by default the super POM,
+            // as we can have intermediate situations in the DependenciesSolver where
+            // the true parent POM is not known and will be eliminated, yet we need
+            // the versions from the super POM.
+            pomInfo.mergeManagement(parentPOM);
         }
 
         resolvedPoms.put(file, pomInfo);
-        poms.remove(file);
+        unresolvedPoms.remove(file);
 
-        pomInfo.mergeManagement(parentPOM);
-
         for (Iterator i = pomInfo.getDependencies().iterator(); i.hasNext();) {
             Dependency dependency = (Dependency) i.next();
             if (dependency.getVersion() == null) {
@@ -230,7 +308,9 @@
             repoLocation = args[0];
         }
         System.out.println("Scanning repository...");
-        new Repository(new File(repoLocation)).scan();
+        Repository repository = new Repository(new File(repoLocation));
+        repository.scan();
+        repository.report();
         System.out.println("Done.");
     }
 }

Modified: trunk/maven-repo-helper/src/test/java/org/debian/maven/repo/POMCleanerTest.java
===================================================================
--- trunk/maven-repo-helper/src/test/java/org/debian/maven/repo/POMCleanerTest.java	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/test/java/org/debian/maven/repo/POMCleanerTest.java	2009-06-26 19:37:04 UTC (rev 8615)
@@ -125,6 +125,29 @@
     /**
      * Test of cleanPom method, of class POMCleaner.
      */
+    public void testCleanPlexusActiveCollectionsPom() throws Exception {
+        pomProperties = new File(testDir, "pom.properties");
+        usePom("plexus-active-collections.pom");
+        boolean noParent = true;
+        POMCleaner instance = new POMCleaner();
+        instance.addDefaultRules();
+        instance.addRule(new DependencyRule("junit junit jar s/3\\..*/3.x/"));
+        instance.addRule(new DependencyRule("org.codehaus.plexus plexus-container-default jar s/1\\.0-alpha.*/1.0-alpha/"));
+        instance.addRule(new DependencyRule("org.codehaus.plexus plexus-maven-plugin maven-plugin s/.*/1.3.8/"));
+        instance.cleanPom(pom, updatedPom, pomProperties, noParent, false, "libplexus-active-collections-java");
+        assertXMLEqual(read("plexus-active-collections.cleaned"), read(updatedPom));
+        Properties pomInfo = new Properties();
+        pomInfo.load(new FileReader(pomProperties));
+        assertEquals("org.codehaus.plexus", pomInfo.get("groupId"));
+        assertEquals("plexus-active-collections", pomInfo.get("artifactId"));
+        assertEquals("jar", pomInfo.get("type"));
+        assertEquals("1.0-beta-2", pomInfo.get("version"));
+        assertEquals("debian", pomInfo.get("debianVersion"));
+    }
+
+    /**
+     * Test of cleanPom method, of class POMCleaner.
+     */
     public void testCleanSlf4jPom() throws Exception {
         pomProperties = new File(testDir, "pom.properties");
         usePom("slf4j.xml");

Added: trunk/maven-repo-helper/src/test/resources/plexus-active-collections.cleaned
===================================================================
--- trunk/maven-repo-helper/src/test/resources/plexus-active-collections.cleaned	                        (rev 0)
+++ trunk/maven-repo-helper/src/test/resources/plexus-active-collections.cleaned	2009-06-26 19:37:04 UTC (rev 8615)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.codehaus.plexus</groupId>
+	<artifactId>plexus-active-collections</artifactId>
+	<version>debian</version>
+	<packaging>jar</packaging>
+	<properties>
+		<debian.originalVersion>1.0-beta-2</debian.originalVersion>
+		<debian.package>libplexus-active-collections-java</debian.package>
+	</properties>
+
+	<name>Plexus Container-Backed Active Collections</name>
+	<dependencies>
+		<dependency>
+			<groupId>org.codehaus.plexus</groupId>
+			<artifactId>plexus-component-api</artifactId>
+			<version>debian</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.codehaus.plexus</groupId>
+			<artifactId>plexus-container-default</artifactId>
+			<version>1.0-alpha</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.x</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+	<scm>
+		<connection>scm:svn:http://svn.codehaus.org/plexus/tags/plexus-active-collections-1.0-beta-2</connection>
+		<developerConnection>scm:svn:https://svn.codehaus.org/plexus/tags/plexus-active-collections-1.0-beta-2</developerConnection>
+	</scm>
+</project>
\ No newline at end of file

Added: trunk/maven-repo-helper/src/test/resources/plexus-active-collections.pom
===================================================================
--- trunk/maven-repo-helper/src/test/resources/plexus-active-collections.pom	                        (rev 0)
+++ trunk/maven-repo-helper/src/test/resources/plexus-active-collections.pom	2009-06-26 19:37:04 UTC (rev 8615)
@@ -0,0 +1,81 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>plexus-components</artifactId>
+    <groupId>org.codehaus.plexus</groupId>
+    <version>1.1.6</version>
+  </parent>
+
+  <artifactId>plexus-active-collections</artifactId>
+  <version>1.0-beta-2</version>
+  <name>Plexus Container-Backed Active Collections</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-component-api</artifactId>
+      <version>1.0-alpha-22</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-22</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <exclude>**/TestComponent.java</exclude>
+            <exclude>**/TestBadComponent.java</exclude>
+            <exclude>**/*TCK.java</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <version>1.3</version>
+        <executions>
+          <execution>
+            <id>create-component-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <!--
+          <execution>
+            <id>merge</id>
+            <configuration>
+              <output>${project.build.outputDirectory}/META-INF/plexus/components.xml</output>
+              <descriptors>
+                <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
+                <descriptor>src/main/resources/META-INF/plexus/components.xml</descriptor>
+              </descriptors>
+            </configuration>
+            <phase>generate-resources</phase>
+            <goals>
+              <goal>merge-descriptors</goal>
+            </goals>
+          </execution>
+           -->
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <scm>
+    <connection>scm:svn:http://svn.codehaus.org/plexus/tags/plexus-active-collections-1.0-beta-2</connection>
+    <developerConnection>scm:svn:https://svn.codehaus.org/plexus/tags/plexus-active-collections-1.0-beta-2</developerConnection>
+  </scm>
+</project>
\ No newline at end of file

Modified: trunk/maven-repo-helper/src/test/resources/plexus-container-default.cleaned
===================================================================
--- trunk/maven-repo-helper/src/test/resources/plexus-container-default.cleaned	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/test/resources/plexus-container-default.cleaned	2009-06-26 19:37:04 UTC (rev 8615)
@@ -8,7 +8,7 @@
   <properties>
     <debian.originalVersion>1.0-alpha-9-stable-1</debian.originalVersion>
     <debian.package>libplexus-container-default-java</debian.package>
-	<debian.mavenRule><![CDATA[org.codehaus.plexus plexus-container-default jar s/1\.0-alpha-.*/1.0-alpha/]]></debian.mavenRule>
+    <debian.mavenRules><![CDATA[org.codehaus.plexus plexus-container-default jar s/1\.0-alpha-.*/1.0-alpha/]]></debian.mavenRules>
   </properties>
   <name>Default Plexus Container</name>
 

Modified: trunk/maven-repo-helper/src/test/resources/plexus-container-default.transformed
===================================================================
--- trunk/maven-repo-helper/src/test/resources/plexus-container-default.transformed	2009-06-26 01:54:47 UTC (rev 8614)
+++ trunk/maven-repo-helper/src/test/resources/plexus-container-default.transformed	2009-06-26 19:37:04 UTC (rev 8615)
@@ -12,7 +12,7 @@
 	</parent>
 	<properties>
 		<debian.originalVersion>1.0-alpha-9-stable-1</debian.originalVersion>
-		<debian.mavenRule><![CDATA[org.codehaus.plexus plexus-container-default jar s/1\.0-alpha-.*/1.0-alpha/]]></debian.mavenRule>
+		<debian.mavenRules><![CDATA[org.codehaus.plexus plexus-container-default jar s/1\.0-alpha-.*/1.0-alpha/]]></debian.mavenRules>
 	</properties>
 
 	<name>Default Plexus Container</name>




More information about the pkg-java-commits mailing list