ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r1402344 - in /ant/ivy/core/branches/2.3.x: ./ CHANGES.txt src/java/org/apache/ivy/plugins/parser/m2/PomReader.java src/java/org/apache/ivy/util/XMLHelper.java
Date Thu, 25 Oct 2012 21:56:18 GMT
Author: maartenc
Date: Thu Oct 25 21:56:17 2012
New Revision: 1402344

URL: http://svn.apache.org/viewvc?rev=1402344&view=rev
Log:
FIX: Ivy default cache path with non-ASCII character lets it crash (IVY-1378) (merged from
trunk)

Modified:
    ant/ivy/core/branches/2.3.x/   (props changed)
    ant/ivy/core/branches/2.3.x/CHANGES.txt
    ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
    ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/util/XMLHelper.java

Propchange: ant/ivy/core/branches/2.3.x/
------------------------------------------------------------------------------
  Merged /ant/ivy/core/trunk:r1401854,1402340

Modified: ant/ivy/core/branches/2.3.x/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/CHANGES.txt?rev=1402344&r1=1402343&r2=1402344&view=diff
==============================================================================
--- ant/ivy/core/branches/2.3.x/CHANGES.txt (original)
+++ ant/ivy/core/branches/2.3.x/CHANGES.txt Thu Oct 25 21:56:17 2012
@@ -133,6 +133,7 @@ for detailed view of each issue, please 
 - DOCUMENTATION: Documentation and Implementation mismatch of makepom (IVY-1383) (thanks
to Thomas Kurpick)
 - DOCUMENTATION: added link to extra beginners guide (IVY-1381)
 
+- FIX: Ivy default cache path with non-ASCII character lets it crash (IVY-1378)
 - FIX: latest.integration isn't resolved against a Maven snapshot repository (when uniqueVersion
= true) (IVY-1036)
 - FIX: Resolve does not deliver all dependent artifacts (IVY-1366) (thanks to Wolfgang Frank)
 - FIX: Ivy descriptors are merged incorrectly when there is an <exclude> element (IVY-1356)

Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java?rev=1402344&r1=1402343&r2=1402344&view=diff
==============================================================================
--- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java (original)
+++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java Thu
Oct 25 21:56:17 2012
@@ -48,8 +48,6 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
-
-
 /**
  * Provides the method to read some data out of the DOM tree of a pom 
  * file.
@@ -91,8 +89,10 @@ public class PomReader {
     
     public PomReader(URL descriptorURL, Resource res) throws IOException, SAXException {
         InputStream stream = new AddDTDFilterInputStream(URLHandlerRegistry.getDefault().openStream(descriptorURL));
+        InputSource source = new InputSource(stream);
+        source.setSystemId(XMLHelper.toSystemId(descriptorURL));
         try {
-            Document pomDomDoc = XMLHelper.parseToDom(stream, res, new EntityResolver() {
+            Document pomDomDoc = XMLHelper.parseToDom(source, new EntityResolver() {
                 public InputSource resolveEntity(String publicId, String systemId) 
                                 throws SAXException, IOException {
                     if ((systemId != null) && systemId.endsWith("m2-entities.ent"))
{
@@ -109,12 +109,10 @@ public class PomReader {
             }
             parentElement = getFirstChildElement(projectElement , PARENT);
         } finally {
-            if (stream != null) {
-                try {
-                    stream.close();
-                } catch (IOException e) {
-                    // ignore
-                }
+            try {
+                stream.close();
+            } catch (IOException e) {
+                // ignore
             }
         }
     }

Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/util/XMLHelper.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/util/XMLHelper.java?rev=1402344&r1=1402343&r2=1402344&view=diff
==============================================================================
--- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/util/XMLHelper.java (original)
+++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/util/XMLHelper.java Thu Oct 25 21:56:17
2012
@@ -19,6 +19,8 @@ package org.apache.ivy.util;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -77,6 +79,17 @@ public abstract class XMLHelper {
         return parser;
     }
 
+    /**
+     * Convert an URL to a valid systemId according to RFC 2396.
+     */
+    public static String toSystemId(URL url) {
+        try {
+            return new URI(url.toExternalForm()).toASCIIString();
+        } catch (URISyntaxException e) {
+            return url.toExternalForm();
+        }
+    }
+
     // IMPORTANT: validation errors are only notified to the given handler, and
     // do not cause exception
     // implement warning error and fatalError methods in handler to be informed
@@ -92,7 +105,7 @@ public abstract class XMLHelper {
         InputStream xmlStream = URLHandlerRegistry.getDefault().openStream(xmlURL);
         try {
             InputSource inSrc = new InputSource(xmlStream);
-            inSrc.setSystemId(xmlURL.toExternalForm());
+            inSrc.setSystemId(toSystemId(xmlURL));
             parse(inSrc, schema, handler, lHandler);
         } finally {
             try {
@@ -189,20 +202,10 @@ public abstract class XMLHelper {
     }
 
     
-    public static Document parseToDom(
-            InputStream stream, Resource res, EntityResolver entityResolver) 
-                throws IOException, SAXException {
+    public static Document parseToDom(InputSource source, EntityResolver entityResolver)
+            throws IOException, SAXException {
         DocumentBuilder docBuilder = getDocBuilder(entityResolver);
-        Document pomDomDoc;
-        try {
-            pomDomDoc = docBuilder.parse(stream, res.getName());
-        } catch (SAXException e) {
-            e.printStackTrace();
-            throw e;
-        } finally {
-            stream.close();
-        } 
-        return pomDomDoc;
+        return docBuilder.parse(source);
     }
 
     public static DocumentBuilder getDocBuilder(EntityResolver entityResolver) {



Mime
View raw message