diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-12-11 02:13:51 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-12-11 02:13:51 +0000 |
commit | ddc28fdc7152a612dab9ff04eaafc2c20a875544 (patch) | |
tree | c915ec3c7ac0b3f382787ede943782a636c36d89 /libjava | |
parent | 9bdf7cc7f9d84deb0c8edb7fa2db44a463eec862 (diff) | |
download | gcc-ddc28fdc7152a612dab9ff04eaafc2c20a875544.tar.gz |
2002-12-10 Mark Wielaard <mark@klomp.org>
Tom Tromey <tromey@redhat.com>
* java/net/URLClassLoader.java (getCanonicalFileURL): New method.
(JarURLLoader): Use it.
(FileURLLoader): Likewise.
(JarURLResource.getURL): Use chained exception.
(FileResource.getURL): Likewise.
(FileURLLoader.getResource): Use canonical file name.
(addURL): Indentation fix.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@60019 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 11 | ||||
-rw-r--r-- | libjava/java/net/URLClassLoader.java | 65 |
2 files changed, 55 insertions, 21 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 76bd80594e5..20242558b88 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,14 @@ +2002-12-10 Mark Wielaard <mark@klomp.org> + Tom Tromey <tromey@redhat.com> + + * java/net/URLClassLoader.java (getCanonicalFileURL): New method. + (JarURLLoader): Use it. + (FileURLLoader): Likewise. + (JarURLResource.getURL): Use chained exception. + (FileResource.getURL): Likewise. + (FileURLLoader.getResource): Use canonical file name. + (addURL): Indentation fix. + 2002-12-10 Tom Tromey <tromey@redhat.com> * include/win32.h: Fixed typo in "DISABLE_JAVA_NET". diff --git a/libjava/java/net/URLClassLoader.java b/libjava/java/net/URLClassLoader.java index e37a81a5021..c6dc4b1d44d 100644 --- a/libjava/java/net/URLClassLoader.java +++ b/libjava/java/net/URLClassLoader.java @@ -212,7 +212,7 @@ public class URLClassLoader extends SecureClassLoader return null; } } - + /** * A <code>Resource</code> represents a resource in some * <code>URLLoader</code>. It also contains all information (e.g., @@ -271,6 +271,22 @@ public class URLClassLoader extends SecureClassLoader abstract InputStream getInputStream() throws IOException; } + static URL getCanonicalFileURL(URL url) + { + if ("file".equals(url.getProtocol())) + { + try + { + File f = new File(url.getFile()).getCanonicalFile(); + url = new URL("file", "", f.toString()); + } + catch (IOException ignore) + { + } + } + return url; + } + /** * A <code>JarURLLoader</code> is a type of <code>URLLoader</code> * only loading from jar url. @@ -282,8 +298,8 @@ public class URLClassLoader extends SecureClassLoader public JarURLLoader(URLClassLoader classloader, URL baseURL) { - super(classloader, baseURL); - + super(classloader, getCanonicalFileURL(baseURL)); + // cache url prefix for all resources in this jar url String external = baseURL.toExternalForm(); StringBuffer sb = new StringBuffer(external.length() + 6); @@ -306,7 +322,7 @@ public class URLClassLoader extends SecureClassLoader this.baseJarURL = baseJarURL; this.jarfile = jarfile; } - + /** get resource with the name "name" in the jar url */ Resource getResource(String name) { @@ -331,7 +347,6 @@ public class URLClassLoader extends SecureClassLoader return null; } } - } final static class JarURLResource extends Resource @@ -358,7 +373,7 @@ public class URLClassLoader extends SecureClassLoader { return entry.getCertificates(); } - + URL getURL() { try @@ -368,7 +383,9 @@ public class URLClassLoader extends SecureClassLoader } catch(MalformedURLException e) { - throw new InternalError(e.toString()); + InternalError ie = new InternalError(); + ie.initCause(e); + throw ie; } } } @@ -468,19 +485,24 @@ public class URLClassLoader extends SecureClassLoader FileURLLoader(URLClassLoader classloader, URL url) { - super(classloader, url); - // Note that this must be a "file" protocol URL. - dir = new File(url.getFile()); + super(classloader, getCanonicalFileURL(url)); + dir = new File(baseURL.getFile()); } - + /** get resource with the name "name" in the file url */ Resource getResource(String name) { File file = new File(dir, name); + try + { + file = file.getCanonicalFile(); + } + catch (IOException ignore) + { + } if (file.exists() && !file.isDirectory()) return new FileResource(this, name, file); - else - return null; + return null; } } @@ -503,7 +525,7 @@ public class URLClassLoader extends SecureClassLoader { return (int)file.length(); } - + public URL getURL() { try @@ -513,7 +535,9 @@ public class URLClassLoader extends SecureClassLoader } catch(MalformedURLException e) { - throw new InternalError(e.toString()); + InternalError ie = new InternalError(); + ie.initCause(e); + throw ie; } } } @@ -667,13 +691,12 @@ public class URLClassLoader extends SecureClassLoader { String file = newUrl.getFile(); // Check that it is not a directory - if (!(file.endsWith("/") || file.endsWith(File.separator))) + if (! (file.endsWith("/") || file.endsWith(File.separator))) loader = new JarURLLoader(this, newUrl); - else // it's a url that point to a jar file - if ("file".equals(newUrl.getProtocol())) - loader = new FileURLLoader(this, newUrl); - else - loader = new RemoteURLLoader(this, newUrl); + else if ("file".equals(newUrl.getProtocol())) + loader = new FileURLLoader(this, newUrl); + else + loader = new RemoteURLLoader(this, newUrl); // cache it urlloaders.put(newUrl, loader); |