[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: class loading fixes

Kaffe CVS cvs-commits at kaffe.org
Tue Feb 15 19:51:50 PST 2005


PatchSet 5551 
Date: 2005/02/16 03:43:33
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: class loading fixes

2005-02-16  Dalibor Topic  <robilad at kaffe.org>

        Resynced with GNU Classpath.

        2005-02-15  Mark Wielaard  <mark at klomp.org>

        * java/net/URLClassLoader.java (JarURLLoader.JarURLLoader): Just use
        space for parsing CLASS_PATH attribute.

        2005-02-15  Andrew Haley  <aph at redhat.com>

        * 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().

Members: 
	ChangeLog:1.3595->1.3596 
	libraries/javalib/java/net/URLClassLoader.java:1.22->1.23 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3595 kaffe/ChangeLog:1.3596
--- kaffe/ChangeLog:1.3595	Wed Feb 16 03:30:19 2005
+++ kaffe/ChangeLog	Wed Feb 16 03:43:33 2005
@@ -2,6 +2,28 @@
 
 	Resynced with GNU Classpath.
 
+	2005-02-15  Mark Wielaard  <mark at klomp.org>
+
+        * java/net/URLClassLoader.java (JarURLLoader.JarURLLoader): Just use
+        space for parsing CLASS_PATH attribute.
+
+	2005-02-15  Andrew Haley  <aph at redhat.com>
+
+        * 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().
+
+2005-02-16  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+
 	2005-02-14  Mark Wielaard  <mark at klomp.org>
 
         * java/net/URLClassLoader.java (findClass): Throw
Index: kaffe/libraries/javalib/java/net/URLClassLoader.java
diff -u kaffe/libraries/javalib/java/net/URLClassLoader.java:1.22 kaffe/libraries/javalib/java/net/URLClassLoader.java:1.23
--- kaffe/libraries/javalib/java/net/URLClassLoader.java:1.22	Wed Feb 16 03:30:24 2005
+++ kaffe/libraries/javalib/java/net/URLClassLoader.java	Wed Feb 16 03:43:37 2005
@@ -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);




More information about the kaffe mailing list