diff -wur src.orig/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java src/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java --- src.orig/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java 2008-12-04 17:11:26 -0500 +++ src/java/org/apache/ivy/plugins/parser/m2/DefaultPomDependencyMgt.java 2009-02-25 18:14:51 -0500 @@ -17,18 +17,22 @@ */ package org.apache.ivy.plugins.parser.m2; +import java.util.List; + public class DefaultPomDependencyMgt implements PomDependencyMgt { private String groupId; private String artifactId; private String version; private String scope; + private List /**/ excludedModules; public DefaultPomDependencyMgt( - String groupId, String artifactId, String version, String scope) { + String groupId, String artifactId, String version, String scope, List /**/ excludedModules) { this.groupId = groupId; this.artifactId = artifactId; this.version = version; this.scope = scope; + this.excludedModules = excludedModules; } public String getScope() { @@ -45,5 +49,7 @@ return version; } - + public List /**/ getExcludedModules() { + return excludedModules; + } } diff -wur src.orig/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java src/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java --- src.orig/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java 2008-12-04 17:11:26 -0500 +++ src/java/org/apache/ivy/plugins/parser/m2/PomDependencyMgt.java 2009-02-25 17:48:38 -0500 @@ -17,6 +17,8 @@ */ package org.apache.ivy.plugins.parser.m2; +import java.util.List; + public interface PomDependencyMgt { public abstract String getGroupId(); @@ -27,4 +29,5 @@ public abstract String getScope(); + public List /**/ getExcludedModules(); } \ No newline at end of file diff -wur src.orig/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java --- src.orig/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java 2009-01-07 15:46:18 -0500 +++ src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java 2009-02-25 18:15:47 -0500 @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -305,7 +306,16 @@ dd.addDependencyArtifact(optionalizedScope, depArtifact); } - for (Iterator itExcl = dep.getExcludedModules().iterator(); itExcl.hasNext();) { + // It's not entirely clear to me how this should work but + // experimentation shows the following, excluded modules are + // inherited from parent POMs if either of the following is true: + // the element is missing or the element + // is present, but empty. + List /**/ excluded = dep.getExcludedModules(); + if(excluded.isEmpty()) { + excluded = getDependencyMgtExclusions(ivyModuleDescriptor, dep.getGroupId(), dep.getArtifactId()); + } + for (Iterator itExcl = excluded.iterator(); itExcl.hasNext();) { ModuleId excludedModule = (ModuleId) itExcl.next(); String[] confs = dd.getModuleConfigurations(); for (int k = 0; k < confs.length; k++) { @@ -334,6 +344,17 @@ dep.getGroupId(), dep.getArtifactId()); ivyModuleDescriptor.addExtraInfo(scopeKey, dep.getScope()); } + if(!dep.getExcludedModules().isEmpty()) { + final String exclusionPrefix = getDependencyMgtExtraInfoPrefixForExclusion( + dep.getGroupId(), dep.getArtifactId()); + int index = 0; + for(final Iterator iter = dep.getExcludedModules().iterator(); iter.hasNext();) { + final ModuleId excludedModule = (ModuleId) iter.next(); + ivyModuleDescriptor.addExtraInfo(exclusionPrefix + index, + excludedModule.getOrganisation() + EXTRA_INFO_DELIMITER + excludedModule.getName()); + index += 1; + } + } // dependency management info is also used for version mediation of transitive dependencies ivyModuleDescriptor.addDependencyDescriptorMediator( ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId()), @@ -394,6 +415,10 @@ public String getScope() { return null; } + + public List /**/ getExcludedModules() { + return Collections.EMPTY_LIST; // probably not used? at any rate I don't care about it. -jgibson + } } private String getDefaultVersion(PomDependencyData dep) { @@ -425,6 +450,38 @@ return PROPERTIES + EXTRA_INFO_DELIMITER + propertyName; } + private static String getDependencyMgtExtraInfoPrefixForExclusion( + String groupId, String artifaceId) { + return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId + + EXTRA_INFO_DELIMITER + artifaceId + EXTRA_INFO_DELIMITER + "exclusion_"; + } + + private static List /**/ getDependencyMgtExclusions( + final ModuleDescriptor descriptor, + final String groupId, + final String artifactId) { + final String exclusionPrefix = getDependencyMgtExtraInfoPrefixForExclusion( + groupId, artifactId); + final List /**/ exclusionIds = new LinkedList /**/ (); + final Map /**/ extras = descriptor.getExtraInfo(); + for (final Iterator entIter = extras.entrySet().iterator(); entIter.hasNext();) { + final Map.Entry /**/ ent = (Map.Entry) entIter.next(); + final String key = (String) ent.getKey(); + if (key.startsWith(exclusionPrefix)) { + final String full_exclusion = (String) ent.getValue(); + final String[] exclusion_parts = full_exclusion.split(EXTRA_INFO_DELIMITER); + if(exclusion_parts.length != 2) { + Message.error("what seemed to be a dependency management extra info exclusion " + + "had the wrong number of parts (should have 2) " + exclusion_parts.length + " : " + full_exclusion); + continue; + } + exclusionIds.add(ModuleId.newInstance(exclusion_parts[0], exclusion_parts[1])); + } + } + + return exclusionIds; + } + public static Map/**/ getDependencyManagementMap(ModuleDescriptor md) { Map ret = new LinkedHashMap(); @@ -466,7 +523,8 @@ String version = (String) md.getExtraInfo().get(versionKey); String scope = (String) md.getExtraInfo().get(scopeKey); - result.add(new DefaultPomDependencyMgt(parts[1], parts[2], version, scope)); + List /**/ exclusions = getDependencyMgtExclusions(md, parts[1], parts[2]); + result.add(new DefaultPomDependencyMgt(parts[1], parts[2], version, scope, exclusions)); } } } diff -wur src.orig/java/org/apache/ivy/plugins/parser/m2/PomReader.java src/java/org/apache/ivy/plugins/parser/m2/PomReader.java --- src.orig/java/org/apache/ivy/plugins/parser/m2/PomReader.java 2008-12-15 17:35:28 -0500 +++ src/java/org/apache/ivy/plugins/parser/m2/PomReader.java 2009-02-25 17:56:36 -0500 @@ -25,6 +25,7 @@ import java.io.LineNumberReader; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -325,6 +326,24 @@ return replaceProps(val); } + public List /**/ getExcludedModules() { + Element exclusionsElement = getFirstChildElement(depElement, EXCLUSIONS); + LinkedList exclusions = new LinkedList(); + if (exclusionsElement != null) { + NodeList childs = exclusionsElement.getChildNodes(); + for (int i = 0; i < childs.getLength(); i++) { + Node node = childs.item(i); + if (node instanceof Element && EXCLUSION.equals(node.getNodeName())) { + String groupId = getFirstChildText((Element) node, GROUP_ID); + String artifactId = getFirstChildText((Element) node, ARTIFACT_ID); + if ((groupId != null) && (artifactId != null)) { + exclusions.add(ModuleId.newInstance(groupId, artifactId)); + } + } + } + } + return exclusions; + } } public List /* */ getPlugins() { @@ -374,6 +393,9 @@ return null; // not used } + public List /**/ getExcludedModules() { + return Collections.EMPTY_LIST; // probably not used? at any rate I don't care about it. -jgibson + } } @@ -403,26 +425,6 @@ Element e = getFirstChildElement(depElement, OPTIONAL); return (e != null) && "true".equalsIgnoreCase(getTextContent(e)); } - - public List /**/ getExcludedModules() { - Element exclusionsElement = getFirstChildElement(depElement, EXCLUSIONS); - LinkedList exclusions = new LinkedList(); - if (exclusionsElement != null) { - NodeList childs = exclusionsElement.getChildNodes(); - for (int i = 0; i < childs.getLength(); i++) { - Node node = childs.item(i); - if (node instanceof Element && EXCLUSION.equals(node.getNodeName())) { - String groupId = getFirstChildText((Element) node, GROUP_ID); - String artifactId = getFirstChildText((Element) node, ARTIFACT_ID); - if ((groupId != null) && (artifactId != null)) { - exclusions.add(ModuleId.newInstance(groupId, artifactId)); - } - } - } - } - return exclusions; - } - } /**