From 55c133cecd1c4802f356b7013f5e851e94ebd8c3 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 20 Apr 2004 13:25:08 +0000 Subject: [PATCH] Generate proper file URLs in AntClassLoader#getResource, PR: 28060 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276354 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 +++ src/main/org/apache/tools/ant/AntClassLoader.java | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 919ca9b90..31aea7673 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -119,6 +119,9 @@ Fixed bugs: * and are working together. Bugzilla report 27218 +* AntClassLoader#getResource could return invalid URLs. Bugzilla + Report 28060. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java index 43e2e0b12..14b78e246 100644 --- a/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/src/main/org/apache/tools/ant/AntClassLoader.java @@ -32,6 +32,7 @@ import java.util.Vector; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.util.LoaderUtils; @@ -45,6 +46,8 @@ import org.apache.tools.ant.util.LoaderUtils; */ public class AntClassLoader extends ClassLoader implements BuildListener { + private static final FileUtils fileUtils = FileUtils.newFileUtils(); + /** * An enumeration of all resources of a given name found within the * classpath of this class loader. This enumeration is used by the @@ -888,7 +891,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { if (resource.exists()) { try { - return new URL("file:" + resource.toString()); + return fileUtils.getFileURL(resource); } catch (MalformedURLException ex) { return null; } @@ -903,7 +906,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { ZipEntry entry = zipFile.getEntry(resourceName); if (entry != null) { try { - return new URL("jar:file:" + file.toString() + return new URL("jar:" + fileUtils.getFileURL(file) + "!/" + entry); } catch (MalformedURLException ex) { return null;