Repository: ant-ivy
Updated Branches:
  refs/heads/master 313d28f67 -> 3b17df0ab


IVY-1576 Fix parsing of (maven) dependency with multiple classifiers


Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/3b17df0a
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/3b17df0a
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/3b17df0a

Branch: refs/heads/master
Commit: 3b17df0ab67a1f14794bc6c60b735f3354caec9e
Parents: 313d28f
Author: Jaikiran Pai <jaiki...@apache.org>
Authored: Fri Mar 2 16:48:34 2018 +0530
Committer: Jaikiran Pai <jaiki...@apache.org>
Committed: Fri Mar 2 16:58:36 2018 +0530

----------------------------------------------------------------------
 .../parser/m2/PomModuleDescriptorBuilder.java   | 22 +++++++++++---
 .../apache/ivy/core/resolve/ResolveTest.java    | 31 ++++++++++++++++++++
 .../1.0/test-classified-1.0-other.jar           |  1 +
 .../1.0/test-classified-1.0-unix.jar            |  1 +
 .../test-classifier/1.0/test-classifier-1.0.pom | 12 ++++++++
 5 files changed, 63 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/3b17df0a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java 
b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
index 4f1d427..c57b6ee 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
@@ -297,8 +297,12 @@ public class PomModuleDescriptorBuilder {
                     dep.getArtifactId());
         }
         final boolean excludeAllTransitiveDeps = 
shouldExcludeAllTransitiveDeps(excluded);
-        DefaultDependencyDescriptor dd = new PomDependencyDescriptor(dep, 
ivyModuleDescriptor,
-                moduleRevId, !excludeAllTransitiveDeps);
+        // the same dependency mrid could appear twice in the module 
descriptor,
+        // so we check if we already have created a dependency descriptor for 
the dependency mrid
+        final DependencyDescriptor existing = 
this.ivyModuleDescriptor.depDescriptors.get(moduleRevId);
+        final DefaultDependencyDescriptor dd = (existing != null && existing 
instanceof DefaultDependencyDescriptor)
+                ? (DefaultDependencyDescriptor) existing
+                : new PomDependencyDescriptor(dep, ivyModuleDescriptor, 
moduleRevId, !excludeAllTransitiveDeps);
         if (isNullOrEmpty(scope)) {
             scope = getDefaultScope(dep);
         }
@@ -346,8 +350,10 @@ public class PomModuleDescriptorBuilder {
                         PatternMatcher.ANY_EXPRESSION), 
ExactPatternMatcher.INSTANCE, null));
             }
         }
