From aaa2583f35f67f2a2c8d3381cad144cc7ba39f3e Mon Sep 17 00:00:00 2001 From: Maarten Coene Date: Mon, 1 Sep 2008 21:52:35 +0000 Subject: [PATCH] FIX: Ivy Publish Task Fails When XML Comments Exist Next to Dependency Declarations (IVY-888) git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@691071 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../xml/XmlModuleDescriptorUpdater.java | 4 ++ .../parser/xml/XmlModuleUpdaterTest.java | 18 +++++++++ .../plugins/parser/xml/test-with-comments.xml | 38 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 test/java/org/apache/ivy/plugins/parser/xml/test-with-comments.xml diff --git a/CHANGES.txt b/CHANGES.txt index aaa8c780..8e811215 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -108,6 +108,7 @@ for detailed view of each issue, please consult http://issues.apache.org/jira/br - IMPROVEMENT: Add a memory cache for the module descriptor that are parsed from the cache (IVY-883) - IMPROVEMENT: Improve performance (IVY-872) +- FIX: Ivy Publish Task Fails When XML Comments Exist Next to Dependency Declarations (IVY-888) - FIX: Incorrect directory path resolve when running from a different directory (IVY-232) - FIX: Ivy#listTokenValues(String, Map) does not filter returned values, and does not use maven-metadata.xml files with IBiblio resolver (IVY-886) - FIX: Circular Dependency messages in a resolve do not reflect the configuration used during the resolve (IVY-708) 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 26673362..33d2be77 100644 --- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java +++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java @@ -704,6 +704,10 @@ public final class XmlModuleDescriptorUpdater { } public void comment(char[] ch, int start, int length) throws SAXException { + if (justOpen != null) { + write(">"); + justOpen = null; + } if (!inHeader) { StringBuffer comment = new StringBuffer(); comment.append(ch, start, length); 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 e9a4c8f9..26fd88af 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java +++ b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java @@ -17,6 +17,7 @@ */ package org.apache.ivy.plugins.parser.xml; +import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -78,6 +79,23 @@ public class XmlModuleUpdaterTest extends TestCase { assertEquals(expected, updated); } + public void testUpdateWithComments() throws Exception { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + + "test-with-comments.xml").toURL(); + XmlModuleDescriptorUpdater.update(settingsUrl, new BufferedOutputStream(buffer, 1024), + getUpdateOptions("release", "mynewrev")); + + XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); + ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), + new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, + false), true); + + DependencyDescriptor[] dependencies = updatedMd.getDependencies(); + assertNotNull(dependencies); + assertEquals(3, dependencies.length); + } + public void testVariableReplacement() throws Exception { /* * For updated file to be equals to updated.xml, we have to fix the line separator to the diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-with-comments.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-with-comments.xml new file mode 100644 index 00000000..8727d0ac --- /dev/null +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-with-comments.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + +