its class locating code. Learned by failing <xmlvalidate> tests that FileUtils.getFileURL wouldn't append slashes where it should (because normalize strips them). git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273824 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -76,6 +76,7 @@ import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.ant.util.JAXPUtils; | |||
| import org.xml.sax.EntityResolver; | |||
| import org.xml.sax.InputSource; | |||
| @@ -162,6 +163,9 @@ import org.xml.sax.XMLReader; | |||
| public class XMLCatalog extends DataType | |||
| implements Cloneable, EntityResolver, URIResolver { | |||
| /** helper for some File.toURL connversions */ | |||
| private static FileUtils fileUtils = FileUtils.newFileUtils(); | |||
| //-- Fields ---------------------------------------------------------------- | |||
| /** Holds dtd/entity objects until needed. */ | |||
| @@ -477,7 +481,7 @@ public class XMLCatalog extends DataType | |||
| URL baseURL = null; | |||
| try { | |||
| if (base == null) { | |||
| baseURL = getProject().getBaseDir().toURL(); | |||
| baseURL = fileUtils.getFileURL(getProject().getBaseDir()); | |||
| } | |||
| else { | |||
| baseURL = new URL(base); | |||
| @@ -646,7 +650,7 @@ public class XMLCatalog extends DataType | |||
| baseURL = matchingEntry.getBase(); | |||
| } else { | |||
| try { | |||
| baseURL = getProject().getBaseDir().toURL(); | |||
| baseURL = fileUtils.getFileURL(getProject().getBaseDir()); | |||
| } | |||
| catch (MalformedURLException ex) { | |||
| throw new BuildException("Project basedir cannot be converted to a URL"); | |||
| @@ -666,7 +670,7 @@ public class XMLCatalog extends DataType | |||
| if (url != null) { | |||
| String fileName = url.getFile(); | |||
| if (fileName != null) { | |||
| log("fileName"+fileName, Project.MSG_DEBUG); | |||
| log("fileName " + fileName, Project.MSG_DEBUG); | |||
| File resFile = new File(fileName); | |||
| if (resFile.exists() && resFile.canRead()) { | |||
| try { | |||
| @@ -743,7 +747,7 @@ public class XMLCatalog extends DataType | |||
| baseURL = matchingEntry.getBase(); | |||
| } else { | |||
| try { | |||
| baseURL = getProject().getBaseDir().toURL(); | |||
| baseURL = fileUtils.getFileURL(getProject().getBaseDir()); | |||
| } | |||
| catch (MalformedURLException ex) { | |||
| throw new BuildException("Project basedir cannot be converted to a URL"); | |||
| @@ -1,7 +1,7 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001-2002 The Apache Software Foundation. All rights | |||
| * Copyright (c) 2001-2003 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| @@ -154,11 +154,7 @@ public class FileUtils { | |||
| * formed. | |||
| */ | |||
| public URL getFileURL(File file) throws MalformedURLException { | |||
| String path = file.getAbsolutePath(); | |||
| if (file.isDirectory()) { | |||
| path += "/"; | |||
| } | |||
| return new URL(toURI(path)); | |||
| return new URL(toURI(file.getAbsolutePath())); | |||
| } | |||
| /** | |||
| @@ -706,8 +702,7 @@ public class FileUtils { | |||
| synchronized (rand) { | |||
| do { | |||
| result = new File(parent, | |||
| prefix | |||
| + fmt.format(rand.nextInt(Integer.MAX_VALUE)) | |||
| prefix + fmt.format(Math.abs(rand.nextInt())) | |||
| + suffix); | |||
| } while (result.exists()); | |||
| } | |||
| @@ -915,6 +910,8 @@ public class FileUtils { | |||
| * @since Ant 1.6 | |||
| */ | |||
| public String toURI(String path) { | |||
| boolean isDir = (new File(path)).isDirectory(); | |||
| StringBuffer sb = new StringBuffer("file:"); | |||
| // catch exception if normalize thinks this is not an absolute path | |||
| @@ -931,6 +928,7 @@ public class FileUtils { | |||
| } | |||
| path = path.replace('\\', '/'); | |||
| CharacterIterator iter = new StringCharacterIterator(path); | |||
| for (char c = iter.first(); c != CharacterIterator.DONE; | |||
| c = iter.next()) { | |||
| @@ -942,6 +940,9 @@ public class FileUtils { | |||
| sb.append(c); | |||
| } | |||
| } | |||
| if (isDir && !path.endsWith("/")) { | |||
| sb.append('/'); | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||
| * Copyright (c) 2000-2003 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| @@ -101,7 +101,7 @@ public class LazyHashtable extends Hashtable { | |||
| public boolean containsValue( Object value ) { | |||
| initAll(); | |||
| return super.containsValue( value ); | |||
| return super.contains( value ); | |||
| } | |||
| public Enumeration keys() { | |||