-
-        ivyModuleDescriptor.addDependency(dd);
+        // intentional identity check to make sure we don't re-add the same 
dependency
+        if (existing != dd) {
+            ivyModuleDescriptor.addDependency(dd);
+        }
     }
 
     private static boolean shouldExcludeAllTransitiveDeps(final List<ModuleId> 
exclusions) {
@@ -723,6 +729,8 @@ public class PomModuleDescriptorBuilder {
 
     public static class PomModuleDescriptor extends DefaultModuleDescriptor {
         private final Map<ModuleId, PomDependencyMgt> dependencyManagementMap 
= new LinkedHashMap<>();
+        // dependency descriptor keyed by its dependency revision id
+        private final Map<ModuleRevisionId, DependencyDescriptor> 
depDescriptors = new HashMap<>();
 
         public PomModuleDescriptor(ModuleDescriptorParser parser, Resource 
res) {
             super(parser, res);
@@ -737,5 +745,11 @@ public class PomModuleDescriptorBuilder {
         public Map<ModuleId, PomDependencyMgt> getDependencyManagementMap() {
             return dependencyManagementMap;
         }
+
+        @Override
+        public void addDependency(final DependencyDescriptor dependency) {
+            super.addDependency(dependency);
+            this.depDescriptors.put(dependency.getDependencyRevisionId(), 
dependency);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/3b17df0a/test/java/org/apache/ivy/core/resolve/ResolveTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/core/resolve/ResolveTest.java 
b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
index c3fe21a..f3bf74f 100644
--- a/test/java/org/apache/ivy/core/resolve/ResolveTest.java
+++ b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
@@ -27,6 +27,7 @@ import org.apache.ivy.core.module.descriptor.DefaultArtifact;
 import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
 import org.apache.ivy.core.module.descriptor.ExtendsDescriptor;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.module.id.ArtifactRevisionId;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.report.ArtifactDownloadReport;
@@ -6287,4 +6288,34 @@ public class ResolveTest {
         assertEquals(new File(adr.getUnpackedLocalFile(), 
"META-INF/MANIFEST.MF"),
             jarContents[0].listFiles()[0]);
     }
+
+    /**
+     * Tests that if a pom.xml has multiple dependencies for the same module, 
but for different Maven classifiers,
+     * then the resolution of such dependencies, preserves those multiple 
(Ivy) artifacts against the dependency
+     *
+     * @throws Exception
+     * @see <a 
href="https://issues.apache.org/jira/browse/IVY-1576";>IVY-1576</a> for more 
details
+     */
+    @Test
+    public void testMultiClassifierMavenDepResolution() throws Exception {
+        final File pomFile = new 
File("test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom");
+        final ResolveReport resolveReport = 
ivy.resolve(pomFile.toURI().toURL(), new ResolveOptions().setConfs(new 
String[]{"*"}));
+        assertFalse(resolveReport.hasError());
+        final ModuleRevisionId dependencyId = 
ModuleRevisionId.newInstance("org.apache", "test-classified", "1.0");
+        final ArtifactDownloadReport[] adrs = 
resolveReport.getArtifactsReports(dependencyId);
+        assertNotNull("Artifact download reports is null for dependency " + 
dependencyId, adrs);
+        assertEquals("Unexpected number of artifact download reports for 
dependency " + dependencyId, 3, adrs.length);
+        final Set<String> classifiers = new HashSet<>();
+        Collections.addAll(classifiers, "other", "asl", "unix");
+        for (final ArtifactDownloadReport adr : adrs) {
+            final Artifact artifact = adr.getArtifact();
+            assertNotNull("Artifact is null for dependency " + dependencyId, 
artifact);
+            final ArtifactRevisionId artifactId = artifact.getId();
+            assertEquals("Unexpected artifact " + artifactId.getName(), 
"test-classified", artifactId.getName());
+            final String classifier = 
artifact.getExtraAttribute("m:classifier");
+            assertNotNull("No classifier extra attribute on artifact for 
dependency " + dependencyId, classifier);
+            assertTrue("Unexpected classifier " + classifier + " on artifact " 
+ artifact, classifiers.remove(classifier));
+        }
+        assertTrue("Missing artifact(s) with classifiers " + classifiers, 
classifiers.isEmpty());
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/3b17df0a/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-other.jar
----------------------------------------------------------------------
diff --git 
a/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-other.jar
 
b/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-other.jar
new file mode 100644
index 0000000..8d1c8b6
--- /dev/null
+++ 
b/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-other.jar
@@ -0,0 +1 @@
+ 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/3b17df0a/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-unix.jar
----------------------------------------------------------------------
diff --git 
a/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-unix.jar
 
b/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-unix.jar
new file mode 100644
index 0000000..8d1c8b6
--- /dev/null
+++ 
b/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0-unix.jar
@@ -0,0 +1 @@
+ 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/3b17df0a/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom
----------------------------------------------------------------------
diff --git 
a/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom 
b/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom
index f0e41f5..d8ca078 100644
--- 
a/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom
+++ 
b/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom
@@ -35,5 +35,17 @@
       <version>1.0</version>
       <classifier>asl</classifier>
     </dependency>
+    <dependency>
+      <groupId>org.apache</groupId>
+      <artifactId>test-classified</artifactId>
+      <version>1.0</version>
+      <classifier>other</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache</groupId>
+      <artifactId>test-classified</artifactId>
+      <version>1.0</version>
+      <classifier>unix</classifier>
+    </dependency>
   </dependencies>
 </project>

Reply via email to