ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gin...@apache.org
Subject ant-ivy git commit: IVY-1420, take two: defaultconf is a mapping, too; add test cases for related issues IVY-1315 and IVY-1419
Date Sun, 08 Oct 2017 20:30:12 GMT
Repository: ant-ivy
Updated Branches:
  refs/heads/master 8054f746b -> 6b610aa41


IVY-1420, take two: defaultconf is a mapping, too;
add test cases for related issues IVY-1315 and IVY-1419

Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/6b610aa4
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/6b610aa4
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/6b610aa4

Branch: refs/heads/master
Commit: 6b610aa411df723b59d4b683baeebd5d65e356b7
Parents: 8054f74
Author: Gintas Grigelionis <gintas@apache.org>
Authored: Sun Oct 8 22:29:54 2017 +0200
Committer: Gintas Grigelionis <gintas@apache.org>
Committed: Sun Oct 8 22:29:54 2017 +0200

----------------------------------------------------------------------
 .../parser/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(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/6b610aa4/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
----------------------------------------------------------------------
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 44c5b52..60c33b5 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 final class XmlModuleDescriptorUpdater {
                 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 final class XmlModuleDescriptorUpdater {
                         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 @@ public final class XmlModuleDescriptorUpdater {
             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 @@ public final class XmlModuleDescriptorUpdater {
                     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 @@ public final class XmlModuleDescriptorUpdater {
                 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);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/6b610aa4/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java
----------------------------------------------------------------------
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 f20a459..b09ebb5 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 class XmlModuleUpdaterTest {
         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());

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/6b610aa4/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-default.xml
----------------------------------------------------------------------
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 0000000..fedfc43
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-default.xml
@@ -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>

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/6b610aa4/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs6.xml
----------------------------------------------------------------------
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 0000000..2bca955
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs6.xml
@@ -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>


Mime
View raw message