IMPROVEMENT: ivy:makepom will generate an exclusion when transitive=false on a dependency (IVY-1470)

git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@1592628 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maarten Coene 2014-05-05 20:56:51 +00:00
parent 8d85139073
commit e484646c60
5 changed files with 102 additions and 5 deletions

View File

@ -144,6 +144,7 @@ for detailed view of each issue, please consult http://issues.apache.org/jira/br
=====================================
- IMPROVEMENT: Add support for packed jar within an OSGi bundle
- IMPROVEMENT: ModuleRules.getRule is O(n) leading to resolution slowness (IVY-1465) (Thanks to Zhong Wang aka Kewpie)
- IMPROVEMENT: ivy:makepom will generate an exclusion when transitive=false on a dependency (IVY-1470)
- FIX: impossible to get artifacts when data has not been loaded. (IVY-1399) (Thanks to David Turner)
- FIX: regression introduced by IVY-1457, dependency management wasn't properly handled introducing lots of resolution failures

View File

@ -228,7 +228,7 @@ public final class PomModuleDescriptorWriter {
version = md.getModuleRevisionId().getRevision();
}
printDependency(out, indent, groupId, dep.getArtifact(), version, dep.getType(),
dep.getClassifier(), dep.getScope(), dep.isOptional(), null);
dep.getClassifier(), dep.getScope(), dep.isOptional(), true, null);
}
// now print the dependencies listed in the ModuleDescriptor
@ -251,13 +251,15 @@ public final class PomModuleDescriptorWriter {
String scope = mapping.getScope(dds[i].getModuleConfigurations());
boolean optional = mapping.isOptional(dds[i].getModuleConfigurations());
printDependency(out, indent, mrid.getOrganisation(), mrid.getName(),
mrid.getRevision(), type, classifier, scope, optional, excludes);
mrid.getRevision(), type, classifier, scope, optional,
dds[i].isTransitive(), excludes);
}
} else {
String scope = mapping.getScope(dds[i].getModuleConfigurations());
boolean optional = mapping.isOptional(dds[i].getModuleConfigurations());
printDependency(out, indent, mrid.getOrganisation(), mrid.getName(),
mrid.getRevision(), null, null, scope, optional, excludes);
mrid.getRevision(), null, null, scope, optional, dds[i].isTransitive(),
excludes);
}
}
@ -270,7 +272,7 @@ public final class PomModuleDescriptorWriter {
private static void printDependency(PrintWriter out, int indent, String groupId,
String artifactId, String version, String type, String classifier, String scope,
boolean isOptional, ExcludeRule[] excludes) {
boolean isOptional, boolean isTransitive, ExcludeRule[] excludes) {
indent(out, indent * 2);
out.println("<dependency>");
indent(out, indent * 3);
@ -295,7 +297,20 @@ public final class PomModuleDescriptorWriter {
indent(out, indent * 3);
out.println("<optional>true</optional>");
}
if (excludes != null) {
if (!isTransitive) {
indent(out, indent * 3);
out.println("<exclusions>");
indent(out, indent * 4);
out.println("<exclusion>");
indent(out, indent * 5);
out.println("<groupId>*</groupId>");
indent(out, indent * 5);
out.println("<artifactId>*</artifactId>");
indent(out, indent * 4);
out.println("</exclusion>");
indent(out, indent * 3);
out.println("</exclusions>");
} else if (excludes != null) {
printExclusions(excludes, out, indent);
}
indent(out, indent * 2);

View File

@ -27,6 +27,7 @@ import junit.framework.TestCase;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry;
import org.apache.ivy.util.FileUtil;
public class PomModuleDescriptorWriterTest extends TestCase {
@ -121,6 +122,20 @@ public class PomModuleDescriptorWriterTest extends TestCase {
assertEquals(expected, wrote);
}
public void testTransitive() throws Exception {
ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(
new IvySettings(), getClass().getResource("test-transitive.xml"), false);
PomModuleDescriptorWriter.write(md, _dest, getWriterOptions());
assertTrue(_dest.exists());
String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest)))
.replaceAll("\r\n", "\n").replace('\r', '\n');
System.out.println(wrote);
String expected = readEntirely("test-transitive.pom").replaceAll("\r\n", "\n").replace(
'\r', '\n');
assertEquals(expected, wrote);
}
public void testPackaging() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(
new IvySettings(), getClass().getResource("test-packaging.pom"), false);

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>apache</groupId>
<artifactId>test-transitive</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>apache</groupId>
<artifactId>ivy</artifactId>
<version>1.0</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,24 @@
<!--
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="1.0">
<info organisation="apache" module="test-transitive" revision="1.0"/>
<dependencies>
<dependency org="apache" name="ivy" rev="1.0" transitive="false" />
</dependencies>
</ivy-module>