Author: maartenc
Date: Wed Dec 22 22:18:32 2010
New Revision: 1052083
URL: http://svn.apache.org/viewvc?rev=1052083&view=rev
Log:
FIX: ivy.xml that contains UTF-8 encoded umlauts cannot be bigger than 10000
bytes (IVY-1253) (2nd attempt)
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-merged.xml
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-minimal-merged.xml
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/published-ivy-custom.xml
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java?rev=1052083&r1=1052082&r2=1052083&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
Wed Dec 22 22:18:32 2010
@@ -17,12 +17,11 @@
*/
package org.apache.ivy.plugins.parser.xml;
-import java.io.BufferedReader;
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
@@ -1156,6 +1155,15 @@ public final class XmlModuleDescriptorUp
out.flush();
out.close();
}
+
+ public void processingInstruction(String target, String data) throws
SAXException {
+ write("<?");
+ write(target);
+ write(" ");
+ write(data);
+ write("?>");
+ write(LINE_SEPARATOR);
+ }
public void warning(SAXParseException e) throws SAXException {
throw e;
@@ -1183,12 +1191,15 @@ public final class XmlModuleDescriptorUp
write(">");
justOpen = null;
}
- if (!inHeader) {
- StringBuffer comment = new StringBuffer();
- comment.append(ch, start, length);
- write("<!--");
- write(comment.toString());
- write("-->");
+
+ StringBuffer comment = new StringBuffer();
+ comment.append(ch, start, length);
+ write("<!--");
+ write(comment.toString());
+ write("-->");
+
+ if (inHeader) {
+ write(LINE_SEPARATOR);
}
}
@@ -1207,15 +1218,12 @@ public final class XmlModuleDescriptorUp
OutputStream outStream, final UpdateOptions options)
throws IOException, SAXException {
final PrintWriter out = new PrintWriter(new
OutputStreamWriter(outStream, "UTF-8"));
- final BufferedReader in = new BufferedReader(new
InputStreamReader(inStream));
-
- in.mark(MAX_HEADER_LENGTH); // assume the header is never larger than
10000 characters.
- copyHeader(in, out);
- in.reset(); // reposition the stream at the beginning
-
+ out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ out.write(LINE_SEPARATOR);
+
try {
UpdaterHandler updaterHandler = new UpdaterHandler(inStreamCtx,
out, options);
- InputSource inSrc = new InputSource(in);
+ InputSource inSrc = new InputSource(new
BufferedInputStream(inStream));
if (inStreamCtx != null) {
inSrc.setSystemId(inStreamCtx.toExternalForm());
}
@@ -1228,31 +1236,6 @@ public final class XmlModuleDescriptorUp
}
}
- /**
- * Copy xml header from src url ivy file to given printwriter In fact,
copies everything before
- * <ivy-module to out, except if <ivy-module is not found, in which case
nothing is copied. The
- * prolog <?xml version="..." encoding="...."?> is also replaced by <?xml
version="1.0"
- * encoding="UTF-8"?> if it was present.
- */
- private static void copyHeader(BufferedReader r, PrintWriter out) throws
IOException {
- String line = r.readLine();
- if (line != null && line.startsWith("<?xml ")) {
- out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- line = line.substring(line.indexOf(">") + 1, line.length());
- }
- for (; line != null; line = r.readLine()) {
- int index = line.indexOf("<ivy-module");
- if (index == -1) {
- out.write(line);
- out.write(LINE_SEPARATOR);
- } else {
- out.write(line.substring(0, index));
- break;
- }
- }
- // r.close();
- }
-
private static class ExtendedBuffer {
private String context = null;
Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-merged.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-merged.xml?rev=1052083&r1=1052082&r2=1052083&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-merged.xml
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-merged.xml Wed
Dec 22 22:18:32 2010
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-minimal-merged.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-minimal-merged.xml?rev=1052083&r1=1052082&r2=1052083&view=diff
==============================================================================
---
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-minimal-merged.xml
(original)
+++
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivy-extends-minimal-merged.xml
Wed Dec 22 22:18:32 2010
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/published-ivy-custom.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/published-ivy-custom.xml?rev=1052083&r1=1052082&r2=1052083&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/published-ivy-custom.xml
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/published-ivy-custom.xml
Wed Dec 22 22:18:32 2010
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file