From fb2b9616dc8be39d80b58a0fbdfff5ceecd18d1f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 10 Dec 2002 16:38:26 +0000 Subject: [PATCH] Rumors say that absolute file: URLs on Windows need a third slash. Get rid of some code duplication. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273645 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++++ .../org/apache/tools/ant/util/FileUtils.java | 10 ++++++++++ .../org/apache/tools/ant/util/JAXPUtils.java | 16 +++++----------- .../org/apache/tools/ant/util/FileUtilsTest.java | 8 ++++---- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 6badfc7ca..1618700b7 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -65,6 +65,10 @@ Fixed bugs: * the errorsbeginat attribute of the condition didn't work. +* Ant will try to force loading of certain packages like com.sun.* + from the system classloader. The packages are determined by the + version of the JVM running Ant. + Other changes: -------------- * The filesetmanifest attribute of has been reenabled. diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 0331c03f6..4c0141bee 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -920,6 +920,11 @@ public class FileUtils { try { path = normalize(path).getAbsolutePath(); sb.append("//"); + // add an extra slash for filesystems with drive-specifiers + if (!path.startsWith("/")) { + sb.append("/"); + } + } catch (BuildException e) { // relative path } @@ -960,6 +965,11 @@ public class FileUtils { } uri = uri.replace('/', File.separatorChar); + if (Os.isFamily("dos") && uri.startsWith("\\") && uri.length() > 2 + && Character.isLetter(uri.charAt(1)) && uri.charAt(2) == ':') { + uri = uri.substring(1); + } + StringBuffer sb = new StringBuffer(); CharacterIterator iter = new StringCharacterIterator(uri); for (char c = iter.first(); c != CharacterIterator.DONE; diff --git a/src/main/org/apache/tools/ant/util/JAXPUtils.java b/src/main/org/apache/tools/ant/util/JAXPUtils.java index 7f6b4256e..4d2f185fe 100644 --- a/src/main/org/apache/tools/ant/util/JAXPUtils.java +++ b/src/main/org/apache/tools/ant/util/JAXPUtils.java @@ -76,9 +76,11 @@ import org.xml.sax.XMLReader; public class JAXPUtils { /** - * The file protocol: 'file://' + * Helper for systemId. + * + * @since Ant 1.6 */ - private static final String FILE_PROTOCOL_PREFIX = "file://"; + private static final FileUtils fu = FileUtils.newFileUtils(); /** * Parser factory to use to create parsers. @@ -163,15 +165,7 @@ public class JAXPUtils { * @since Ant 1.5.2 */ public static String getSystemId(File file){ - String path = file.getAbsolutePath(); - path = path.replace('\\', '/'); - - // on Windows, use 'file:///' - if (File.separatorChar == '\\') { - return FILE_PROTOCOL_PREFIX + "/" + path; - } - // Unix, use 'file://' - return FILE_PROTOCOL_PREFIX + path; + return fu.toURI(file.getAbsolutePath()); } /** diff --git a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java index 23b4b9422..66704274a 100644 --- a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java @@ -412,8 +412,8 @@ public class FileUtilsTest extends TestCase { * test toUri */ public void testToURI() { - if (Os.isFamily("windows")) { - assertEquals("file://C:/foo", fu.toURI("c:\\foo")); + if (Os.isFamily("dos")) { + assertEquals("file:///C:/foo", fu.toURI("c:\\foo")); } assertEquals("file:///foo", fu.toURI("/foo")); assertEquals("file:./foo", fu.toURI("./foo")); @@ -429,8 +429,8 @@ public class FileUtilsTest extends TestCase { * test fromUri */ public void testFromURI() { - if (Os.isFamily("windows")) { - assertEquals("C:\\foo", fu.fromURI("file://c:/foo")); + if (Os.isFamily("dos")) { + assertEquals("C:\\foo", fu.fromURI("file:///c:/foo")); } assertEquals(localize("/foo"), fu.fromURI("file:///foo")); assertEquals("." + File.separator + "foo",