Browse Source

Bugzilla Report: 39295

Reporter: Waldek Herka
extract the fileToURL code
use it for tools jar as well as the other paths


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@396563 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 19 years ago
parent
commit
bce9fe013a
4 changed files with 30 additions and 26 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +2
    -6
      src/main/org/apache/tools/ant/launch/Launcher.java
  4. +24
    -20
      src/main/org/apache/tools/ant/launch/Locator.java

+ 1
- 0
CONTRIBUTORS View File

@@ -231,6 +231,7 @@ Tom Ball
Tom Dimock Tom Dimock
Tom Eugelink Tom Eugelink
Ulrich Schmidt Ulrich Schmidt
Waldek Herka
Will Wang Will Wang
William Ferguson William Ferguson
Wolfgang Werner Wolfgang Werner


+ 3
- 0
WHATSNEW View File

@@ -397,6 +397,9 @@ Other changes:
attribute will read default values from the properties attribute will read default values from the properties
ant.build.javac.source and ant.build.javac.target. ant.build.javac.source and ant.build.javac.target.


* Handling of ' ', '#' in CLASSPATH and '#' in -lib (cannot use ' '
in -lib on UNIX at the moment). Bugzilla Report 39295.

Changes from Ant 1.6.4 to Ant 1.6.5 Changes from Ant 1.6.4 to Ant 1.6.5
=================================== ===================================




+ 2
- 6
src/main/org/apache/tools/ant/launch/Launcher.java View File

@@ -130,11 +130,7 @@ public class Launcher {
} }
} }


try {
libPathURLs.add(new URL(Locator.encodeURI(element.toURL().toString())));
} catch (UnsupportedEncodingException ex) {
throw new MalformedURLException(ex.toString());
}
libPathURLs.add(Locator.fileToURL(element));
} }
} }


@@ -255,7 +251,7 @@ public class Launcher {
systemJars.length); systemJars.length);


if (toolsJar != null) { if (toolsJar != null) {
jars[jars.length - 1] = toolsJar.toURL();
jars[jars.length - 1] = Locator.fileToURL(toolsJar);
} }






+ 24
- 20
src/main/org/apache/tools/ant/launch/Locator.java View File

@@ -310,6 +310,28 @@ public final class Locator {
return sb == null ? path : sb.toString(); return sb == null ? path : sb.toString();
} }


/**
* Convert a File to a URL.
* File.toURL() does not encode characters like #.
* File.toURI() has been introduced in java 1.4, so
* ANT cannot use it (except by reflection)
* FileUtils.toURI() cannot be used by Locator.java
* Implemented this way.
* File.toURL() adds file: and changes '\' to '/' for dos OSes
* encodeURI converts characters like ' ' and '#' to %DD
* @param file the file to convert
* @return URL the converted File
* @throws MalformedURLException on error
*/
public static URL fileToURL(File file)
throws MalformedURLException {
try {
return new URL(encodeURI(file.toURL().toString()));
} catch (UnsupportedEncodingException ex) {
throw new MalformedURLException(ex.toString());
}
}

/** /**
* Get the File necessary to load the Sun compiler tools. If the classes * Get the File necessary to load the Sun compiler tools. If the classes
* are available to this class, then no additional URL is required and * are available to this class, then no additional URL is required and
@@ -401,20 +423,7 @@ public final class Locator {
String path = location.getPath(); String path = location.getPath();
for (int i = 0; i < extensions.length; ++i) { for (int i = 0; i < extensions.length; ++i) {
if (path.toLowerCase().endsWith(extensions[i])) { if (path.toLowerCase().endsWith(extensions[i])) {
try {
/**
* File.toURL() does not encode characters like #.
* File.toURI() has been introduced in java 1.4, so
* ANT cannot use it (except by reflection)
* FileUtils.toURI() cannot be used by Locator.java
* Implemented this way.
* File.toURL() adds file: and changes '\' to '/' for dos OSes
* encodeURI converts characters like ' ' and '#' to %DD
*/
urls[0] = new URL(encodeURI(location.toURL().toString()));
} catch (UnsupportedEncodingException ex) {
throw new MalformedURLException(ex.toString());
}
urls[0] = fileToURL(location);
break; break;
} }
} }
@@ -433,12 +442,7 @@ public final class Locator {
}); });
urls = new URL[matches.length]; urls = new URL[matches.length];
for (int i = 0; i < matches.length; ++i) { for (int i = 0; i < matches.length; ++i) {
try {
// See comments above.
urls[i] = new URL(encodeURI(matches[i].toURL().toString()));
} catch (UnsupportedEncodingException ex) {
throw new MalformedURLException(ex.toString());
}
urls[i] = fileToURL(matches[i]);
} }
return urls; return urls;
} }


Loading…
Cancel
Save