Browse Source

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
master
Peter Reilly 20 years ago
parent
commit
5cf848fdb5
2 changed files with 20 additions and 15 deletions
  1. +3
    -0
      WHATSNEW
  2. +17
    -15
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java

+ 3
- 0
WHATSNEW View File

@@ -178,6 +178,9 @@ Fixed bugs:
twice - if the resource is in the project classpath and if the classloader is requested twice - if the resource is in the project classpath and if the classloader is requested
with a null path. 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 Changes from Ant 1.6.1 to Ant 1.6.2
=================================== ===================================




+ 17
- 15
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -19,8 +19,6 @@ package org.apache.tools.ant.taskdefs.optional;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector; import java.util.Vector;


import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.AntClassLoader;
@@ -59,7 +57,7 @@ public class XMLValidateTask extends Task {
/** /**
* helper for path -> URI and URI -> path conversions. * 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 = protected static final String INIT_FAILED_MSG =
"Could not start xml validation: "; "Could not start xml validation: ";
@@ -455,7 +453,7 @@ public class XMLValidateTask extends Task {
log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE); log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE);
errorHandler.init(afile); errorHandler.init(afile);
InputSource is = new InputSource(new FileInputStream(afile)); InputSource is = new InputSource(new FileInputStream(afile));
String uri = fu.toURI(afile.getAbsolutePath());
String uri = FILE_UTILS.toURI(afile.getAbsolutePath());
is.setSystemId(uri); is.setSystemId(uri);
xmlReader.parse(is); xmlReader.parse(is);
} catch (SAXException ex) { } catch (SAXException ex) {
@@ -546,18 +544,22 @@ public class XMLValidateTask extends Task {
private String getMessage(SAXParseException e) { private String getMessage(SAXParseException e) {
String sysID = e.getSystemId(); String sysID = e.getSystemId();
if (sysID != null) { 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(); return e.getMessage();
} }


Loading…
Cancel
Save