ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional XMLValidateTask.java
Date Mon, 13 Dec 2004 18:51:55 GMT
peterreilly    2004/12/13 10:51:55

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional
                        XMLValidateTask.java
  Log:
  URL#getFile does not output a nice filename
  for files with spaces, and absolute windows filenames.
  So use the FileUtils#fromURI() instead.
  PR: 32508
  
  Revision  Changes    Path
  1.694     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.693
  retrieving revision 1.694
  diff -u -r1.693 -r1.694
  --- WHATSNEW	10 Dec 2004 15:18:57 -0000	1.693
  +++ WHATSNEW	13 Dec 2004 18:51:55 -0000	1.694
  @@ -178,6 +178,9 @@
     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
   ===================================
   
  
  
  
  1.45      +17 -15    ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  
  Index: XMLValidateTask.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- XMLValidateTask.java	1 Dec 2004 22:49:02 -0000	1.44
  +++ XMLValidateTask.java	13 Dec 2004 18:51:55 -0000	1.45
  @@ -19,8 +19,6 @@
   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 @@
       /**
        * 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 @@
               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 @@
           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();
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message