[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Add support for (recursive) URL manifest Class-Path ha
From: |
Mark Wielaard |
Subject: |
[cp-patches] FYI: Add support for (recursive) URL manifest Class-Path handling from libgcj |
Date: |
Tue, 15 Feb 2005 21:02:53 +0100 |
Hi,
This adds support for (recursively) handling the CLASS_PATH attribute in
the jar Manifest file for libgcj. I made one little change to how the
Class-Path entry is parsed. All MANIFEST.MF files I could find use a
space " " as path separator. This is also what the JCLv1 supplement says
should be used.
2005-02-15 Mark Wielaard <address@hidden>
* java/net/URLClassLoader.java (JarURLLoader.JarURLLoader): Just use
space for parsing CLASS_PATH attribute.
2005-02-15 Andrew Haley <address@hidden>
* java/net/URLClassLoader.java
(URLLoader.getClassPath): New method.
(JarURLLoader.JarURLLoader): Read mainfest to parse "Class-Path"
attribute and add URLs for each entry.
(JarURLLoader.classPath): New field.
(JarURLLoader.getClassPath): New method.
(addURLImpl): Scan through the list of extraUrls in the new
loader, adding them to our urlinfos.
(definePackage, findURLResource, findResources): Use
urlinfos.size(), not urls.size().
This makes things like jamvm -jar some.jar work when it contains a
manifest file pointing to other (relative) classpaths to use.
Committed,
Mark
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLClassLoader.java,v
retrieving revision 1.27
diff -u -r1.27 URLClassLoader.java
--- java/net/URLClassLoader.java 15 Feb 2005 15:36:04 -0000 1.27
+++ java/net/URLClassLoader.java 15 Feb 2005 19:52:24 -0000
@@ -55,12 +55,15 @@
import java.security.cert.Certificate;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.StringTokenizer;
import java.util.Vector;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+
/**
* A secure class loader that can load classes and resources from
* multiple locations. Given an array of <code>URL</code>s this class
@@ -143,9 +146,10 @@
private final Vector urls = new Vector();
/**
- * Store pre-parsed information for each url into this vector
- * each element is a URL loader, corresponding to the URL of
- * the same index in "urls"
+ * Store pre-parsed information for each url into this vector: each
+ * element is a URL loader. A jar file has its own class-path
+ * attribute which adds to the URLs that will be searched, but this
+ * does not add to the list of urls.
*/
private final Vector urlinfos = new Vector();
@@ -214,6 +218,11 @@
{
return null;
}
+
+ Vector getClassPath()
+ {
+ return null;
+ }
}
/**
@@ -283,6 +292,8 @@
final JarFile jarfile; // The jar file for this url
final URL baseJarURL; // Base jar: url for all resources loaded from jar
+ Vector classPath; // The "Class-Path" attribute of this Jar's manifest
+
public JarURLLoader(URLClassLoader classloader, URL baseURL)
{
super(classloader, baseURL);
@@ -295,19 +306,48 @@
sb.append("!/");
String jarURL = sb.toString();
+ this.classPath = null;
URL baseJarURL = null;
JarFile jarfile = null;
try
- {
- baseJarURL =
- new URL(null, jarURL, classloader.getURLStreamHandler("jar"));
-
- jarfile =
- ((JarURLConnection) baseJarURL.openConnection()).getJarFile();
- }
+ {
+ baseJarURL =
+ new URL(null, jarURL, classloader.getURLStreamHandler("jar"));
+
+ jarfile =
+ ((JarURLConnection) baseJarURL.openConnection()).getJarFile();
+
+ Manifest manifest;
+ Attributes attributes;
+ String classPathString;
+
+ if ((manifest = jarfile.getManifest()) != null
+ && (attributes = manifest.getMainAttributes()) != null
+ && ((classPathString
+ = attributes.getValue(Attributes.Name.CLASS_PATH))
+ != null))
+ {
+ this.classPath = new Vector();
+
+ StringTokenizer st = new StringTokenizer(classPathString, " ");
+ while (st.hasMoreElements ())
+ {
+ String e = st.nextToken ();
+ try
+ {
+ URL url = new URL(baseURL, e);
+ this.classPath.add(url);
+ }
+ catch (java.net.MalformedURLException xx)
+ {
+ // Give up
+ }
+ }
+ }
+ }
catch (IOException ioe)
{
- /* ignored */
+ /* ignored */
}
this.baseJarURL = baseJarURL;
@@ -341,6 +381,11 @@
return null;
}
}
+
+ Vector getClassPath()
+ {
+ return classPath;
+ }
}
static final class JarURLResource extends Resource
@@ -650,6 +695,7 @@
*/
protected void addURL(URL newUrl)
{
+ urls.add(newUrl);
addURLImpl(newUrl);
}
@@ -680,8 +726,21 @@
urlloaders.put(newUrl, loader);
}
- urls.add(newUrl);
- urlinfos.add(loader);
+ urlinfos.add(loader);
+
+ Vector extraUrls = loader.getClassPath();
+ if (extraUrls != null)
+ {
+ Iterator it = extraUrls.iterator();
+ while (it.hasNext())
+ {
+ URL url = (URL)it.next();
+ URLLoader extraLoader = (URLLoader) urlloaders.get(url);
+ if (! urlinfos.contains (extraLoader))
+ addURLImpl(url);
+ }
+ }
+
}
}
@@ -692,7 +751,7 @@
private void addURLs(URL[] newUrls)
{
for (int i = 0; i < newUrls.length; i++)
- addURLImpl(newUrls[i]);
+ addURL(newUrls[i]);
}
/**
@@ -890,7 +949,7 @@
*/
private Resource findURLResource(String resourceName)
{
- int max = urls.size();
+ int max = urlinfos.size();
for (int i = 0; i < max; i++)
{
URLLoader loader = (URLLoader) urlinfos.elementAt(i);
@@ -961,7 +1020,7 @@
throws IOException
{
Vector resources = new Vector();
- int max = urls.size();
+ int max = urlinfos.size();
for (int i = 0; i < max; i++)
{
URLLoader loader = (URLLoader) urlinfos.elementAt(i);
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Add support for (recursive) URL manifest Class-Path handling from libgcj,
Mark Wielaard <=