[pkg-java] r9050 - in trunk/maven-repo-helper: debian 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
Thu Jul 9 20:20:26 UTC 2009


Author: ludovicc-guest
Date: 2009-07-09 20:20:22 +0000 (Thu, 09 Jul 2009)
New Revision: 9050

Added:
   trunk/maven-repo-helper/src/test/resources/plexus-archiver.cleaned
   trunk/maven-repo-helper/src/test/resources/plexus-archiver.pom
Modified:
   trunk/maven-repo-helper/debian/changelog
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMInfo.java
   trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMTransformer.java
   trunk/maven-repo-helper/src/test/java/org/debian/maven/repo/POMCleanerTest.java
Log:
Repair missing version information on dependencies

Modified: trunk/maven-repo-helper/debian/changelog
===================================================================
--- trunk/maven-repo-helper/debian/changelog	2009-07-09 18:38:57 UTC (rev 9049)
+++ trunk/maven-repo-helper/debian/changelog	2009-07-09 20:20:22 UTC (rev 9050)
@@ -2,6 +2,7 @@
 
   * Move mh_genrules scripts to the maven-debian-helper package,
     as it needs mh_lspoms and other components from this package.
+  * Repair missing version information on dependencies
 
  -- Ludovic Claude <ludovic.claude at laposte.net>  Thu, 09 Jul 2009 15:53:25 +0100
 

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-07-09 18:38:57 UTC (rev 9049)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMInfo.java	2009-07-09 20:20:22 UTC (rev 9050)
@@ -9,6 +9,17 @@
 import java.util.TreeSet;
 
 public class POMInfo {
+    
+    public static final String DEPENDENCY_MANAGEMENT_LIST = "DependencyManagement";
+    public static final String PROFILE_DEPENDENCY_MANAGEMENT_LIST = "ProfileDependencyManagement";
+    public static final String DEPENDENCIES = "Dependencies";
+    public static final String PROFILE_DEPENDENCIES = "ProfileDependencies";
+    public static final String PLUGIN_DEPENDENCIES = "PluginDependencies";
+    public static final String PROFILE_PLUGIN_DEPENDENCIES = "ProfilePluginDependencies";
+    public static final String PLUGINS = "Plugins";
+    public static final String PLUGIN_MANAGEMENT = "PluginManagement";
+    public static final String EXTENSIONS = "Extensions";
+
     private String originalParentVersion;
     private Dependency originalPom;
     private Dependency parent;
@@ -261,4 +272,35 @@
             }
         }
     }
+
+    public List getDependencyList(String listSelector) {
+        if (DEPENDENCY_MANAGEMENT_LIST.equals(listSelector)) {
+            return getDependencyManagement();
+        }
+        if (PROFILE_DEPENDENCY_MANAGEMENT_LIST.equals(listSelector)) {
+            return getProfileDependencyManagement();
+        }
+        if (DEPENDENCIES.equals(listSelector)) {
+            return getDependencies();
+        }
+        if (PROFILE_DEPENDENCIES.equals(listSelector)) {
+            return getProfileDependencies();
+        }
+        if (PLUGIN_DEPENDENCIES.equals(listSelector)) {
+            return getPluginDependencies();
+        }
+        if (PROFILE_PLUGIN_DEPENDENCIES.equals(listSelector)) {
+            return getProfilePluginDependencies();
+        }
+        if (PLUGINS.equals(listSelector)) {
+            return getPlugins();
+        }
+        if (PLUGIN_MANAGEMENT.equals(listSelector)) {
+            return getPluginManagement();
+        }
+        if (EXTENSIONS.equals(listSelector)) {
+            return getExtensions();
+        }
+        return null;
+    }
 }

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-07-09 18:38:57 UTC (rev 9049)
+++ trunk/maven-repo-helper/src/main/java/org/debian/maven/repo/POMTransformer.java	2009-07-09 20:20:22 UTC (rev 9050)
@@ -134,7 +134,7 @@
             POMInfo info = readPom(originalPom);
 
             info = info.applyRules(rules);
