ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1132472 - in /ant/ivy/core/trunk: src/java/org/apache/ivy/plugins/parser/m2/ test/java/org/apache/ivy/plugins/parser/m2/
Date Sun, 05 Jun 2011 18:24:32 GMT
Author: mbenson
Date: Sun Jun  5 18:24:31 2011
New Revision: 1132472

URL: http://svn.apache.org/viewvc?rev=1132472&view=rev
Log:
[IVY-1299] Ivy does not apply overridden properties to parent dependency versions specified
using properties

Added:
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-override-parent-properties.pom
Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java?rev=1132472&r1=1132471&r2=1132472&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
Sun Jun  5 18:24:31 2011
@@ -292,8 +292,7 @@ public class PomModuleDescriptorBuilder 
             return;
         }
 
-        DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor,
-                moduleRevId, true, false, true);
+        DefaultDependencyDescriptor dd = new PomDependencyDescriptor(dep, ivyModuleDescriptor,
moduleRevId);
         scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
         ConfMapper mapping = (ConfMapper) MAVEN2_CONF_MAPPING.get(scope);
         mapping.addMappingConfs(dd, dep.isOptional());
@@ -631,5 +630,25 @@ public class PomModuleDescriptorBuilder 
     public void addJavadocArtifact() {
         ivyModuleDescriptor.addArtifact("javadoc", getJavadocArtifact());
     }
-    
+
+    /**
+     * <code>DependencyDescriptor</code> that provides access to the original
<code>PomDependencyData</code>.
+     */
+    public static class PomDependencyDescriptor extends DefaultDependencyDescriptor {
+        private final PomDependencyData pomDependencyData;
+
+        private PomDependencyDescriptor(PomDependencyData pomDependencyData,
+                ModuleDescriptor moduleDescriptor, ModuleRevisionId revisionId) {
+            super(moduleDescriptor, revisionId, true, false, true);
+            this.pomDependencyData = pomDependencyData;
+        }
+
+        /**
+         * Get PomDependencyData.
+         * @return PomDependencyData
+         */
+        public PomDependencyData getPomDependencyData() {
+            return pomDependencyData;
+        }
+    }
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java?rev=1132472&r1=1132471&r2=1132472&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
Sun Jun  5 18:24:31 2011
@@ -44,6 +44,8 @@ import org.apache.ivy.core.resolve.Resol
 import org.apache.ivy.plugins.namespace.NameSpaceHelper;
 import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
 import org.apache.ivy.plugins.parser.ParserSettings;
+import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorBuilder.PomDependencyDescriptor;
+import org.apache.ivy.plugins.parser.m2.PomReader.PomDependencyData;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
 import org.apache.ivy.plugins.repository.Resource;
 import org.apache.ivy.plugins.repository.url.URLResource;
@@ -264,7 +266,14 @@ public final class PomModuleDescriptorPa
 
                 if (parentDescr != null) {
                     for (int i = 0; i < parentDescr.getDependencies().length; i++) {
-                        mdBuilder.addDependency(parentDescr.getDependencies()[i]);
+                        DependencyDescriptor descriptor = parentDescr.getDependencies()[i];
+                        if (descriptor instanceof PomDependencyDescriptor) {
+                            PomDependencyData parentDep = ((PomDependencyDescriptor) descriptor).getPomDependencyData();
+                            PomDependencyData dep = domReader.new PomDependencyData(parentDep);
+                            mdBuilder.addDependency(res, dep);
+                        } else {
+                            mdBuilder.addDependency(descriptor);
+                        }
                     }
                 }
                 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java?rev=1132472&r1=1132471&r2=1132472&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java Sun Jun  5
18:24:31 2011
@@ -402,11 +402,16 @@ public class PomReader {
     
     public class PomDependencyData extends PomDependencyMgtElement {
         private final Element depElement;
+
+        public PomDependencyData(PomDependencyData copyFrom) {
+            this(copyFrom.depElement);
+        }
+
         PomDependencyData(Element depElement) {
             super(depElement);
             this.depElement = depElement;
         }
-        
+
         public String getScope() {
             String val = getFirstChildText(depElement , SCOPE);
             return replaceProps(val);
@@ -426,6 +431,7 @@ public class PomReader {
             Element e = getFirstChildElement(depElement, OPTIONAL); 
             return (e != null) && "true".equalsIgnoreCase(getTextContent(e));
         }
+
     }
     
     /**
@@ -443,8 +449,7 @@ public class PomReader {
         }
         return pomProperties;
     }
-    
-   
+
     private String replaceProps(String val) {
         if (val == null) {
             return null;

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java?rev=1132472&r1=1132471&r2=1132472&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
Sun Jun  5 18:24:31 2011
@@ -701,6 +701,32 @@ public class PomModuleDescriptorParserTe
         assertEquals(ModuleRevisionId.newInstance("org.apache", "test-version-other", "5.76"),
dds[0]
                 .getDependencyRevisionId());//present in the pom using a property defined
in the parent
     }
+
+    public void testOverrideParentProperties() throws ParseException, IOException {
+        settings.setDictatorResolver(new MockResolver() {
+            public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData
data) throws ParseException {
+                try {
+                    ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(
+                        settings, getClass().getResource("test-version.pom"), false);
+                    return new ResolvedModuleRevision(null,null,moduleDescriptor,null);
+                } catch (IOException e) {
+                    throw new AssertionError(e);
+                }
+            }
+        });
+        ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(
+            settings, getClass().getResource("test-override-parent-properties.pom"), false);
+        assertNotNull(md);
+        assertEquals("1.0", md.getRevision());
+        
+        DependencyDescriptor[] dds = md.getDependencies();
+        assertNotNull(dds);
+        assertEquals(2, dds.length); 
+        //2 are inherited from parent.  Only the first one is important for this test
+        
+        assertEquals(ModuleRevisionId.newInstance("org.apache", "test-yet-other", "5.79"),
dds[1]
+                .getDependencyRevisionId());//present in the pom using a property defined
in the parent
+    }
     
     public void testPomWithEntity() throws Exception {
         ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(

Added: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-override-parent-properties.pom
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-override-parent-properties.pom?rev=1132472&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-override-parent-properties.pom
(added)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-override-parent-properties.pom
Sun Jun  5 18:24:31 2011
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!--
+   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.    
+-->
+<project>
+  <parent>
+    <artifactId>test-version</artifactId>
+    <groupId>org.apache</groupId>
+    <version>1.0</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache</groupId>
+  <artifactId>test</artifactId>
+  <name>Test Module for Ivy M2 parsing</name>
+  <version>${test-version-version}</version>
+  <url>http://ivy.jayasoft.org/</url>
+  <organization>
+    <name>Jayasoft</name>
+    <url>http://www.jayasoft.org/</url>
+  </organization>
+  <properties>
+  	<test-yet-other-version>5.79</test-yet-other-version>
+  </properties>
+</project>



Mime
View raw message