ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r658922 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/plugins/parser/m2/
Date Wed, 21 May 2008 23:01:48 GMT
Author: maartenc
Date: Wed May 21 16:01:47 2008
New Revision: 658922

URL: http://svn.apache.org/viewvc?rev=658922&view=rev
Log:
FIX: Maven scope defined in POM dependencyManagement section not honoured (IVY-811)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java
    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

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=658922&r1=658921&r2=658922&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Wed May 21 16:01:47 2008
@@ -81,6 +81,7 @@
 - IMPROVEMENT: Change allownomd and skipbuildwithoutivy into a more semantically correct
name (IVY-297)
 - IMPROVEMENT: Smarter determination if an expression is exact or not for RegexpPatternMatcher
and GlobPatternMatcher
 
+- FIX: Maven scope defined in POM dependencyManagement section not honoured (IVY-811)
 - FIX: SFTPRepository incorrectly calculates last modified time for resources (IVY-815)
 - FIX: Filesystem resolver does not evaluate [branch] token when publishing (IVY-814)
 - FIX: Using ivy:settings with the "id" attribute not behaving as expected (IVY-809)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java?rev=658922&r1=658921&r2=658922&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java
Wed May 21 16:01:47 2008
@@ -21,11 +21,17 @@
     private String groupId;
     private String artifactId;
     private String version;
+    private String scope;
     
-    public DefaultPomDependencyMgt(String groupId, String artifactId, String version) {
+    public DefaultPomDependencyMgt(String groupId, String artifactId, String version, String
scope) {
         this.groupId = groupId;
         this.artifactId = artifactId;
         this.version = version;
+        this.scope = scope;
+    }
+    
+    public String getScope() {
+        return scope;
     }
 
     public String getGroupId() {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java?rev=658922&r1=658921&r2=658922&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java Wed
May 21 16:01:47 2008
@@ -24,5 +24,7 @@
     public abstract String getArtifactId();
 
     public abstract String getVersion();
+    
+    public abstract String getScope();
 
 }
\ No newline at end of file

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=658922&r1=658921&r2=658922&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
Wed May 21 16:01:47 2008
@@ -56,7 +56,7 @@
 public class PomModuleDescriptorBuilder {
 
     
-    private static final int DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT = 3;
+    private static final int DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT = 4;
 
     public static final Configuration[] MAVEN2_CONFIGURATIONS = new Configuration[] {
         new Configuration("default", Visibility.PUBLIC,
@@ -227,8 +227,10 @@
 
 
     public void addDependency(Resource res, PomDependencyData dep) throws ParseException
{
-        if (!MAVEN2_CONF_MAPPING.containsKey(dep.getScope())) {
-            String msg = "Unknown scope " + dep.getScope() + " for dependency "
+        String scope = dep.getScope();
+        System.out.println("*** scope = " + scope);
+        if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope))
{
+            String msg = "Unknown scope '" + scope + "' for dependency "
                     + ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId()) + " in
"
                     + res.getName();
             throw new ParseException(msg, 0);
@@ -240,7 +242,8 @@
                 .getArtifactId(), version);
         DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor,
                 moduleRevId, true, false, true);
-        ConfMapper mapping = (ConfMapper) MAVEN2_CONF_MAPPING.get(dep.getScope());
+        scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep): scope;
+        ConfMapper mapping = (ConfMapper) MAVEN2_CONF_MAPPING.get(scope);
         mapping.addMappingConfs(dd, dep.isOptional());
         Map extraAtt = new HashMap();
         if (dep.getClassifier() != null) {
@@ -252,7 +255,7 @@
                         "jar", "jar", null, extraAtt);
             // here we have to assume a type and ext for the artifact, so this is a limitation
             // compared to how m2 behave with classifiers
-            String optionalizedScope = dep.isOptional() ? "optional" : dep.getScope();
+            String optionalizedScope = dep.isOptional() ? "optional" : scope;
             dd.addDependencyArtifact(optionalizedScope, depArtifact);
         }
         
@@ -278,8 +281,12 @@
 
 
     public void addDependencyMgt(PomDependencyMgt dep) {
-        String key = getDependencyMgtExtraInfoKey(dep.getGroupId(), dep.getArtifactId());
+        String key = getDependencyMgtExtraInfoKeyForVersion(dep.getGroupId(), dep.getArtifactId());
         ivyModuleDescriptor.addExtraInfo(key, dep.getVersion());
+        if (dep.getScope() != null) {
+            String scopeKey = getDependencyMgtExtraInfoKeyForScope(dep.getGroupId(), dep.getArtifactId());
+            ivyModuleDescriptor.addExtraInfo(scopeKey, dep.getScope());
+        }
         // dependency management info is also used for version mediation of transitive dependencies
         ivyModuleDescriptor.addDependencyDescriptorMediator(
             ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId()), 
@@ -336,17 +343,34 @@
         public String getVersion() {
             return version;
         }
+        
+        public String getScope() {
+            return null;
+        }
     }
 
     private String getDefaultVersion(PomDependencyData dep) {
-        String key = getDependencyMgtExtraInfoKey(dep.getGroupId(), dep.getArtifactId());
       
+        String key = getDependencyMgtExtraInfoKeyForVersion(dep.getGroupId(), dep.getArtifactId());
       
         return (String) ivyModuleDescriptor.getExtraInfo().get(key);
     }
 
