geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r767617 [2/2] - in /geronimo/sandbox/djencks/framework: buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/ configs/jee-specs/ m...
Date Wed, 22 Apr 2009 18:52:45 GMT
Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/ConfigurationClassLoaderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/ConfigurationClassLoaderExtension.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/ConfigurationClassLoaderExtension.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/ConfigurationClassLoaderExtension.java
Wed Apr 22 18:52:43 2009
@@ -22,17 +22,26 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
+import java.util.Enumeration;
+import java.io.IOException;
+
+import org.apache.geronimo.kernel.repository.Artifact;
 
 /**
  *
  * @version $Rev:$ $Date:$
  */
 public interface ConfigurationClassLoaderExtension {
+    
     void addURL(URL url);
 
-    Class<?> loadClassInternal(String name,
-        boolean resolve,
-        List<ClassLoader> visitedClassLoaders) throws ClassNotFoundException, MalformedURLException;
+    Class<?> loadClassInternal(String name, boolean resolve, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException, MalformedURLException;
     
     void destroy();
+
+    URL findResource(String name);
+
+    Enumeration<URL> findResources(String name) throws IOException;
+
+    Artifact getId();
 }

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/DependencySAXHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/DependencySAXHandler.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/DependencySAXHandler.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/DependencySAXHandler.java
Wed Apr 22 18:52:43 2009
@@ -33,6 +33,7 @@
  */
 public final class DependencySAXHandler extends DefaultHandler {
     private final GlobalClassLoaderRegister register;
+    private final Artifact docSourceArtifact;
     private StringBuilder currentString = new StringBuilder();
     private boolean dependency;
     private boolean parent;
@@ -43,11 +44,12 @@
     private Artifact child;
     private Set<Artifact> parents;
 
-    public DependencySAXHandler(GlobalClassLoaderRegister register) {
+    public DependencySAXHandler(GlobalClassLoaderRegister register, Artifact docSourceArtifact)
{
         if (null == register) {
             throw new IllegalArgumentException("register is required");
         }
         this.register = register;
+        this.docSourceArtifact = docSourceArtifact;
     }
 
     @Override
@@ -86,7 +88,7 @@
                 parent = false;
             } else if (dependency) {
                 Artifact tmp = child == null? getArtifact(): child;
-                register.register(tmp, parents);
+                register.register(tmp, parents, docSourceArtifact);
                 dependency = false;
                 parents = null;
                 child = null;

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoader.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoader.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoader.java
Wed Apr 22 18:52:43 2009
@@ -30,56 +30,64 @@
 import java.util.List;
 import java.util.Set;
 import java.util.Collections;
+import java.util.ArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
 import org.apache.geronimo.kernel.config.ChildrenConfigurationClassLoader;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.classloader.UnionEnumeration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
  * @version $Rev: 732599 $ $Date: 2009-01-08 14:36:25 +1100 (Thu, 08 Jan 2009) $
  */
-public class GlobalClassLoader extends URLClassLoader {
+public class GlobalClassLoader extends URLClassLoader implements ConfigurationClassLoaderExtension
{
     private static final Logger LOG = LoggerFactory.getLogger(GlobalClassLoader.class);
 
     private final Artifact artifact;
     private final Set<Artifact> dependencies;
     private final CopyOnWriteArraySet<String> resourcesNotFound = new CopyOnWriteArraySet<String>();
-    private ClassLoader[] parents;
+    private ConfigurationClassLoaderExtension[] parents;
 
-    public GlobalClassLoader(Artifact artifact, URL[] urls, ClassLoader[] parents) {
+    public GlobalClassLoader(Artifact artifact, URL[] urls, ConfigurationClassLoaderExtension[]
parents) {
         super(urls);
         this.artifact = artifact;
         this.parents = parents;
         dependencies = Collections.emptySet();
     }
 
-    public Artifact getArtifact() {
+    public Artifact getId() {
         return artifact;
     }
-    
-    public Class<?> loadClass(String name, List<ClassLoader> visitedClassLoaders)
throws ClassNotFoundException {
+
+    public Class<?> loadClass(String name, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException {
         return loadClass(name, false, visitedClassLoaders);
     }
-    
+
     protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
-        return loadClass(name, resolve, new LinkedList<ClassLoader>());
+        return loadClass(name, resolve, new LinkedList<ConfigurationClassLoaderExtension>());
     }
-    
-    protected synchronized Class<?> loadClass(String name, boolean resolve, List<ClassLoader>
visitedClassLoaders) throws ClassNotFoundException {
+
+    protected synchronized Class<?> loadClass(String name, boolean resolve, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException {
         return loadClass(name, resolve, visitedClassLoaders, false);
     }
-    
-    protected synchronized Class<?> loadClassInternal(String name, boolean resolve,
List<ClassLoader> visitedClassLoaders) throws ClassNotFoundException, MalformedURLException
{
+
+    public void addURL(URL url) {
+        throw new RuntimeException("dont call this");
+    }
+
+    public synchronized Class<?> loadClassInternal(String name, boolean resolve, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException, MalformedURLException {
         return loadClass(name, resolve, visitedClassLoaders, true);
     }
-    
+
+    public void destroy() {
+    }
+
     protected synchronized Class<?> loadClass(String name,
-            boolean resolve,
-            List<ClassLoader> visitedClassLoaders,
-            boolean forParent) throws ClassNotFoundException {
+                                              boolean resolve,
+                                              List<ConfigurationClassLoaderExtension>
visitedClassLoaders,
+                                              boolean forParent) throws ClassNotFoundException
{
         //
         // Check if class is in the loaded classes cache
         //
@@ -87,7 +95,7 @@
         if (cachedClass != null) {
             return resolveClass(cachedClass, resolve);
         }
-        
+
         if (!forParent) {
             //
             // If this is a java.* or primitive class, use the primordial ClassLoader...
@@ -106,7 +114,7 @@
                 }
             }
         }
-        
+
         //
         // Check parent class loaders
         //
@@ -114,7 +122,7 @@
         if (clazz != null) {
             return resolveClass(clazz, resolve);
         }
-        
+
         //
         // if we are not using inverse class loading, check local urls now
         //
@@ -125,37 +133,39 @@
             clazz = findClass(name);
             return resolveClass(clazz, resolve);
         } catch (ClassNotFoundException ignored) {
+        } catch (NoClassDefFoundError e) {
+            throw new NoClassDefFoundError("Error for class: " + name + " could not find:
" + e.getMessage() + " in classLoader: \n" + toString());
         }
-        
+
         if (forParent) {
             return null;
         }
         throw new ClassNotFoundException(name + " in classloader " + this);
     }
-    
-    private synchronized Class<?> checkParents(String name, boolean resolve, List<ClassLoader>
visitedClassLoaders) throws ClassNotFoundException {
-        for (ClassLoader parent : parents) {
+
+    private synchronized Class<?> checkParents(String name, boolean resolve, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException {
+        for (ConfigurationClassLoaderExtension parent : parents) {
             if (!visitedClassLoaders.contains(parent)) {
                 visitedClassLoaders.add(parent);  // Track that we've been here before
                 try {
-        	        if (parent instanceof GlobalClassLoader) {
-        	        	Class clazz = ((GlobalClassLoader) parent).loadClassInternal(name, resolve,
visitedClassLoaders);
-        	        	if (clazz != null) return resolveClass(clazz, resolve);
-        	        } else if (parent instanceof ChildrenConfigurationClassLoader) {
-                        Class clazz = ((ChildrenConfigurationClassLoader) parent).loadClass(name,
visitedClassLoaders);
+//                    if (parent instanceof GlobalClassLoader) {
+                        Class clazz = parent.loadClassInternal(name, resolve, visitedClassLoaders);
                         if (clazz != null) return resolveClass(clazz, resolve);
-        	        } else {
-        	        	return parent.loadClass(name);
-        	        }
-    	    	} catch (ClassNotFoundException cnfe) {
+//                    } else if (parent instanceof ChildrenConfigurationClassLoader) {
+//                        Class clazz = ((ChildrenConfigurationClassLoader) parent).loadClassInternal(name,
resolve, visitedClassLoaders);
+//                        if (clazz != null) return resolveClass(clazz, resolve);
+//                    } else {
+//                        return ((ClassLoader)parent).loadClass(name);
+//                    }
+                } catch (ClassNotFoundException cnfe) {
                     // ignore
                 } catch (MalformedURLException me) {
                     LOG.debug("Failed findClass for {}", name, me);
                 }
             }
-    	} 
-     	// To avoid yet another CNFE we'll simply return null and let the caller handle appropriately.
-    	return null;
+        }
+        // To avoid yet another CNFE we'll simply return null and let the caller handle appropriately.
+        return null;
     }
 
     private Class resolveClass(Class clazz, boolean resolve) {
@@ -167,41 +177,33 @@
 
     @Override
     public Enumeration<URL> getResources(String name) throws IOException {
-        Set<URL> foundResources = new HashSet<URL>();
-        
-        for (ClassLoader parent : parents) {
-            Enumeration<URL> urls = parent.getResources(name);
-            while (urls.hasMoreElements()) {
-                URL url = urls.nextElement();
-                foundResources.add(url);
+        List<Enumeration<URL>> urls = new ArrayList<Enumeration<URL>>();
+
+        for (ConfigurationClassLoaderExtension parent : parents) {
+            if (parent instanceof ClassLoader) {
+                urls.add(((ClassLoader)parent).getResources(name));
+            } else {
+                urls.add(parent.findResources(name));
             }
         }
-        
-        Enumeration<URL> urls = findResources(name);
-        while (urls.hasMoreElements()) {
-            URL url = urls.nextElement();
-            foundResources.add(url);
-        }
 
-        final Iterator<URL> iterator = foundResources.iterator();
-        return new Enumeration<URL>() {
-            public boolean hasMoreElements() {
-                return iterator.hasNext();
-            }
+        urls.add(findResources(name));
 
-            public URL nextElement() {
-                return iterator.next();
-            }
-        };
+        return new UnionEnumeration(urls);
     }
-    
+
     public URL getResource(String name) {
         if (resourcesNotFound.contains(name)) {
             return null;
         }
 
-        for (ClassLoader parent : parents) {
-            URL url = parent.getResource(name);
+        for (ConfigurationClassLoaderExtension parent : parents) {
+            URL url = null;
+            if (parent instanceof ClassLoader) {
+                url = ((ClassLoader)parent).getResource(name);
+            } else {
+                url = parent.findResource(name);
+            }
             if (url != null) {
                 return url;
             }
@@ -221,11 +223,31 @@
 
     @Override
     public String toString() {
-        return "GlobalClassLoader [" + artifact + "]";
+        StringBuilder buf = new StringBuilder();
+        toString(buf, "", new HashSet<Artifact>());
+        return buf.toString();
+    }
+
+    protected void toString(StringBuilder buf, String indent, Set<Artifact> known)
{
+        if (known.contains(artifact)) {
+            buf.append(indent).append("GlobalClassLoader [").append(artifact).append("] (already
listed)\n");
+            return;
+        }
+        buf.append(indent).append("GlobalClassLoader [").append(artifact).append("]\n");
+        known.add(artifact);
+        indent += "  ";
+        for (ConfigurationClassLoaderExtension parent : parents) {
+            if (parent instanceof GlobalClassLoader) {
+                ((GlobalClassLoader) parent).toString(buf, indent, known);
+            } else {
+                buf.append(indent).append(parent).append("\n");
+            }
+
+        }
     }
 
     public Set<Artifact> getDependencies() {
         return dependencies;
     }
-    
+
 }

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderDependencyResolver.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderDependencyResolver.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderDependencyResolver.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderDependencyResolver.java
Wed Apr 22 18:52:43 2009
@@ -29,5 +29,5 @@
  * @version $Rev:$ $Date:$
  */
 public interface GlobalClassLoaderDependencyResolver {
-    void resolve(URL url, GlobalClassLoaderRegister register);
+    void resolve(URL url, GlobalClassLoaderRegister register, Artifact docSourceArtifact);
 }

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderRegister.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderRegister.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderRegister.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/GlobalClassLoaderRegister.java
Wed Apr 22 18:52:43 2009
@@ -28,15 +28,17 @@
  * @version $Rev:$ $Date:$
  */
 public interface GlobalClassLoaderRegister {
-    void register(GlobalClassLoader classLoader);
+    void register(ConfigurationClassLoaderExtension classLoader);
     
-    void unregister(GlobalClassLoader classLoader);
+    void unregister(ConfigurationClassLoaderExtension classLoader);
 
-    GlobalClassLoader retrieve(Artifact artifact);
+    ConfigurationClassLoaderExtension retrieve(Artifact artifact);
 
-    void register(Artifact child, Set<Artifact> parents);
+    void register(Artifact child, Set<Artifact> parents, Artifact docSourceArtifact);
 
     void unregister(Artifact artifact);
 
     Set<Artifact> getParents(Artifact artifact);
+
+    void cleanClassLoaderRegistry();
 }

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MavenDependencyResolver.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MavenDependencyResolver.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MavenDependencyResolver.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MavenDependencyResolver.java
Wed Apr 22 18:52:43 2009
@@ -31,6 +31,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.SAXException;
+import org.apache.geronimo.kernel.repository.Artifact;
 
 /**
  * Given a URL to an artifact in a maven repo, say <base>.jar, attempts to read dependencies
out of
@@ -41,11 +42,11 @@
 public class MavenDependencyResolver implements GlobalClassLoaderDependencyResolver {
     private static final Logger log = LoggerFactory.getLogger(MavenDependencyResolver.class);
 
-    public void resolve(URL url, GlobalClassLoaderRegister register) {
+    public void resolve(URL url, GlobalClassLoaderRegister register, Artifact docSourceArtifact)
{
         try {
             InputStream in = locateDependencyDeclaration(url);
             try {
-                addDependencies(register, in);
+                addDependencies(register, in, docSourceArtifact);
             } finally {
                 in.close();
             }
@@ -55,11 +56,11 @@
 
     }
 
-    void addDependencies(GlobalClassLoaderRegister register, InputStream dependencyDeclaration)
{
+    void addDependencies(GlobalClassLoaderRegister register, InputStream dependencyDeclaration,
Artifact docSourceArtifact) {
         SAXParserFactory factory = SAXParserFactory.newInstance();
         try {
             SAXParser parser = factory.newSAXParser();
-            parser.parse(dependencyDeclaration, new DependencySAXHandler(register));
+            parser.parse(dependencyDeclaration, new DependencySAXHandler(register, docSourceArtifact));
         } catch (NullPointerException e) {
             log.error("error parsing " + dependencyDeclaration, e);
         } catch (SAXException e) {

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MultiParentClassLoader2.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MultiParentClassLoader2.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MultiParentClassLoader2.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/MultiParentClassLoader2.java
Wed Apr 22 18:52:43 2009
@@ -29,7 +29,6 @@
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -97,13 +96,14 @@
 
     //jars "in" this classloader.  These classloaders cannot affect the visibility of contained
classes.  The classloading rule inverseclassloading
     //determines whether the parents or these classloaders are searched first.
-    private final Set<GlobalClassLoader> classloaders;
+    private final Set<ConfigurationClassLoaderExtension> classloaders;
 
     public MultiParentClassLoader2(Artifact id,
-                                   Set<GlobalClassLoader> globalClassLoaders,
+                                   URL[] urls,
+                                   Set<ConfigurationClassLoaderExtension> globalClassLoaders,
                                    ClassLoader[] parents,
                                    ClassLoadingRules classLoadingRules) {
-        super(new URL[0]);
+        super(urls);
         this.id = id;
         this.classloaders = globalClassLoaders;
         this.parents = parents;
@@ -278,7 +278,7 @@
         //
         if (!isHiddenClass(name)) {
             try {
-                LinkedList<ClassLoader> visitedClassLoaders = new LinkedList<ClassLoader>();
+                LinkedList<ConfigurationClassLoaderExtension> visitedClassLoaders =
new LinkedList<ConfigurationClassLoaderExtension>();
                 Class clazz = checkParents(name, resolve, visitedClassLoaders);
                 if (clazz != null) return resolveClass(clazz, resolve);
             } catch (ClassNotFoundException cnfe) {
@@ -305,21 +305,25 @@
 
     @Override
     protected Class<?> findClass(String name) throws ClassNotFoundException {
-        LinkedList<ClassLoader> visitedClassLoaders = new LinkedList<ClassLoader>();
+        LinkedList<ConfigurationClassLoaderExtension> visitedClassLoaders = new LinkedList<ConfigurationClassLoaderExtension>();
         return findClass(name, visitedClassLoaders);
     }
 
-    protected Class<?> findClass(String name, List<ClassLoader> visitedClassLoaders)
throws ClassNotFoundException {
-        for (GlobalClassLoader classLoader : classloaders) {
+    protected Class<?> findClass(String name, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException {
+        for (ConfigurationClassLoaderExtension classLoader : classloaders) {
             if (!visitedClassLoaders.contains(classLoader)) {
                 visitedClassLoaders.add(classLoader);
                 try {
-                    return classLoader.loadClass(name, visitedClassLoaders);
+                    Class clazz = classLoader.loadClassInternal(name, true, visitedClassLoaders);
+                    if (clazz != null) return clazz;
                 } catch (ClassNotFoundException e) {
+                    //ignore
+                } catch (MalformedURLException e) {
+                    //ignore
                 }
             }
         }
-        throw new ClassNotFoundException();
+        return super.findClass(name);
     }
 
     /**
@@ -333,7 +337,7 @@
      * @return
      * @throws ClassNotFoundException
      */
-    public synchronized Class<?> loadClassInternal(String name, boolean resolve, List<ClassLoader>
visitedClassLoaders) throws ClassNotFoundException, MalformedURLException {
+    public synchronized Class<?> loadClassInternal(String name, boolean resolve, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException, MalformedURLException {
         //
         // Check if class is in the loaded classes cache
         //
@@ -380,16 +384,19 @@
      * @return
      * @throws ClassNotFoundException
      */
-    private synchronized Class<?> checkParents(String name, boolean resolve, List<ClassLoader>
visitedClassLoaders) throws ClassNotFoundException {
+    private synchronized Class<?> checkParents(String name, boolean resolve, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException {
         for (ClassLoader parent : parents) {
             if (!visitedClassLoaders.contains(parent)) {
-                visitedClassLoaders.add(parent);  // Track that we've been here before
+                //TODO inefficient
+                if (parent instanceof ConfigurationClassLoaderExtension) {
+                    visitedClassLoaders.add((ConfigurationClassLoaderExtension) parent);
 // Track that we've been here before
+                }
                 try {
                     if (parent instanceof MultiParentClassLoader2) {
                         Class clazz = ((MultiParentClassLoader2) parent).loadClassInternal(name,
resolve, visitedClassLoaders);
                         if (clazz != null) return resolveClass(clazz, resolve);
                     } else if (parent instanceof ChildrenConfigurationClassLoader) {
-                        Class clazz = ((ChildrenConfigurationClassLoader) parent).loadClass(name,
visitedClassLoaders);
+                        Class clazz = ((ChildrenConfigurationClassLoader) parent).loadClassInternal(name,
resolve, visitedClassLoaders);
                         if (clazz != null) return resolveClass(clazz, resolve);
                     } else {
                         return parent.loadClass(name);
@@ -475,8 +482,12 @@
 
     @Override
     public URL findResource(String name) {
-        for (URLClassLoader classLoader : classloaders) {
-            URL url = classLoader.findResource(name);
+        URL url = super.findResource(name);
+        if (url != null) {
+            return url;
+        }
+        for (ConfigurationClassLoaderExtension classLoader : classloaders) {
+            url = ((ConfigurationClassLoaderExtension)classLoader).findResource(name);
             if (null != url) {
                 return url;
             }
@@ -523,23 +534,12 @@
     }
 
     protected Enumeration<URL> internalfindResources(String name) throws IOException
{
-        Set<URL> resources = new HashSet<URL>();
-        for (URLClassLoader classLoader : classloaders) {
-            Enumeration<URL> findResources = classLoader.findResources(name);
-            while (findResources.hasMoreElements()) {
-                resources.add(findResources.nextElement());
-            }
+        List<Enumeration<URL>> urls = new ArrayList<Enumeration<URL>>();
+        urls.add(super.findResources(name));
+        for (ConfigurationClassLoaderExtension classLoader : classloaders) {
+            urls.add(classLoader.findResources(name));
         }
-        final Iterator<URL> iterator = resources.iterator();
-        return new Enumeration<URL>() {
-            public boolean hasMoreElements() {
-                return iterator.hasNext();
-            }
-
-            public URL nextElement() {
-                return iterator.next();
-            }
-        };
+        return new UnionEnumeration<URL>(urls);
     }
 
     private boolean isNonOverridableResource(String name) {

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/OneClassLoaderPerJarClassLoaderBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/OneClassLoaderPerJarClassLoaderBuilder.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/OneClassLoaderPerJarClassLoaderBuilder.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/classloading/OneClassLoaderPerJarClassLoaderBuilder.java
Wed Apr 22 18:52:43 2009
@@ -26,45 +26,60 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Enumeration;
+import java.io.IOException;
 
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.ClassLoadingRules;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.MissingDependencyException;
 import org.apache.geronimo.kernel.config.ConfigurationResolver;
+import org.apache.geronimo.kernel.config.ChildrenConfigurationClassLoader;
+import org.apache.geronimo.kernel.config.ClassLoaderHolder;
 
 /**
- *
  * @version $Rev:$ $Date:$
  */
 public class OneClassLoaderPerJarClassLoaderBuilder {
     public static final GlobalClassLoaderRegister GLOBAL_CL_REGISTER = new BasicGlobalClassLoaderRegister();
 
-    public ClassLoader build(Environment environment,
-            List<ClassLoader> parentClassLoaders,
-            ClassLoadingRules classLoadingRules,
-            LinkedHashMap<Artifact, URL[]> artifactToURL,
-            ConfigurationResolver configurationResolver) throws MissingDependencyException,
MalformedURLException {
-        Set<GlobalClassLoader> globalClassLoaders = retrieveGlobalClassLoaders(environment.getConfigId(),
artifactToURL, configurationResolver);
-        return new MultiParentClassLoader2(environment.getConfigId(),
+    public ClassLoaderHolder build(Environment environment,
+                             List<ClassLoader> parentClassLoaders,
+                             ClassLoadingRules classLoadingRules,
+                             LinkedHashMap<Artifact, URL[]> dependencyUrls,
+                             URL[] resolvedClassPath,
+                             ConfigurationResolver configurationResolver) throws MissingDependencyException,
MalformedURLException {
+        Set<ConfigurationClassLoaderExtension> globalClassLoaders = retrieveGlobalClassLoaders(environment.getConfigId(),
dependencyUrls, configurationResolver);
+        ClassLoader configurationClassLoader = new MultiParentClassLoader2(environment.getConfigId(),
+                resolvedClassPath,
                 globalClassLoaders,
                 parentClassLoaders.toArray(new ClassLoader[parentClassLoaders.size()]),
                 classLoadingRules);
+
+        ClassLoadingRules rules = environment.getClassLoadingRules();
+        ChildrenConfigurationClassLoader childrenConfigurationClassLoader = new ChildrenConfigurationClassLoader(configurationClassLoader,
rules);
+        GLOBAL_CL_REGISTER.register(childrenConfigurationClassLoader);
+
+        return new ClassLoaderHolder(configurationClassLoader, childrenConfigurationClassLoader);
+    }
+
+    public static void unregister(ConfigurationClassLoaderExtension classLoader) {
+        GLOBAL_CL_REGISTER.unregister(classLoader);
     }
 
-    protected Set<GlobalClassLoader> retrieveGlobalClassLoaders(Artifact configId,
LinkedHashMap<Artifact, URL[]> urls, ConfigurationResolver configurationResolver) throws
MissingDependencyException, MalformedURLException {
-        Set<GlobalClassLoader> classloaders = new HashSet<GlobalClassLoader>();
+    protected Set<ConfigurationClassLoaderExtension> retrieveGlobalClassLoaders(Artifact
configId, LinkedHashMap<Artifact, URL[]> urls, ConfigurationResolver configurationResolver)
throws MissingDependencyException, MalformedURLException {
+        Set<ConfigurationClassLoaderExtension> classloaders = new HashSet<ConfigurationClassLoaderExtension>();
         URL artifactURL;
         try {
             artifactURL = configurationResolver.resolve(configId).toURL();
-            new MavenDependencyResolver().resolve(artifactURL, GLOBAL_CL_REGISTER);
+            new MavenDependencyResolver().resolve(artifactURL, GLOBAL_CL_REGISTER, configId);
         } catch (MissingDependencyException e) {
             //bootstrap configuration
         }
         for (Map.Entry<Artifact, URL[]> entry : urls.entrySet()) {
             Artifact artifact = entry.getKey();
             URL[] entryURLs = entry.getValue();
-            GlobalClassLoader classLoader;
+            ConfigurationClassLoaderExtension classLoader;
             synchronized (GLOBAL_CL_REGISTER) {
                 classLoader = GLOBAL_CL_REGISTER.retrieve(artifact);
                 if (null == classLoader) {
@@ -76,27 +91,52 @@
         return classloaders;
     }
 
-    protected GlobalClassLoader newGlobalClassLoader(Artifact artifact, URL[] urls, ConfigurationResolver
configurationResolver) throws MissingDependencyException, MalformedURLException {
+    protected ConfigurationClassLoaderExtension newGlobalClassLoader(Artifact artifact, URL[]
urls, ConfigurationResolver configurationResolver) throws MissingDependencyException, MalformedURLException
{
         Set<Artifact> parents;
         try {
             parents = GLOBAL_CL_REGISTER.getParents(artifact);
         } catch (NullPointerException e) {
             throw new MissingDependencyException("Unregistered artifact", null, artifact);
         }
-        ClassLoader[] classLoaders;
+        ConfigurationClassLoaderExtension[] classLoaders;
         if (parents != null && !parents.isEmpty()) {
-            classLoaders = new ClassLoader[parents.size()];
+            classLoaders = new ConfigurationClassLoaderExtension[parents.size()];
             int i = 0;
-            for (Artifact parent: parents) {
-                GlobalClassLoader cl = GLOBAL_CL_REGISTER.retrieve(parent);
+            for (Artifact parent : parents) {
+                ConfigurationClassLoaderExtension cl = GLOBAL_CL_REGISTER.retrieve(parent);
                 if (cl == null) {
                     URL url = configurationResolver.resolve(parent).toURL();
-                    cl = newGlobalClassLoader(parent, new URL[] {url}, configurationResolver);
+                    cl = newGlobalClassLoader(parent, new URL[]{url}, configurationResolver);
                 }
                 classLoaders[i++] = cl;
             }
         } else {
-            classLoaders = new ClassLoader[] {getClass().getClassLoader()};
+            final ClassLoader root = getClass().getClassLoader();
+            classLoaders = new ConfigurationClassLoaderExtension[]{new ConfigurationClassLoaderExtension()
{
+                public void addURL(URL url) {
+                }
+
+                public Class<?> loadClassInternal(String name, boolean resolve, List<ConfigurationClassLoaderExtension>
visitedClassLoaders) throws ClassNotFoundException, MalformedURLException {
+                    visitedClassLoaders.add(this);
+                    return root.loadClass(name);
+                }
+
+                public void destroy() {
+                }
+
+                public URL findResource(String name) {
+                    return root.getResource(name);
+                }
+
+                public Enumeration<URL> findResources(String name) throws IOException
{
+                    return root.getResources(name);
+                }
+
+                public Artifact getId() {
+                    return null;
+                }
+            }
+            };
         }
         GlobalClassLoader cl = new GlobalClassLoader(artifact, urls, classLoaders);
         GLOBAL_CL_REGISTER.register(cl);

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/classloading/DependencyResolverTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/classloading/DependencyResolverTest.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/classloading/DependencyResolverTest.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/classloading/DependencyResolverTest.java
Wed Apr 22 18:52:43 2009
@@ -355,7 +355,7 @@
         MavenDependencyResolver resolver = new MavenDependencyResolver();
         InputStream in = new StringBufferInputStream(DOC);
         BasicGlobalClassLoaderRegister register = new BasicGlobalClassLoaderRegister();
-        resolver.addDependencies(register, in);
+        resolver.addDependencies(register, in, null);
         int size = register.graph.size();
 
     }

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/sharedlib/SharedLib.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/sharedlib/SharedLib.java?rev=767617&r1=767616&r2=767617&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/sharedlib/SharedLib.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/sharedlib/SharedLib.java
Wed Apr 22 18:52:43 2009
@@ -42,6 +42,7 @@
     }
 
     private SharedLib(ClassLoader classLoader, String[] classesDirs, String[] libDirs, ServerInfo
serverInfo) throws MalformedURLException {
+        if (classLoader instanceof MultiParentClassLoader){
         MultiParentClassLoader multiParentClassLoader = (MultiParentClassLoader) classLoader;
         Set currentUrls = new HashSet(Arrays.asList(multiParentClassLoader.getURLs()));
 
@@ -99,6 +100,7 @@
             URL url = (URL) iterator.next();
             multiParentClassLoader.addURL(url);
         }
+        }
     }
 
     public static final GBeanInfo GBEAN_INFO;



Mime
View raw message