You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ma...@apache.org on 2008/03/04 11:29:36 UTC

svn commit: r633416 - in /maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime: ChildDelegatingClassLoader.java CompoundEnumeration.java

Author: markh
Date: Tue Mar  4 02:29:25 2008
New Revision: 633416

URL: http://svn.apache.org/viewvc?rev=633416&view=rev
Log:
Also delegate getResources correctly

Added:
    maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/CompoundEnumeration.java   (with props)
Modified:
    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/ChildDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/ChildDelegatingClassLoader.java?rev=633416&r1=633415&r2=633416&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/ChildDelegatingClassLoader.java Tue Mar  4 02:29:25 2008
@@ -19,8 +19,10 @@
  * under the License.
  */
 
+import java.io.IOException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Enumeration;
 
 /**
  * A child-delegating class loader for use by tests.
@@ -82,5 +84,22 @@
         }
         
         return url;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Enumeration getResources( String name ) throws IOException
+    {
+        Enumeration urls = findResources( name );
+
+        if ( getParent() != null )
+        {
+            Enumeration parentURLs = getParent().getResources( name );
+
+            urls = new CompoundEnumeration( urls, parentURLs );
+        }
+
+        return urls;
     }
 }

Added: maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/CompoundEnumeration.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/CompoundEnumeration.java?rev=633416&view=auto
==============================================================================
--- maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/CompoundEnumeration.java (added)
+++ maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/CompoundEnumeration.java Tue Mar  4 02:29:25 2008
@@ -0,0 +1,93 @@
+package org.apache.maven.shared.runtime;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * Enumeration that spans a series of other enumerations.
+ * 
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class CompoundEnumeration implements Enumeration
+{
+    // fields -------------------------------------------------------------
+
+    private final Iterator enumerations;
+
+    private Enumeration enumeration;
+
+    // constructors -------------------------------------------------------
+
+    public CompoundEnumeration( Enumeration enumeration1, Enumeration enumeration2 )
+    {
+        this( new Enumeration[] { enumeration1, enumeration2 } );
+    }
+
+    public CompoundEnumeration( Enumeration[] enumerations )
+    {
+        this( Arrays.asList( enumerations ) );
+    }
+
+    public CompoundEnumeration( List enumerations )
+    {
+        this.enumerations = enumerations.iterator();
+    }
+
+    // Enumeration methods ------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasMoreElements()
+    {
+        return ( enumeration != null && enumeration.hasMoreElements() ) || enumerations.hasNext();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object nextElement()
+    {
+        Object element;
+
+        if ( enumeration != null && enumeration.hasMoreElements() )
+        {
+            element = enumeration.nextElement();
+        }
+        else if ( enumerations.hasNext() )
+        {
+            enumeration = (Enumeration) enumerations.next();
+
+            element = enumeration.nextElement();
+        }
+        else
+        {
+            throw new NoSuchElementException();
+        }
+
+        return element;
+    }
+}

Propchange: maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/CompoundEnumeration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/shared/maven-runtime/src/test/java/org/apache/maven/shared/runtime/CompoundEnumeration.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"