bodewig 2003/01/17 06:34:56 Modified: src/main/org/apache/tools/ant/types XMLCatalog.java src/main/org/apache/tools/ant/util FileUtils.java LazyHashtable.java Log: Fix some JDK 1.1 issues - only culprit remaining is Diagnostics with its class locating code. Learned by failing <xmlvalidate> tests that FileUtils.getFileURL wouldn't append slashes where it should (because normalize strips them). Revision Changes Path 1.22 +9 -5 jakarta-ant/src/main/org/apache/tools/ant/types/XMLCatalog.java Index: XMLCatalog.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/XMLCatalog.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- XMLCatalog.java 13 Jan 2003 15:52:12 -0000 1.21 +++ XMLCatalog.java 17 Jan 2003 14:34:55 -0000 1.22 @@ -76,6 +76,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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.35 +10 -9 jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java Index: FileUtils.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- FileUtils.java 19 Dec 2002 11:20:29 -0000 1.34 +++ FileUtils.java 17 Jan 2003 14:34:55 -0000 1.35 @@ -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 @@ * 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 @@ 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 @@ * @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 @@ } path = path.replace('\\', '/'); + CharacterIterator iter = new StringCharacterIterator(path); for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { @@ -941,6 +939,9 @@ } else { sb.append(c); } + } + if (isDir && !path.endsWith("/")) { + sb.append('/'); } return sb.toString(); } 1.2 +2 -2 jakarta-ant/src/main/org/apache/tools/ant/util/LazyHashtable.java Index: LazyHashtable.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/LazyHashtable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LazyHashtable.java 6 Dec 2002 23:02:30 -0000 1.1 +++ LazyHashtable.java 17 Jan 2003 14:34:55 -0000 1.2 @@ -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 boolean containsValue( Object value ) { initAll(); - return super.containsValue( value ); + return super.contains( value ); } public Enumeration keys() {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>