Browse Source

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
master
Stefan Bodewig 22 years ago
parent
commit
fb2b9616dc
4 changed files with 23 additions and 15 deletions
  1. +4
    -0
      WHATSNEW
  2. +10
    -0
      src/main/org/apache/tools/ant/util/FileUtils.java
  3. +5
    -11
      src/main/org/apache/tools/ant/util/JAXPUtils.java
  4. +4
    -4
      src/testcases/org/apache/tools/ant/util/FileUtilsTest.java

+ 4
- 0
WHATSNEW View File

@@ -65,6 +65,10 @@ Fixed bugs:

* the errorsbeginat attribute of the <http> 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 <jar> has been reenabled.


+ 10
- 0
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -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;


+ 5
- 11
src/main/org/apache/tools/ant/util/JAXPUtils.java View File

@@ -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());
}

/**


+ 4
- 4
src/testcases/org/apache/tools/ant/util/FileUtilsTest.java View File

@@ -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",


Loading…
Cancel
Save