Commit a7e693d5 by Mark Wielaard Committed by Tom Tromey

URLClassLoader.java (getCanonicalFileURL): New method.

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.

Co-Authored-By: Tom Tromey <tromey@redhat.com>

From-SVN: r60019
parent d23faea1
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> 2002-12-10 Tom Tromey <tromey@redhat.com>
* include/win32.h: Fixed typo in "DISABLE_JAVA_NET". * include/win32.h: Fixed typo in "DISABLE_JAVA_NET".
......
...@@ -271,6 +271,22 @@ public class URLClassLoader extends SecureClassLoader ...@@ -271,6 +271,22 @@ public class URLClassLoader extends SecureClassLoader
abstract InputStream getInputStream() throws IOException; 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> * A <code>JarURLLoader</code> is a type of <code>URLLoader</code>
* only loading from jar url. * only loading from jar url.
...@@ -282,7 +298,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -282,7 +298,7 @@ public class URLClassLoader extends SecureClassLoader
public JarURLLoader(URLClassLoader classloader, URL baseURL) public JarURLLoader(URLClassLoader classloader, URL baseURL)
{ {
super(classloader, baseURL); super(classloader, getCanonicalFileURL(baseURL));
// cache url prefix for all resources in this jar url // cache url prefix for all resources in this jar url
String external = baseURL.toExternalForm(); String external = baseURL.toExternalForm();
...@@ -331,7 +347,6 @@ public class URLClassLoader extends SecureClassLoader ...@@ -331,7 +347,6 @@ public class URLClassLoader extends SecureClassLoader
return null; return null;
} }
} }
} }
final static class JarURLResource extends Resource final static class JarURLResource extends Resource
...@@ -368,7 +383,9 @@ public class URLClassLoader extends SecureClassLoader ...@@ -368,7 +383,9 @@ public class URLClassLoader extends SecureClassLoader
} }
catch(MalformedURLException e) catch(MalformedURLException e)
{ {
throw new InternalError(e.toString()); InternalError ie = new InternalError();
ie.initCause(e);
throw ie;
} }
} }
} }
...@@ -468,18 +485,23 @@ public class URLClassLoader extends SecureClassLoader ...@@ -468,18 +485,23 @@ public class URLClassLoader extends SecureClassLoader
FileURLLoader(URLClassLoader classloader, URL url) FileURLLoader(URLClassLoader classloader, URL url)
{ {
super(classloader, url); super(classloader, getCanonicalFileURL(url));
// Note that this must be a "file" protocol URL. dir = new File(baseURL.getFile());
dir = new File(url.getFile());
} }
/** get resource with the name "name" in the file url */ /** get resource with the name "name" in the file url */
Resource getResource(String name) Resource getResource(String name)
{ {
File file = new File(dir, name); File file = new File(dir, name);
try
{
file = file.getCanonicalFile();
}
catch (IOException ignore)
{
}
if (file.exists() && !file.isDirectory()) if (file.exists() && !file.isDirectory())
return new FileResource(this, name, file); return new FileResource(this, name, file);
else
return null; return null;
} }
} }
...@@ -513,7 +535,9 @@ public class URLClassLoader extends SecureClassLoader ...@@ -513,7 +535,9 @@ public class URLClassLoader extends SecureClassLoader
} }
catch(MalformedURLException e) catch(MalformedURLException e)
{ {
throw new InternalError(e.toString()); InternalError ie = new InternalError();
ie.initCause(e);
throw ie;
} }
} }
} }
...@@ -667,10 +691,9 @@ public class URLClassLoader extends SecureClassLoader ...@@ -667,10 +691,9 @@ public class URLClassLoader extends SecureClassLoader
{ {
String file = newUrl.getFile(); String file = newUrl.getFile();
// Check that it is not a directory // 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); loader = new JarURLLoader(this, newUrl);
else // it's a url that point to a jar file else if ("file".equals(newUrl.getProtocol()))
if ("file".equals(newUrl.getProtocol()))
loader = new FileURLLoader(this, newUrl); loader = new FileURLLoader(this, newUrl);
else else
loader = new RemoteURLLoader(this, newUrl); loader = new RemoteURLLoader(this, newUrl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment