mirror of https://github.com/apache/ant-ivy
IVY-1586 Set the correct "conf" on the "artifact" of the dependency when parsing a pom.xml
This commit is contained in:
parent
46752f7475
commit
3fc534020f
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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("/>");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
Loading…
Reference in New Issue