You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ja...@apache.org on 2019/09/21 12:16:05 UTC

[ant-ivy] branch master updated: IVY-1586 Set the correct "conf" on the "artifact" of the dependency when parsing a pom.xml

This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant-ivy.git


The following commit(s) were added to refs/heads/master by this push:
     new 3fc5340  IVY-1586 Set the correct "conf" on the "artifact" of the dependency when parsing a pom.xml
3fc5340 is described below

commit 3fc534020f71e0f86afbc0888dec6d11265f5cb3
Author: Jaikiran Pai <ja...@apache.org>
AuthorDate: Sat Sep 21 17:45:35 2019 +0530

    IVY-1586 Set the correct "conf" on the "artifact" of the dependency when parsing a pom.xml
---
 .../parser/m2/PomModuleDescriptorBuilder.java      |  5 +-
 .../parser/xml/XmlModuleDescriptorWriter.java      |  8 ++-
 .../org/apache/ivy/core/resolve/ResolveTest.java   | 66 ++++++++++++++++++++++
 test/repositories/1/ivy-1586/ivy-1586.xml          | 27 +++++++++
 4 files changed, 101 insertions(+), 5 deletions(-)

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 c1accb8..87690f0 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
@@ -335,11 +335,12 @@ public class PomModuleDescriptorBuilder {
             if (dep.getClassifier() != null) {
                 extraAtt.put("m:classifier", dep.getClassifier());
             }
-            DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(
+            final DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(
                     dd, dd.getDependencyId().getName(), type, ext, 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" : scope;
+            final String optionalizedScope = dep.isOptional() ? "optional" : scope;
+            depArtifact.addConfiguration(optionalizedScope);
             dd.addDependencyArtifact(optionalizedScope, depArtifact);
         }
 
diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
index 5ddaff3..44825b8 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
@@ -272,9 +272,11 @@ public final class XmlModuleDescriptorWriter {
                         XMLHelper.escape(depArtifact.getName()),
                         XMLHelper.escape(depArtifact.getType()),
                         XMLHelper.escape(depArtifact.getExt())));
-                String[] dadConfs = depArtifact.getConfigurations();
-                if (!Arrays.asList(dadConfs).equals(Arrays.asList(md.getConfigurationsNames()))) {
-                    out.print(listToPrefixedString(dadConfs, " conf=\""));
+                final String[] dadConfs = depArtifact.getConfigurations();
+                if (dadConfs != null && dadConfs.length > 0) {
+                    if (!Arrays.asList(dadConfs).equals(Arrays.asList(md.getConfigurationsNames()))) {
+                        out.print(listToPrefixedString(dadConfs, " conf=\""));
+                    }
                 }
                 printExtraAttributes(depArtifact, out, " ");
                 out.println("/>");
diff --git a/test/java/org/apache/ivy/core/resolve/ResolveTest.java b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
index 8d2fea3..abeae45 100644
--- a/test/java/org/apache/ivy/core/resolve/ResolveTest.java
+++ b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
@@ -6523,6 +6523,72 @@ public class ResolveTest {
 
     }
 
+
+    /**
+     * Tests the issue noted in IVY-1586.
+     * <pre>
+     *  org.apache:1586:1.0.0 depends on (Maven modules):
+     *      -> org.apache:1580-foo-api:1.2.3
+     *      -> org.apache:1580-foo-impl:1.2.3 conf="default", which in turn depends on:
+     *          -> org.apache:1580-foo-api:1.2.3 (in compile scope)
+     *          -> org.apache:1580-foo-api:1.2.3 (type = test-jar, in test scope)
+     * </pre>
+     * It's expected that the resolution of org.apache:1586:1.0.0, gets the
+     * "jar" type of org.apache:1580-foo-api and not the test-jar of the same org.apache:1580-foo-api,
+     * since only the "default" conf is demanded via the org.apache:1580-foo-impl:1.2.3 dependency.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/IVY-1586">IVY-1586</a>
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testIvy1586() throws Exception {
+        // do it twice (once in fresh cache and once with the cache populated)
+        for (int i = 0; i < 2; i++) {
+            if (i == 0) {
+                ivy.getLoggerEngine().info("ResolveTest#testIvy1586 - Using a clean Ivy cache");
+            } else {
+                ivy.getLoggerEngine().info("ResolveTest#testIvy1586 - Using an already populated Ivy cache");
+            }
+            final File ivyXML = new File("test/repositories/1/ivy-1586/ivy-1586.xml");
+            final ResolveReport resolveReport = ivy.resolve(ivyXML.toURI().toURL(),
+                    new ResolveOptions().setConfs(new String[]{"*"}));
+            assertFalse("Resolution report has failures", resolveReport.hasError());
+            final String rootModuleConf = "default";
+            // get the "default" conf, resolution report for the org.apache:1586:1.0.0 module (represented by the
+            // ivy-1586.xml module descriptor)
+            final ConfigurationResolveReport confReport = resolveReport.getConfigurationReport(rootModuleConf);
+            assertNotNull(rootModuleConf + " conf resolution report for " +
+                    resolveReport.getModuleDescriptor().getModuleRevisionId() + " is null", confReport);
+
+            final ModuleRevisionId apiDependencyId = ModuleRevisionId.newInstance("org.apache", "1580-foo-api", "1.2.3");
+            final IvyNode apiDepNode = confReport.getDependency(apiDependencyId);
+            assertNotNull("Dependency " + apiDependencyId + " not found in conf resolve report", apiDepNode);
+            final Artifact[] apiArtifacts = apiDepNode.getArtifacts(rootModuleConf);
+            assertNotNull("No artifacts available for dependency " + apiDependencyId, apiArtifacts);
+            assertEquals("Unexpected number of artifacts for dependency " + apiDependencyId, 1, apiArtifacts.length);
+            final Artifact apiArtifact = apiArtifacts[0];
+            assertEquals("Unexpected artifact name", "1580-foo-api", apiArtifact.getName());
+            assertEquals("Unexpected type for artifact", "jar", apiArtifact.getType());
+            ArtifactDownloadReport apiDownloadReport = null;
+            for (final ArtifactDownloadReport artifactDownloadReport : confReport.getAllArtifactsReports()) {
+                if (artifactDownloadReport.getArtifact().equals(apiArtifact)) {
+                    apiDownloadReport = artifactDownloadReport;
+                    break;
+                }
+            }
+            assertNotNull("No download report found for artifact " + apiArtifact, apiDownloadReport);
+            final File apiJar = apiDownloadReport.getLocalFile();
+            assertNotNull("artifact jar file is null for " + apiArtifact, apiJar);
+            assertJarContains(apiJar, "api-file.txt");
+
+            // just do some basic check on the impl module as well
+            final ModuleRevisionId implDepId = ModuleRevisionId.newInstance("org.apache", "1580-foo-impl", "1.2.3");
+            final IvyNode implDepNode = confReport.getDependency(implDepId);
+            assertNotNull("Dependency " + implDepId + " not found in conf resolve report", implDepNode);
+        }
+    }
+
     private void assertJarContains(final File jar, final String jarEntryPath) throws IOException {
         try (final JarFile jarFile = new JarFile(jar)) {
             final JarEntry entry = jarFile.getJarEntry(jarEntryPath);
diff --git a/test/repositories/1/ivy-1586/ivy-1586.xml b/test/repositories/1/ivy-1586/ivy-1586.xml
new file mode 100644
index 0000000..2045436
--- /dev/null
+++ b/test/repositories/1/ivy-1586/ivy-1586.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ 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.
+  -->
+<ivy-module version="2.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
+    <info organisation="org.apache" module="1586" revision="1.0.0"/>
+    <dependencies>
+        <!-- These modules are Maven based artifacts (available in test/repositories/m2/) -->
+        <dependency org="org.apache" name="1580-foo-api" rev="1.2.3" />
+        <dependency org="org.apache" name="1580-foo-impl" rev="1.2.3" conf="default"/>
+    </dependencies>
+</ivy-module>