mirror of https://github.com/apache/ant-ivy
Merge pull request #124 from eric-milles/IVY-1656
IVY-1656: write inherited dependencies first to preserve resolve order
This commit is contained in:
commit
05981d1a56
|
|
@ -292,12 +292,10 @@ public final class XmlModuleDescriptorUpdater {
|
|||
// according to ivy.xsd, all <dependency> elements must occur before
|
||||
// the <exclude>, <override> or <conflict> elements
|
||||
if (options.isMerge()
|
||||
&& ("exclude".equals(localName) || "override".equals(localName) || "conflict"
|
||||
.equals(localName)) && "ivy-module/dependencies".equals(getContext())) {
|
||||
&& !mergedDependencies
|
||||
&& "ivy-module/dependencies".equals(getContext())) {
|
||||
ModuleDescriptor merged = options.getMergedDescriptor();
|
||||
writeInheritedDependencies(merged);
|
||||
out.println();
|
||||
out.print(getIndent());
|
||||
}
|
||||
|
||||
context.push(qName);
|
||||
|
|
@ -991,7 +989,7 @@ public final class XmlModuleDescriptorUpdater {
|
|||
* just write the inherited items inline, with a comment indicating where they
|
||||
* came from.
|
||||
*/
|
||||
private void writeInheritedItems(ModuleDescriptor merged, InheritableItem[] items,
|
||||
private boolean writeInheritedItems(ModuleDescriptor merged, InheritableItem[] items,
|
||||
ItemPrinter printer, String itemName, boolean includeContainer) {
|
||||
// first categorize inherited items by their source module, so that
|
||||
// we can add some useful comments
|
||||
|
|
@ -1014,6 +1012,10 @@ public final class XmlModuleDescriptorUpdater {
|
|||
newMapping.isEmpty() ? "" : " defaultconfmapping=\"" + newMapping + "\"",
|
||||
(confMappingOverride != null) ? " confmappingoverride=\"" + confMappingOverride + "\"" : ""));
|
||||
context.push(itemName);
|
||||
if ("dependencies".equals(itemName)) {
|
||||
out.println();
|
||||
out.print(getIndent());
|
||||
}
|
||||
justOpen = null;
|
||||
}
|
||||
|
||||
|
|
@ -1039,13 +1041,17 @@ public final class XmlModuleDescriptorUpdater {
|
|||
// restore the prior indent
|
||||
out.print(currentIndent);
|
||||
}
|
||||
|
||||
return hasItems;
|
||||
}
|
||||
|
||||
private void writeInheritanceComment(String itemDescription, Object parentInfo) {
|
||||
PrintWriter out = getWriter();
|
||||
out.println();
|
||||
out.println(getIndent() + "<!-- " + itemDescription + " inherited from " + parentInfo
|
||||
+ " -->");
|
||||
if (!"dependencies".equals(itemDescription)) {
|
||||
out.println();
|
||||
out.print(getIndent());
|
||||
}
|
||||
out.println("<!-- " + itemDescription + " inherited from " + parentInfo + " -->");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1113,8 +1119,12 @@ public final class XmlModuleDescriptorUpdater {
|
|||
private void writeInheritedDependencies(ModuleDescriptor merged) {
|
||||
if (!mergedDependencies) {
|
||||
mergedDependencies = true;
|
||||
writeInheritedItems(merged, getDependencies(merged), DependencyPrinter.INSTANCE,
|
||||
"dependencies", false);
|
||||
InheritableItem[] items = getDependencies(merged);
|
||||
if (writeInheritedItems(merged, items, DependencyPrinter.INSTANCE, "dependencies", false)) {
|
||||
out.println("<!-- dependencies inherited end -->");
|
||||
out.println(); // separate from next section
|
||||
out.print(getIndent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1149,7 +1159,7 @@ public final class XmlModuleDescriptorUpdater {
|
|||
* a descriptor element name, for example "configurations" or "info"
|
||||
*/
|
||||
private void flushMergedElementsBefore(String moduleElement) {
|
||||
if (options.isMerge() && context.size() == 1 && "ivy-module".equals(context.peek())
|
||||
if (options.isMerge() && "ivy-module".equals(getContext())
|
||||
&& !(mergedConfigurations && mergedDependencies)) {
|
||||
|
||||
// calculate the position of the element in ivy-module
|
||||
|
|
@ -1184,7 +1194,6 @@ public final class XmlModuleDescriptorUpdater {
|
|||
}
|
||||
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
|
||||
String path = getContext();
|
||||
if (options.isMerge()) {
|
||||
ModuleDescriptor merged = options.getMergedDescriptor();
|
||||
|
|
@ -1198,10 +1207,6 @@ public final class XmlModuleDescriptorUpdater {
|
|||
// write inherited configurations after all child configurations
|
||||
writeInheritedConfigurations(merged);
|
||||
break;
|
||||
case "ivy-module/dependencies":
|
||||
// write inherited dependencies after all child dependencies
|
||||
writeInheritedDependencies(merged);
|
||||
break;
|
||||
case "ivy-module":
|
||||
// write any remaining inherited data before we close the
|
||||
// descriptor.
|
||||
|
|
@ -1284,6 +1289,13 @@ public final class XmlModuleDescriptorUpdater {
|
|||
justOpen = null;
|
||||
}
|
||||
|
||||
if (options.isMerge()
|
||||
&& !mergedDependencies
|
||||
&& "ivy-module/dependencies".equals(getContext())) {
|
||||
ModuleDescriptor merged = options.getMergedDescriptor();
|
||||
writeInheritedDependencies(merged);
|
||||
}
|
||||
|
||||
write("<!--");
|
||||
write(String.valueOf(ch, start, length));
|
||||
write("-->");
|
||||
|
|
|
|||
|
|
@ -118,8 +118,9 @@ public class IvyDeliverTest {
|
|||
res.setProject(project);
|
||||
res.execute();
|
||||
|
||||
deliver.setPubrevision("1.2");
|
||||
deliver.setDeliverpattern("build/test/deliver/merge/ivy-[revision].xml");
|
||||
deliver.setPubrevision("1.2");
|
||||
deliver.setStatus("release");
|
||||
deliver.execute();
|
||||
|
||||
// should have delivered the file to the specified destination
|
||||
|
|
@ -138,10 +139,10 @@ public class IvyDeliverTest {
|
|||
mergeLine = mergeLine.trim();
|
||||
expectedLine = expectedLine.trim();
|
||||
|
||||
if (!mergeLine.startsWith("<info")) {
|
||||
assertEquals("published descriptor matches at line[" + lineNo + "]",
|
||||
expectedLine.trim(), mergeLine.trim());
|
||||
if (mergeLine.startsWith("<info")) {
|
||||
mergeLine = mergeLine.replaceFirst(" publication=\"\\d+\"", "");
|
||||
}
|
||||
assertEquals("published descriptor matches at line[" + lineNo + "]", expectedLine.trim(), mergeLine.trim());
|
||||
|
||||
++lineNo;
|
||||
mergeLine = merged.readLine();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
<info organisation="apache" module="resolve-extends" revision="1.2" status="release">
|
||||
<!-- <extends organisation="apache" module="resolve-simple" revision="1.0" location="./ivy-multiconf.xml"/> -->
|
||||
|
||||
|
||||
<!-- description inherited from parent -->
|
||||
<description>Demonstrates configuration-specific dependencies</description>
|
||||
</info>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
<conf name="extra"/>
|
||||
<!-- overrides conf in parent -->
|
||||
<conf name="default" extends="compile" description="overrides the conf definition in parent descriptor"/>
|
||||
|
||||
|
||||
<!-- configurations inherited from apache#resolve-simple;1.0 -->
|
||||
<conf name="compile" visibility="public"/>
|
||||
</configurations>
|
||||
|
|
@ -39,14 +39,15 @@
|
|||
<publications/>
|
||||
|
||||
<dependencies>
|
||||
<!-- dependencies inherited from apache#resolve-simple;1.0 -->
|
||||
<dependency org="org1" name="mod1.2" rev="2.0" conf="default->default"/>
|
||||
<dependency org="org1" name="mod1.1" rev="2.0" transitive="false" conf="compile->default"/>
|
||||
<!-- dependencies inherited end -->
|
||||
|
||||
<!-- not in parent -->
|
||||
<dependency org="org2" name="mod2.1" rev="0.3" conf="default->compile(default)"/>
|
||||
<!-- overrides parent -->
|
||||
<dependency org="org1" name="mod1.1" rev="1.1" conf="default,compile->default" transitive="false"/>
|
||||
|
||||
<!-- dependencies inherited from apache#resolve-simple;1.0 -->
|
||||
<dependency org="org1" name="mod1.2" rev="2.0" conf="default->default"/>
|
||||
<dependency org="org1" name="mod1.1" rev="2.0" transitive="false" conf="compile->default"/>
|
||||
</dependencies>
|
||||
|
||||
</ivy-module>
|
||||
</ivy-module>
|
||||
|
|
|
|||
Loading…
Reference in New Issue