From 6b610aa411df723b59d4b683baeebd5d65e356b7 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Sun, 8 Oct 2017 22:29:54 +0200 Subject: [PATCH] IVY-1420, take two: defaultconf is a mapping, too; add test cases for related issues IVY-1315 and IVY-1419 --- .../xml/XmlModuleDescriptorUpdater.java | 34 +++++----- .../parser/xml/XmlModuleUpdaterTest.java | 65 +++++++++++++++++++ .../imported-configurations-with-default.xml | 22 +++++++ .../parser/xml/test-update-excludedconfs6.xml | 36 ++++++++++ 4 files changed, 142 insertions(+), 15 deletions(-) create mode 100644 test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-default.xml create mode 100644 test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs6.xml diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java index 44c5b52e5..60c33b5d7 100644 --- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java +++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java @@ -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)) + "\""); } } @@ -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)) + "\""); } } @@ -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) { @@ -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)) + "\""); } } @@ -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); diff --git a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java index f20a4598a..b09ebb5c0 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java +++ b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java @@ -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 IVY-1315 + */ + @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 IVY-1419 + */ + @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(), status, revision, new Date()); diff --git a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-default.xml b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-default.xml new file mode 100644 index 000000000..fedfc4368 --- /dev/null +++ b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-default.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs6.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs6.xml new file mode 100644 index 000000000..2bca955eb --- /dev/null +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs6.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + +