geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r481332 - /geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
Date Fri, 01 Dec 2006 18:23:29 GMT
Author: dblevins
Date: Fri Dec  1 10:23:28 2006
New Revision: 481332

URL: http://svn.apache.org/viewvc?view=rev&rev=481332
Log:
Fix the classfinder so that it doesn't need all urls to start with "jar" when they point to
jars

Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java?view=diff&rev=481332&r1=481331&r2=481332
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassFinder.java
Fri Dec  1 10:23:28 2006
@@ -31,6 +31,9 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.AnnotatedElement;
 import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.URLConnection;
+import java.net.JarURLConnection;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -119,7 +122,15 @@
                 if (location.getProtocol().equals("jar")) {
                     classNames.addAll(jar(location));
                 } else if (location.getProtocol().equals("file")) {
-                    classNames.addAll(file(location));
+                    try {
+                        // See if it's actually a jar
+                        URL jarUrl = new URL("jar", "", location.toExternalForm() + "!/");
+                        JarURLConnection juc = (JarURLConnection) jarUrl.openConnection();
+                        juc.getJarFile();
+                        classNames.addAll(jar(jarUrl));
+                    } catch (IOException e) {
+                        classNames.addAll(file(location));
+                    }
                 }
             } catch (Exception e) {
                 e.printStackTrace();
@@ -382,12 +393,22 @@
     }
 
     private List<String> jar(URL location) throws IOException {
-        List<String> classNames = new ArrayList();
-
-        String jarPath = location.getFile().replaceFirst("./META-INF", "");
+        String jarPath = location.getFile();
+        if (jarPath.indexOf("!") > -1){
+            jarPath = jarPath.substring(0, jarPath.indexOf("!"));
+        }
         URL url = new URL(jarPath);
         InputStream in = url.openStream();
-        JarInputStream jarStream = new JarInputStream(in);
+        try {
+            JarInputStream jarStream = new JarInputStream(in);
+            return jar(jarStream);
+        } finally {
+            in.close();
+        }
+    }
+
+    private List<String> jar(JarInputStream jarStream) throws IOException {
+        List<String> classNames = new ArrayList();
 
         JarEntry entry;
         while ((entry = jarStream.getNextJarEntry()) != null) {



Mime
View raw message