-            Dependency parent = info.getParent();
+            Dependency parent = noParent ? null : info.getParent();
             Dependency pomInfo = info.getThisPom();
 
             // Second pass - create the new document
@@ -145,6 +145,7 @@
             int inPlugin = 0;
             int inProperty = 0;
             int inLevel = 0;
+            boolean sawVersion = false;
             List path = new ArrayList();
             Map dependencyIndexes = new HashMap();
             Dependency dependency = null;
@@ -175,38 +176,40 @@
                             path.add(element);
 
                             if ("project".equals(element) && inLevel == 1) {
-                                copyAndFillProjectHeader(parser, writer, inLevel, pomInfo, keepPomVersion, info, noParent, parent, debianPackage);
+                                copyAndFillProjectHeader(parser, writer, inLevel, pomInfo, keepPomVersion, info, parent, debianPackage);
                             } else if (inLevel == 2 && "properties".equals(element)) {
                                 inProperty++;
                             } else if (inProperty > 0) {
                                 inProperty++;
                             } else if ("dependency".equals(element)) {
                                 inDependency++;
+                                sawVersion = false;
                                 String parentElement = (String) path.get(path.size() - 2);
                                 String parentParentElement = (String) path.get(path.size() - 3);
                                 if ("dependencies".equals(parentElement)) {
-                                    List dependencyList = null;
+                                    String listSelector = null;
                                     if ("dependencyManagement".equals(parentParentElement)) {
                                         String p3Element = (String) path.get(path.size() - 4);
                                         if ("project".equals(p3Element)) {
-                                            dependencyList = info.getDependencyManagement();
+                                            listSelector = POMInfo.DEPENDENCY_MANAGEMENT_LIST;
                                         } else if ("profile".equals(p3Element)) {
-                                            dependencyList = info.getProfileDependencyManagement();
+                                            listSelector = POMInfo.PROFILE_DEPENDENCY_MANAGEMENT_LIST;
                                         }
                                     } else if ("project".equals(parentParentElement)) {
-                                        dependencyList = info.getDependencies();
+                                        listSelector = POMInfo.DEPENDENCIES;
                                     } else if ("profile".equals(parentParentElement)) {
-                                        dependencyList = info.getProfileDependencies();
+                                        listSelector = POMInfo.PROFILE_DEPENDENCIES;
                                     } else if ("plugin".equals(parentParentElement)) {
                                         String p5Element = (String) path.get(path.size() - 6);
                                         if ("project".equals(p5Element)) {
-                                            dependencyList = info.getPluginDependencies();
+                                            listSelector = POMInfo.PLUGIN_DEPENDENCIES;
                                         } else if ("profile".equals(p5Element)) {
-                                            dependencyList = info.getProfilePluginDependencies();
+                                            listSelector = POMInfo.PROFILE_PLUGIN_DEPENDENCIES;
                                         }
                                     }
-                                    if (dependencyList != null) {
-                                        int index = inc(dependencyIndexes, dependencyList);
+                                    if (listSelector != null) {
+                                        int index = inc(dependencyIndexes, listSelector);
+                                        List dependencyList = info.getDependencyList(listSelector);
                                         dependency = (Dependency) dependencyList.get(index);
                                     }
                                 }
@@ -216,6 +219,9 @@
                                 if ("exclusion".equals(element)) {
                                     inExclusion++;
                                 } else {
+                                    if ("version".equals(element)) {
+                                        sawVersion = true;
+                                    }
                                     inDependency++;
                                 }
                             } else if ("plugin".equals(element)) {
@@ -223,20 +229,19 @@
                                 String parentElement = (String) path.get(path.size() - 2);
                                 String parentParentElement = (String) path.get(path.size() - 3);
                                 if ("plugins".equals(parentElement)) {
-                                    List dependencyList;
+                                    String listSelector = POMInfo.PLUGINS;
                                     if ("pluginManagement".equals(parentParentElement)) {
-                                        dependencyList = info.getPluginManagement();
-                                    } else {
-                                        dependencyList = info.getPlugins();
+                                        listSelector = POMInfo.PLUGIN_MANAGEMENT;
                                     }
-                                    int index = inc(dependencyIndexes, dependencyList);
+                                    int index = inc(dependencyIndexes, listSelector);
+                                    List dependencyList = info.getDependencyList(listSelector);
                                     dependency = (Dependency) dependencyList.get(index);
                                 }
                             } else if (inPlugin > 0) {
                                 inPlugin++;
                             } else if ("extension".equals(element)) {
                                 inExtension++;
-                                int index = inc(dependencyIndexes, info.getExtensions());
+                                int index = inc(dependencyIndexes, POMInfo.EXTENSIONS);
                                 dependency = (Dependency) info.getExtensions().get(index);
                             } else if (inExtension > 0) {
                                 inExtension++;
@@ -251,6 +256,21 @@
                         if (inIgnoredElement > 0) {
                             inIgnoredElement--;
                         } else {
+                            // Attempt to repair missing version information on dependencies
+                            if (inDependency == 1 && !sawVersion && parent == null) {
+                                if (dependency.getVersion() == null) {
+                                    dependency.setVersion("debian");
+                                    // Give a chance to customize the version
+                                    // In maven.rules, you can write:
+                                    // myDependencyGroup myDependencyArtifact * s/.*/myVersion/
+                                    dependency = dependency.applyRules(rules);
+                                }
+                                indent(writer, inLevel);
+                                writer.writeStartElement("version");
+                                writer.writeCharacters(dependency.getVersion());
+                                writer.writeEndElement();
+                            }
+
                             inLevel--;
                             path.remove(path.size() - 1);
                             if (inExclusion > 0) {
@@ -322,7 +342,7 @@
         }
     }
 
-    private void copyAndFillProjectHeader(XMLStreamReader parser, XMLStreamWriter writer, int inLevel, Dependency pomInfo, boolean keepPomVersion, POMInfo info, boolean noParent, Dependency parent, String debianPackage) throws XMLStreamException {
+    private void copyAndFillProjectHeader(XMLStreamReader parser, XMLStreamWriter writer, int inLevel, Dependency pomInfo, boolean keepPomVersion, POMInfo info, Dependency parent, String debianPackage) throws XMLStreamException {
         if (parser.getNamespaceCount() == 0) {
             writer.writeNamespace(null, "http://maven.apache.org/POM/4.0.0");
             writer.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
@@ -354,7 +374,7 @@
         writer.writeCharacters(pomInfo.getType());
         writer.writeEndElement();
         indent(writer, inLevel);
-        if (!noParent && parent != null) {
+        if (parent != null) {
             writer.writeStartElement("parent");
             indent(writer, inLevel + 1);
             writer.writeStartElement("groupId");
@@ -422,14 +442,14 @@
         return INFO_ELEMENTS.contains(element);
     }
 
-    private int inc(Map dependencyIndexes, List dependencyList) {
-        Integer index = (Integer) dependencyIndexes.get(dependencyList);
+    private int inc(Map dependencyIndexes, String selector) {
+        Integer index = (Integer) dependencyIndexes.get(selector);
         if (index == null) {
             index = new Integer(0);
         } else {
             index = new Integer(index.intValue() + 1);
         }
-        dependencyIndexes.put(dependencyList, index);
+        dependencyIndexes.put(selector, index);
         return index.intValue();
     }
 

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-07-09 18:38:57 UTC (rev 9049)
+++ trunk/maven-repo-helper/src/test/java/org/debian/maven/repo/POMCleanerTest.java	2009-07-09 20:20:22 UTC (rev 9050)
@@ -148,6 +148,26 @@
     /**
      * Test of cleanPom method, of class POMCleaner.
      */
+    public void testCleanPlexusArchiverPom() throws Exception {
+        pomProperties = new File(testDir, "pom.properties");
+        usePom("plexus-archiver.pom");
+        boolean noParent = true;
+        POMCleaner instance = new POMCleaner();
+        instance.addDefaultRules();
+        instance.cleanPom(pom, updatedPom, pomProperties, noParent, false, "libplexus-archiver-java");
+        assertXMLEqual(read("plexus-archiver.cleaned"), read(updatedPom));
+        Properties pomInfo = new Properties();
+        pomInfo.load(new FileReader(pomProperties));
+        assertEquals("org.codehaus.plexus", pomInfo.get("groupId"));
+        assertEquals("plexus-achiver", pomInfo.get("artifactId"));
+        assertEquals("jar", pomInfo.get("type"));
+        assertEquals("1.0-alpha-12", 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-archiver.cleaned
===================================================================
--- trunk/maven-repo-helper/src/test/resources/plexus-archiver.cleaned	                        (rev 0)
+++ trunk/maven-repo-helper/src/test/resources/plexus-archiver.cleaned	2009-07-09 20:20:22 UTC (rev 9050)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.codehaus.plexus</groupId>
+	<artifactId>plexus-archiver</artifactId>
+	<version>debian</version>
+	<packaging>jar</packaging>
+	<properties>
+		<debian.originalVersion>1.0-alpha-12</debian.originalVersion>
+		<debian.package>libplexus-archiver-java</debian.package>
+	</properties>
+
+	<name>Plexus Archiver Component</name>
+	<contributors>
+		<contributor>
+			<name>Dan Tran</name>
+		</contributor>
+		<contributor>
+			<name>Richard van der Hoff</name>
+		</contributor>
+	</contributors>
+	<dependencies>
+		<dependency>
+			<groupId>org.codehaus.plexus</groupId>
+			<artifactId>plexus-container-default</artifactId>
+        		<version>debian</version>
+		</dependency>
+		<dependency>
+			<groupId>org.codehaus.plexus</groupId>
+			<artifactId>plexus-utils</artifactId>
+        		<version>debian</version>
+		</dependency>
+		<dependency>
+			<groupId>org.codehaus.plexus</groupId>
+			<artifactId>plexus-io</artifactId>
+			<version>debian</version>
+		</dependency>
+	</dependencies>
+	<scm>
+		<connection>scm:svn:http://svn.codehaus.org/plexus/plexus-components/tags/plexus-archiver-1.0-alpha-12</connection>
+		<developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-components/tags/plexus-archiver-1.0-alpha-12</developerConnection>
+		<url>http://fisheye.codehaus.org/browse/plexus/plexus-components/tags/plexus-archiver-1.0-alpha-12</url>
+	</scm>
+</project>
\ No newline at end of file

Added: trunk/maven-repo-helper/src/test/resources/plexus-archiver.pom
===================================================================
--- trunk/maven-repo-helper/src/test/resources/plexus-archiver.pom	                        (rev 0)
+++ trunk/maven-repo-helper/src/test/resources/plexus-archiver.pom	2009-07-09 20:20:22 UTC (rev 9050)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>plexus-components</artifactId>
+    <groupId>org.codehaus.plexus</groupId>
+    <version>1.1.14</version>
+  </parent>
+
+  <artifactId>plexus-archiver</artifactId>
+  <version>1.0-alpha-12</version>
+
+  <name>Plexus Archiver Component</name>
+
+  <contributors>
+    <contributor>
+      <name>Dan Tran</name>
+    </contributor>
+    <contributor>
+      <name>Richard van der Hoff</name>
+    </contributor>
+  </contributors>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-io</artifactId>
+      <version>1.0-alpha-4</version>
+    </dependency>
+  </dependencies>
+
+  <scm>
+    <connection>scm:svn:http://svn.codehaus.org/plexus/plexus-components/tags/plexus-archiver-1.0-alpha-12</connection>
+    <developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-components/tags/plexus-archiver-1.0-alpha-12</developerConnection>
+    <url>http://fisheye.codehaus.org/browse/plexus/plexus-components/tags/plexus-archiver-1.0-alpha-12</url>
+  </scm>
+</project>
\ No newline at end of file




More information about the pkg-java-commits mailing list