Get rid of some code duplication. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273645 13f79535-47bb-0310-9956-ffa450edef68master
@@ -65,6 +65,10 @@ Fixed bugs: | |||||
* the errorsbeginat attribute of the <http> condition didn't work. | * 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: | Other changes: | ||||
-------------- | -------------- | ||||
* The filesetmanifest attribute of <jar> has been reenabled. | * The filesetmanifest attribute of <jar> has been reenabled. | ||||
@@ -920,6 +920,11 @@ public class FileUtils { | |||||
try { | try { | ||||
path = normalize(path).getAbsolutePath(); | path = normalize(path).getAbsolutePath(); | ||||
sb.append("//"); | sb.append("//"); | ||||
// add an extra slash for filesystems with drive-specifiers | |||||
if (!path.startsWith("/")) { | |||||
sb.append("/"); | |||||
} | |||||
} catch (BuildException e) { | } catch (BuildException e) { | ||||
// relative path | // relative path | ||||
} | } | ||||
@@ -960,6 +965,11 @@ public class FileUtils { | |||||
} | } | ||||
uri = uri.replace('/', File.separatorChar); | 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(); | StringBuffer sb = new StringBuffer(); | ||||
CharacterIterator iter = new StringCharacterIterator(uri); | CharacterIterator iter = new StringCharacterIterator(uri); | ||||
for (char c = iter.first(); c != CharacterIterator.DONE; | for (char c = iter.first(); c != CharacterIterator.DONE; | ||||
@@ -76,9 +76,11 @@ import org.xml.sax.XMLReader; | |||||
public class JAXPUtils { | 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. | * Parser factory to use to create parsers. | ||||
@@ -163,15 +165,7 @@ public class JAXPUtils { | |||||
* @since Ant 1.5.2 | * @since Ant 1.5.2 | ||||
*/ | */ | ||||
public static String getSystemId(File file){ | 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()); | |||||
} | } | ||||
/** | /** | ||||
@@ -412,8 +412,8 @@ public class FileUtilsTest extends TestCase { | |||||
* test toUri | * test toUri | ||||
*/ | */ | ||||
public void testToURI() { | 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")); | ||||
assertEquals("file:./foo", fu.toURI("./foo")); | assertEquals("file:./foo", fu.toURI("./foo")); | ||||
@@ -429,8 +429,8 @@ public class FileUtilsTest extends TestCase { | |||||
* test fromUri | * test fromUri | ||||
*/ | */ | ||||
public void testFromURI() { | 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(localize("/foo"), fu.fromURI("file:///foo")); | ||||
assertEquals("." + File.separator + "foo", | assertEquals("." + File.separator + "foo", | ||||