Skip to content

Commit

Permalink
IVY-1420, take two: defaultconf is a mapping, too;
Browse files Browse the repository at this point in the history
add test cases for related issues IVY-1315 and IVY-1419
  • Loading branch information
Gintas Grigelionis committed Oct 8, 2017
1 parent 8054f74 commit 6b610aa
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,18 @@ public void startElement(String uri, String localName, String qName, Attributes
confAttributeBuffers.push(buffer);
write("<" + qName);
buffer.setDefaultPrint(attributes.getValue("conf") == null
&& ((newDefaultConf == null) || (newDefaultConf.length() > 0)));
&& (newDefaultConf == null || newDefaultConf.length() > 0));
for (int i = 0; i < attributes.getLength(); i++) {
String attName = attributes.getQName(i);
if ("conf".equals(attName)) {
String confName = substitute(settings, attributes.getValue("conf"));
String newConf = removeConfigurationsFromList(confName, confs);
if (newConf.length() > 0) {
write(" " + attributes.getQName(i) + "=\"" + newConf + "\"");
write(" " + attName + "=\"" + newConf + "\"");
buffers.peek().setPrint(true);
}
} else {
write(" " + attributes.getQName(i) + "=\""
write(" " + attName + "=\""
+ substitute(settings, attributes.getValue(i)) + "\"");
}
}
Expand All @@ -379,11 +379,11 @@ public void startElement(String uri, String localName, String qName, Attributes
String confName = substitute(settings, attributes.getValue("conf"));
String newConf = removeConfigurationsFromList(confName, confs);
if (newConf.length() > 0) {
write(" " + attributes.getQName(i) + "=\"" + newConf + "\"");
write(" " + attName + "=\"" + newConf + "\"");
buffers.peek().setPrint(true);
}
} else {
write(" " + attributes.getQName(i) + "=\""
write(" " + attName + "=\""
+ substitute(settings, attributes.getValue(i)) + "\"");
}
}
Expand Down Expand Up @@ -486,21 +486,23 @@ private void startElementWithConfAttributes(String qName, Attributes attributes)
write("<" + qName);
for (int i = 0; i < attributes.getLength(); i++) {
String attName = attributes.getQName(i);
if ("defaultconfmapping".equals(attName)) {
if ("defaultconf".equals(attName) || "defaultconfmapping".equals(attName)) {
String newMapping = removeConfigurationsFromMapping(
substitute(settings, attributes.getValue("defaultconfmapping")), confs);
substitute(settings, attributes.getValue(attName)), confs);
if (newMapping.length() > 0) {
write(" " + attributes.getQName(i) + "=\"" + newMapping + "\"");
write(" " + attName + "=\"" + newMapping + "\"");
}
} else {
write(" " + attributes.getQName(i) + "=\""
write(" " + attName + "=\""
+ substitute(settings, attributes.getValue(i)) + "\"");
}
}
// add default conf if needed
if (defaultConf != null && attributes.getValue("defaultconf") == null
&& !confs.contains(defaultConf)) {
write(" defaultconf=\"" + defaultConf + "\"");
if (defaultConf != null && attributes.getValue("defaultconf") == null) {
String newConf = removeConfigurationsFromMapping(defaultConf, confs);
if (newConf.length() > 0) {
write(" defaultconf=\"" + newConf + "\"");
}
}
// add default conf mapping if needed
if (defaultConfMapping != null && attributes.getValue("defaultconfmapping") == null) {
Expand All @@ -523,10 +525,10 @@ private void startPublications(Attributes attributes) {
newDefaultConf = removeConfigurationsFromList(
substitute(settings, attributes.getValue("defaultconf")), confs);
if (newDefaultConf.length() > 0) {
write(" " + attributes.getQName(i) + "=\"" + newDefaultConf + "\"");
write(" " + attName + "=\"" + newDefaultConf + "\"");
}
} else {
write(" " + attributes.getQName(i) + "=\""
write(" " + attName + "=\""
+ substitute(settings, attributes.getValue(i)) + "\"");
}
}
Expand Down Expand Up @@ -983,10 +985,12 @@ private void writeInheritedItems(ModuleDescriptor merged, InheritableItem[] item
if (currentIndent.length() == 0) {
out.print(getIndent());
}
String newConf = (defaultConf == null) ? "" :
removeConfigurationsFromMapping(defaultConf, confs);
String newMapping = (defaultConfMapping == null) ? "" :
removeConfigurationsFromMapping(defaultConfMapping, confs);
out.print(String.format("<%s%s%s%s>", itemName,
(defaultConf != null && !confs.contains(defaultConf)) ? " defaultconf=\"" + defaultConf + "\"" : "",
(newConf.length() > 0) ? " defaultconf=\"" + newConf + "\"" : "",
(newMapping.length() > 0) ? " defaultconfmapping=\"" + newMapping + "\"" : "",
(confMappingOverride != null) ? " confmappingoverride=\"" + confMappingOverride + "\"" : ""));
context.push(itemName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,71 @@ public void testMergedUpdateWithExtendsAndConfigurationsInheritance() throws Exc
assertTrue(updatedXml.contains("dependencies defaultconf=\"compile\" defaultconfmapping=\"*->default\""));
}

/**
* Test case for IVY-1315.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1315">IVY-1315</a>
*/
@Test
public void testMergedUpdateWithInclude() throws Exception {
URL url = XmlModuleUpdaterTest.class.getResource("test-update-excludedconfs6.xml");

XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);

ByteArrayOutputStream buffer = new ByteArrayOutputStream();
XmlModuleDescriptorUpdater.update(url, buffer,
getUpdateOptions("release", "mynewrev")
.setMerge(true)
.setMergedDescriptor(md));

ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(),
new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0,
false), true);

Configuration[] configurations = updatedMd.getConfigurations();
assertNotNull("Configurations shouldn't be null", configurations);
assertEquals("Number of configurations is incorrect", 6, configurations.length);

String updatedXml = buffer.toString();
System.out.println(updatedXml);
assertTrue(updatedXml.contains("dependencies defaultconf=\"conf1->default\""));
}

/**
* Test case for IVY-1419.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1419">IVY-1419</a>
*/
@Test
public void testMergedUpdateWithIncludeAndExcludedConf() throws Exception {
URL url = XmlModuleUpdaterTest.class.getResource("test-update-excludedconfs6.xml");

XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);

ByteArrayOutputStream buffer = new ByteArrayOutputStream();
XmlModuleDescriptorUpdater.update(url, buffer,
getUpdateOptions("release", "mynewrev")
.setMerge(true)
.setMergedDescriptor(md)
.setConfsToExclude(new String[]{"conf1"}));

ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(),
new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0,
false), true);

Configuration[] configurations = updatedMd.getConfigurations();
assertNotNull("Configurations shouldn't be null", configurations);
assertEquals("Number of configurations is incorrect", 5, configurations.length);

String updatedXml = buffer.toString();
System.out.println(updatedXml);
assertTrue(updatedXml.contains("dependencies/"));
}

private UpdateOptions getUpdateOptions(String status, String revision) {
return getUpdateOptions(new IvySettings(), new HashMap<ModuleRevisionId, String>(), status,
revision, new Date());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
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.
-->
<configurations defaultconf="conf1->default">
<conf name="conf1" visibility="public"/>
<conf name="conf2" visibility="private"/>
</configurations>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="http://www.somesite.com/ivy-doc.xsl"?>
<!--
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="myorg"
module="mymodule"
revision="myrev"
status="integration"
publication="20041101110000"/>
<configurations>
<include file="imported-configurations-with-default.xml"/>
<conf name="myconf1" description="desc 1"/>
<conf name="myconf2" description="desc 2"/>
<conf name="myconf3" description="desc 3" visibility="private"/>
<conf name="myconf4" description="desc 4"/>
</configurations>
<publications/>
<dependencies/>
</ivy-module>

0 comments on commit 6b610aa

Please sign in to comment.