+    private String getDefaultScope(PomDependencyData dep) {
+        String key = getDependencyMgtExtraInfoKeyForScope(dep.getGroupId(), dep.getArtifactId());
       
+        String result = (String) ivyModuleDescriptor.getExtraInfo().get(key);
+        if (result == null) {
+            result = "compile";
+        }
+        return result;
+    }
 
-    private static String getDependencyMgtExtraInfoKey(String groupId, String artifaceId)
{
+    private static String getDependencyMgtExtraInfoKeyForVersion(String groupId, String artifaceId)
{
         return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId
-                + EXTRA_INFO_DELIMITER + artifaceId;
+                + EXTRA_INFO_DELIMITER + artifaceId + EXTRA_INFO_DELIMITER + "version";
+    }
+    
+    private static String getDependencyMgtExtraInfoKeyForScope(String groupId, String artifaceId)
{
+        return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId
+                + EXTRA_INFO_DELIMITER + artifaceId + EXTRA_INFO_DELIMITER + "scope";
     }
     
     private static String getPropertyExtraInfoKey(String propertyName) {
@@ -372,6 +396,32 @@
         return ret;
     }
     
+    public static List getDependencyManagements(ModuleDescriptor md) {
+        List result = new ArrayList();
+        
+        for (Iterator iterator = md.getExtraInfo().entrySet().iterator(); iterator.hasNext();)
{
+            Map.Entry entry = (Map.Entry) iterator.next();
+            String key = (String) entry.getKey();
+            if ((key).startsWith(DEPENDENCY_MANAGEMENT)) {
+                String[] parts = key.split(EXTRA_INFO_DELIMITER);
+                if (parts.length != DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT) {
+                    Message.warn("what seem to be a dependency management extra info "
+                        + "doesn't match expected pattern: " + key);
+                } else {
+                    String versionKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1]
+ EXTRA_INFO_DELIMITER + parts[2] + EXTRA_INFO_DELIMITER + "version";
+                    String scopeKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1]
+ EXTRA_INFO_DELIMITER + parts[2] + EXTRA_INFO_DELIMITER + "scope";
+
+                    String version = (String) md.getExtraInfo().get(versionKey);
+                    String scope = (String) md.getExtraInfo().get(scopeKey);
+                    
+                    result.add(new DefaultPomDependencyMgt(parts[1], parts[2], version, scope));
+                }
+            }
+        }
+        
+        return result;
+    }
+    
 
     public void addExtraInfos(Map extraAttributes) {
         for (Iterator it = extraAttributes.entrySet().iterator(); it.hasNext();) {

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=658922&r1=658921&r2=658922&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
Wed May 21 16:01:47 2008
@@ -33,7 +33,6 @@
 import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
 import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
-import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.resolve.ResolveData;
 import org.apache.ivy.core.resolve.ResolveEngine;
@@ -41,6 +40,7 @@
 import org.apache.ivy.core.resolve.ResolvedModuleRevision;
 import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
 import org.apache.ivy.plugins.parser.ParserSettings;
+import org.apache.ivy.plugins.parser.m2.PomReader.PomPluginElement;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
 import org.apache.ivy.plugins.repository.Resource;
 import org.apache.ivy.plugins.repository.url.URLResource;
@@ -208,13 +208,9 @@
                     mdBuilder.addExtraInfos(parentDescr.getExtraInfo());
                     
                     // add dependency management info from parent
-                    Map depMgt = PomModuleDescriptorBuilder.getDependencyManagementMap(parentDescr);
-                    for (Iterator iterator = depMgt.entrySet().iterator(); iterator.hasNext();)
{
-                        Map.Entry entry = (Map.Entry) iterator.next();
-                        ModuleId mid = (ModuleId) entry.getKey();
-                        String v = (String) entry.getValue();
-                        mdBuilder.addDependencyMgt(
-                            new DefaultPomDependencyMgt(mid.getOrganisation(), mid.getName(),
v));
+                    List depMgt = PomModuleDescriptorBuilder.getDependencyManagements(parentDescr);
+                    for (Iterator it = depMgt.iterator(); it.hasNext();) {
+                        mdBuilder.addDependencyMgt((PomDependencyMgt) it.next());
                     }
                     
                     // add plugins from parent

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=658922&r1=658921&r2=658922&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 Wed May 21
16:01:47 2008
@@ -258,6 +258,11 @@
             return replaceProps(val);
         }
         
+        public String getScope() {
+            String val = getFirstChildText(depElement , SCOPE);
+            return replaceProps(val);
+        }
+        
     }
     
     public List /* <PomPluginElement> */ getPlugins() {
@@ -303,6 +308,10 @@
             return replaceProps(val);
         }
         
+        public String getScope() {
+            return null; // not used
+        }
+        
     }
     
     
@@ -315,11 +324,7 @@
         
         public String getScope() {
             String val = getFirstChildText(depElement , SCOPE);
-            if (val == null) {
-                return "compile";
-            } else {
-                return replaceProps(val);
-            }
+            return replaceProps(val);
         }
         
         public String getClassifier() {



Mime
View raw message