From 5cf848fdb5a0402838c570e91dacdcca3536fdbc Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Mon, 13 Dec 2004 18:51:55 +0000 Subject: [PATCH] URL#getFile does not output a nice filename for files with spaces, and absolute windows filenames. So use the FileUtils#fromURI() instead. PR: 32508 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277189 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ .../taskdefs/optional/XMLValidateTask.java | 32 ++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 813f74fad..9d5c41ded 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -178,6 +178,9 @@ Fixed bugs: twice - if the resource is in the project classpath and if the classloader is requested with a null path. +* XMLValidate used URL#getFile rather than the ant method FileUtils#fromURI + Bugzilla report 32508 + Changes from Ant 1.6.1 to Ant 1.6.2 =================================== diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java index a84b4b205..ced5af8c8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java @@ -19,8 +19,6 @@ package org.apache.tools.ant.taskdefs.optional; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import java.util.Vector; import org.apache.tools.ant.AntClassLoader; @@ -59,7 +57,7 @@ public class XMLValidateTask extends Task { /** * helper for path -> URI and URI -> path conversions. */ - private static FileUtils fu = FileUtils.newFileUtils(); + private static final FileUtils FILE_UTILS = FileUtils.newFileUtils(); protected static final String INIT_FAILED_MSG = "Could not start xml validation: "; @@ -455,7 +453,7 @@ public class XMLValidateTask extends Task { log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE); errorHandler.init(afile); InputSource is = new InputSource(new FileInputStream(afile)); - String uri = fu.toURI(afile.getAbsolutePath()); + String uri = FILE_UTILS.toURI(afile.getAbsolutePath()); is.setSystemId(uri); xmlReader.parse(is); } catch (SAXException ex) { @@ -546,18 +544,22 @@ public class XMLValidateTask extends Task { private String getMessage(SAXParseException e) { String sysID = e.getSystemId(); if (sysID != null) { - try { - int line = e.getLineNumber(); - int col = e.getColumnNumber(); - return new URL(sysID).getFile() - + (line == -1 - ? "" - : (":" + line + (col == -1 ? "" : (":" + col)))) - + ": " - + e.getMessage(); - } catch (MalformedURLException mfue) { - // ignore and just return exception message + String name = sysID; + if (sysID.startsWith("file:")) { + try { + name = FILE_UTILS.fromURI(sysID); + } catch (Exception ex) { + // if this is not a valid file: just use the uri + } } + int line = e.getLineNumber(); + int col = e.getColumnNumber(); + return name + + (line == -1 + ? "" + : (":" + line + (col == -1 ? "" : (":" + col)))) + + ": " + + e.getMessage(); } return e.getMessage(); }