maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r633431 - in /maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime: ChildDelegatingClassLoader.java DefaultMavenRuntimeTest.java DelegatingClassLoader.java
Date Tue, 04 Mar 2008 11:27:31 GMT
Author: markh
Date: Tue Mar  4 03:27:26 2008
New Revision: 633431

URL: http://svn.apache.org/viewvc?rev=633431&view=rev
Log:
Simplified test class loaders

Added:
    maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DelegatingClassLoader.java
      - copied, changed from r633416, maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/ChildDelegatingClassLoader.java
Removed:
    maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/ChildDelegatingClassLoader.java
Modified:
    maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DefaultMavenRuntimeTest.java

Modified: maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DefaultMavenRuntimeTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DefaultMavenRuntimeTest.java?rev=633431&r1=633430&r2=633431&view=diff
==============================================================================
--- maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DefaultMavenRuntimeTest.java
(original)
+++ maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DefaultMavenRuntimeTest.java
Tue Mar  4 03:27:26 2008
@@ -788,18 +788,7 @@
             urls[i] = files[i].toURI().toURL();
         }
 
-        URLClassLoader classLoader;
-
-        if ( childDelegation )
-        {
-            classLoader = new ChildDelegatingClassLoader( urls, parent );
-        }
-        else
-        {
-            classLoader = new URLClassLoader( urls, parent );
-        }
-
-        return classLoader;
+        return new DelegatingClassLoader( urls, parent, childDelegation );
     }
     
     private void close( URLClassLoader classLoader ) throws IOException

Copied: maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DelegatingClassLoader.java
(from r633416, maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/ChildDelegatingClassLoader.java)
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DelegatingClassLoader.java?p2=maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DelegatingClassLoader.java&p1=maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/ChildDelegatingClassLoader.java&r1=633416&r2=633431&rev=633431&view=diff
==============================================================================
--- maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/ChildDelegatingClassLoader.java
(original)
+++ maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/DelegatingClassLoader.java
Tue Mar  4 03:27:26 2008
@@ -25,79 +25,119 @@
 import java.util.Enumeration;
 
 /**
- * A child-delegating class loader for use by tests.
+ * A parent- or child-delegating class loader for use by tests.
  * 
  * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
  * @version $Id$
  */
-public class ChildDelegatingClassLoader extends URLClassLoader
+public class DelegatingClassLoader extends URLClassLoader
 {
+    // fields -----------------------------------------------------------------
+
+    private final boolean childDelegating;
+
     // constructors -----------------------------------------------------------
-    
-    public ChildDelegatingClassLoader(URL[] urls)
+
+    public DelegatingClassLoader( URL[] urls )
     {
-        super(urls);
+        super( urls );
+
+        childDelegating = false;
     }
-    
-    public ChildDelegatingClassLoader(URL[] urls, ClassLoader parent)
+
+    public DelegatingClassLoader( URL[] urls, ClassLoader parent )
     {
-        super(urls, parent);
+        this( urls, parent, false );
+    }
+
+    public DelegatingClassLoader( URL[] urls, ClassLoader parent, boolean childDelegating
)
+    {
+        super( urls, parent );
+
+        this.childDelegating = childDelegating;
     }
-    
+
     // ClassLoader methods ----------------------------------------------------
-    
+
     /**
      * {@inheritDoc}
      */
     public Class loadClass( String name ) throws ClassNotFoundException
     {
-        Class klass = findLoadedClass( name );
-        
-        if ( klass == null )
+        Class klass;
+
+        if ( childDelegating )
         {
-            try
-            {
-                klass = findClass( name );
-            }
-            catch ( ClassNotFoundException exception )
+            klass = findLoadedClass( name );
+
+            if ( klass == null )
             {
-                if ( getParent() != null)
+                try
+                {
+                    klass = findClass( name );
+                }
+                catch ( ClassNotFoundException exception )
                 {
-                    klass = getParent().loadClass( name );
+                    if ( getParent() != null )
+                    {
+                        klass = getParent().loadClass( name );
+                    }
                 }
             }
         }
-        
+        else
+        {
+            klass = super.loadClass( name );
+        }
+
         return klass;
     }
-    
+
     /**
      * {@inheritDoc}
      */
     public URL getResource( String name )
     {
-        URL url = findResource( name );
-        
-        if ( url == null && getParent() != null )
+        URL url;
+
+        if ( childDelegating )
         {
-            url = getParent().getResource( name );
+            url = findResource( name );
+
+            if ( url == null && getParent() != null )
+            {
+                url = getParent().getResource( name );
+            }
         }
-        
+        else
+        {
+            url = super.getResource( name );
+        }
+
         return url;
     }
-    
+
     /**
      * {@inheritDoc}
      */
     public Enumeration getResources( String name ) throws IOException
     {
-        Enumeration urls = findResources( name );
+        Enumeration urls;
 
-        if ( getParent() != null )
+        if ( childDelegating )
         {
-            Enumeration parentURLs = getParent().getResources( name );
+            urls = findResources( name );
+
+            if ( getParent() != null )
+            {
+                Enumeration parentURLs = getParent().getResources( name );
 
-            urls = new CompoundEnumeration( urls, parentURLs );
+                urls = new CompoundEnumeration( urls, parentURLs );
+            }
+        }
+        else
+        {
+            urls = super.getResources( name );
         }
 
         return urls;



Mime
View raw message