You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ma...@apache.org on 2010/06/14 23:49:11 UTC

svn commit: r954656 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/plugins/parser/m2/ test/java/org/apache/ivy/plugins/parser/m2/

Author: maartenc
Date: Mon Jun 14 21:49:11 2010
New Revision: 954656

URL: http://svn.apache.org/viewvc?rev=954656&view=rev
Log:
FIX: makepom ignores artifact type in ivy.xml and hardcodes 'jar' in the output pom (IVY-736)

Added:
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-packaging.xml   (with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=954656&r1=954655&r2=954656&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Mon Jun 14 21:49:11 2010
@@ -126,6 +126,7 @@ for detailed view of each issue, please 
 - IMPROVEMENT: Trace a message when a property file referenced from the settings doesn't exixts (IVY-1074)
 - IMPROVEMENT: use defaultconf in combination with defaultconfmapping (IVY-1135) (thanks to Jon Schneider)
 
+- FIX: makepom ignores artifact type in ivy.xml and hardcodes 'jar' in the output pom (IVY-736)
 - FIX: Ant output wasn't always prefixed by the name of the Ivy task
 - FIX: Resolved Ivy properties written to cache during ivy:resolve incorrectly represents forced revisions (IVY-1159)
 - FIX: Namespace rules not properly applied to parent projects (IVY-1186)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java?rev=954656&r1=954655&r2=954656&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java Mon Jun 14 21:49:11 2010
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.ivy.Ivy;
+import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
@@ -84,7 +85,18 @@ public final class PomModuleDescriptorWr
         ModuleRevisionId mrid = md.getModuleRevisionId();
         out.println("  <groupId>" + mrid.getOrganisation() + "</groupId>");
         out.println("  <artifactId>" + mrid.getName() + "</artifactId>");
-        out.println("  <packaging>jar</packaging>");
+        
+        String type;
+        
+        Artifact artifact = findArtifact(md);
+        if (artifact == null) {
+            // no suitable artifact found, default to 'pom'
+            type = "pom";
+        } else {
+            type = artifact.getType();
+        }
+
+        out.println("  <packaging>" + type + "</packaging>");
         if (mrid.getRevision() != null) {
             out.println("  <version>" + mrid.getRevision() + "</version>");
         }
@@ -92,6 +104,21 @@ public final class PomModuleDescriptorWr
             out.println("  <url>" + md.getHomePage() + "</url>");
         }
     }
+    
+    /**
+     * Returns the first artifact with the correct name and without a classifier.
+     */
+    private static Artifact findArtifact(ModuleDescriptor md) {
+        Artifact[] artifacts = md.getAllArtifacts();
+        for (int i = 0; i < artifacts.length; i++) {
+            if (artifacts[i].getName().equals(md.getModuleRevisionId().getName())
+                    && artifacts[i].getAttribute("classifier") == null) {
+                return artifacts[i];
+            }
+        }
+        
+        return null;
+    }
 
     private static void printDependencies(
             ModuleDescriptor md, ConfigurationScopeMapping mapping, PrintWriter out) {

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java?rev=954656&r1=954655&r2=954656&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java Mon Jun 14 21:49:11 2010
@@ -93,6 +93,19 @@ public class PomModuleDescriptorWriterTe
         assertEquals(expected, wrote);
     }
     
+    public void testPackaging() throws Exception {
+        ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(
+            new IvySettings(), getClass().getResource("test-packaging.pom"), false);
+        PomModuleDescriptorWriter.write(md, LICENSE, PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+        assertTrue(_dest.exists());
+
+        String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest))).replaceAll(
+            "\r\n", "\n").replace('\r', '\n');
+        String expected = readEntirely("test-write-packaging.xml")
+            .replaceAll("\r\n", "\n").replace('\r', '\n');
+        assertEquals(expected, wrote);
+    }
+    
     private String readEntirely(String resource) throws IOException {
         return FileUtil.readEntirely(new BufferedReader(new InputStreamReader(
             PomModuleDescriptorWriterTest.class.getResource(resource).openStream())));

Added: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-packaging.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-packaging.xml?rev=954656&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-packaging.xml (added)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-packaging.xml Mon Jun 14 21:49:11 2010
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<!--
+   Apache Maven 2 POM generated by Apache Ivy
+   http://ant.apache.org/ivy/
+-->
+<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>
+  <groupId>org.apache</groupId>
+  <artifactId>test</artifactId>
+  <packaging>war</packaging>
+  <version>1.0</version>
+  <url>http://ivy.jayasoft.org/</url>
+</project>

Propchange: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-packaging.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain