geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1326261 - in /geronimo/xbean/trunk/xbean-finder/src: main/java/org/apache/xbean/finder/ main/java/org/apache/xbean/finder/archive/ test/java/org/apache/xbean/finder/archive/
Date Sun, 15 Apr 2012 06:52:41 GMT
Author: dblevins
Date: Sun Apr 15 06:52:40 2012
New Revision: 1326261

URL: http://svn.apache.org/viewvc?rev=1326261&view=rev
Log:
XBEAN-205: JarArchive and Archive API reworked for greater performance

Added:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ArchiveIterator.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeJarArchiveTest.java
      - copied, changed from r1326253, geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java
Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/Archive.java
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/BundleArchive.java
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ClassesArchive.java
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/CompositeArchive.java
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FilteredArchive.java
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/JarArchive.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/Archives.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/ClassesArchiveTest.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FilteredArchiveTest.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/JarArchiveTest.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/MockArchive.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
Sun Apr 15 06:52:40 2012
@@ -32,6 +32,7 @@ import org.objectweb.asm.Type;
 import org.objectweb.asm.commons.EmptyVisitor;
 import org.objectweb.asm.signature.SignatureVisitor;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
@@ -110,6 +111,10 @@ public class AnnotationFinder implements
         }
     }
 
+    public boolean hasMetaAnnotations() {
+        return metaroots.size() > 0;
+    }
+
     private void readClassDef(ClassInfo info) {
         classInfos.put(info.name, info);
         index(info);
@@ -151,13 +156,12 @@ public class AnnotationFinder implements
     public AnnotationFinder(Archive archive) {
         this.archive = archive;
 
-        for (String className : this.archive) {
+        for (Archive.Entry entry : archive) {
+            final String className = entry.getName();
             try {
-                readClassDef(archive.getBytecode(className));
+                readClassDef(entry.getBytecode());
             } catch (NoClassDefFoundError e) {
                 throw new NoClassDefFoundError("Could not fully load class: " + className
+ "\n due to:" + e.getMessage());
-            } catch (ClassNotFoundException e) {
-                e.printStackTrace();
             } catch (IOException e) {
                 e.printStackTrace();
             }
@@ -997,15 +1001,17 @@ public class AnnotationFinder implements
     }
 
     public class SubArchive implements Archive {
-        private List<String> classes = new ArrayList<String>();
+        private List<Entry> classes = new ArrayList<Entry>();
 
         public SubArchive(String... classes) {
-            Collections.addAll(this.classes, classes);
+            for (String name : classes) {
+                this.classes.add(new E(name));
+            }
         }
 
         public SubArchive(Iterable<String> classes) {
             for (String name : classes) {
-                this.classes.add(name);
+                this.classes.add(new E(name));
             }
         }
 
@@ -1017,9 +1023,25 @@ public class AnnotationFinder implements
             return archive.loadClass(className);
         }
 
-        public Iterator<String> iterator() {
+        public Iterator<Entry> iterator() {
             return classes.iterator();
         }
+
+        public class E implements Entry {
+            private final String name;
+
+            public E(String name) {
+                this.name = name;
+            }
+
+            public String getName() {
+                return name;
+            }
+
+            public InputStream getBytecode() throws IOException {
+                return new ByteArrayInputStream(new byte[0]);
+            }
+        }
     }
 
     public class Annotatable {

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/Archive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/Archive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/Archive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/Archive.java
Sun Apr 15 06:52:40 2012
@@ -22,10 +22,14 @@ import java.io.InputStream;
 /**
  * @version $Rev$ $Date$
  */
-public interface Archive extends Iterable<String> {
+public interface Archive extends Iterable<Archive.Entry> {
 
     InputStream getBytecode(String className) throws IOException, ClassNotFoundException;
 
     Class<?> loadClass(String className) throws ClassNotFoundException;
 
+    public interface Entry {
+        String getName();
+        InputStream getBytecode() throws IOException;
+    }
 }

Added: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ArchiveIterator.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ArchiveIterator.java?rev=1326261&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ArchiveIterator.java
(added)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ArchiveIterator.java
Sun Apr 15 06:52:40 2012
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+package org.apache.xbean.finder.archive;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class ArchiveIterator implements Iterator<Archive.Entry> {
+    private final Iterator<String> classes;
+    private final Archive archive;
+
+    public ArchiveIterator(Archive archive, Iterator<String> classes) {
+        this.archive = archive;
+        this.classes = classes;
+    }
+
+    public boolean hasNext() {
+        return classes.hasNext();
+    }
+
+    public Archive.Entry next() {
+        final String name = classes.next();
+        return new Archive.Entry() {
+            public String getName() {
+                return name;
+            }
+
+            public InputStream getBytecode() throws IOException {
+                try {
+                    return archive.getBytecode(name);
+                } catch (ClassNotFoundException e) {
+                    throw new IOException(e);
+                }
+            }
+        };
+    }
+
+    public void remove() {
+        classes.remove();
+    }
+}

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/BundleArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/BundleArchive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/BundleArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/BundleArchive.java
Sun Apr 15 06:52:40 2012
@@ -46,8 +46,7 @@ public class BundleArchive implements Ar
         bundleResourceFinder.find(new AnnotationFindingCallback());
     }
 
-    public Iterator<String> iterator() {
-        // TODO
+    public Iterator<Entry> iterator() {
         return Collections.EMPTY_LIST.iterator();
     }
 

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ClassesArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ClassesArchive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ClassesArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/ClassesArchive.java
Sun Apr 15 06:52:40 2012
@@ -50,8 +50,8 @@ public class ClassesArchive implements A
         }
     }
 
-    public Iterator<String> iterator() {
-        return classes.keySet().iterator();
+    public Iterator<Entry> iterator() {
+        return new ArchiveIterator(this, classes.keySet().iterator());
     }
 
     public InputStream getBytecode(String className) throws IOException, ClassNotFoundException
{
@@ -89,4 +89,5 @@ public class ClassesArchive implements A
 
         throw new ClassNotFoundException(className);
     }
+
 }

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/CompositeArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/CompositeArchive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/CompositeArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/CompositeArchive.java
Sun Apr 15 06:52:40 2012
@@ -63,14 +63,15 @@ public class CompositeArchive implements
         throw new ClassNotFoundException(className);
     }
 
-    public Iterator<String> iterator() {
+    public Iterator<Entry> iterator() {
+        if (archives.size() == 1) return archives.get(0).iterator();
         return new CompositeIterator(archives);
     }
 
-    private static class CompositeIterator implements Iterator<String> {
+    private static class CompositeIterator implements Iterator<Entry> {
 
         private Iterator<Archive> archives;
-        private Iterator<String> current;
+        private Iterator<Entry> current;
 
         private CompositeIterator(Iterable<Archive> archives) {
             this.archives = archives.iterator();
@@ -90,7 +91,7 @@ public class CompositeArchive implements
             return false;
         }
 
-        public String next() {
+        public Entry next() {
             if (!hasNext()) throw new NoSuchElementException();
 
             return current.next();

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
Sun Apr 15 06:52:40 2012
@@ -73,7 +73,11 @@ public class FileArchive implements Arch
         return loader.loadClass(className);
     }
 
-    public Iterator<String> iterator() {
+    public Iterator<Entry> iterator() {
+        return new ArchiveIterator(this, _iterator());
+    }
+
+    public Iterator<String> _iterator() {
         if (list != null) return list.iterator();
 
         list = file(dir);

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FilteredArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FilteredArchive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FilteredArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FilteredArchive.java
Sun Apr 15 06:52:40 2012
@@ -45,16 +45,16 @@ public class FilteredArchive implements 
         return archive.loadClass(className);
     }
 
-    public Iterator<String> iterator() {
+    public Iterator<Entry> iterator() {
         return new FilteredIterator(archive.iterator());
     }
 
-    private final class FilteredIterator implements Iterator<String> {
-        private final Iterator<String> it;
+    private final class FilteredIterator implements Iterator<Entry> {
+        private final Iterator<Entry> it;
 
-        private String next;
+        private Entry next;
 
-        private FilteredIterator(Iterator<String> it) {
+        private FilteredIterator(Iterator<Entry> it) {
             this.it = it;
         }
 
@@ -65,10 +65,10 @@ public class FilteredArchive implements 
             return hasNext();
         }
 
-        public String next() {
+        public Entry next() {
             if (!hasNext()) throw new NoSuchElementException();
 
-            String s = next;
+            Entry s = next;
             next = null;
 
             return s;
@@ -83,7 +83,7 @@ public class FilteredArchive implements 
 
                 next = it.next();
 
-                if (filter.accept(next)) return;
+                if (filter.accept(next.getName())) return;
 
                 next = null;
             }

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/JarArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/JarArchive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/JarArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/JarArchive.java
Sun Apr 15 06:52:40 2012
@@ -17,6 +17,7 @@
 package org.apache.xbean.finder.archive;
 
 import java.io.BufferedInputStream;
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -24,6 +25,7 @@ import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
@@ -38,7 +40,7 @@ public class JarArchive implements Archi
     private List<String> list;
 
     public JarArchive(ClassLoader loader, URL url) {
-        if (!"jar".equals(url.getProtocol())) throw new IllegalArgumentException("not a jar
url: " + url);
+//        if (!"jar".equals(url.getProtocol())) throw new IllegalArgumentException("not a
jar url: " + url);
         this.loader = loader;
         this.url = url;
     }
@@ -71,71 +73,103 @@ public class JarArchive implements Archi
         return loader.loadClass(className);
     }
 
-    public Iterator<String> iterator() {
-        if (list != null) return list.iterator();
-
-        try {
-            list = jar(url);
-            return list.iterator();
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
+    public Iterator<Entry> iterator() {
+        return new JarIterator();
     }
 
-    private List<String> jar(URL location) throws IOException {
-        String jarPath = location.getFile();
-        if (jarPath.indexOf("!") > -1){
-            jarPath = jarPath.substring(0, jarPath.indexOf("!"));
-        }
-        URL url = new URL(jarPath);
-        if ("file".equals(url.getProtocol())) { // ZipFile is faster than ZipInputStream
-            JarFile jarFile = new JarFile(url.getFile().replace("%20", " "));
-            return jar(jarFile);
-        } else {
-            InputStream in = url.openStream();
+    private class JarIterator implements Iterator<Entry> {
+
+        private final JarInputStream stream;
+        private final NonClosable nonClosable;
+        private Entry next;
+
+        private JarIterator() {
             try {
-                JarInputStream jarStream = new JarInputStream(in);
-                return jar(jarStream);
-            } finally {
-                in.close();
+                URL u = url;
+
+                String jarPath = url.getFile();
+                if (jarPath.contains("!")){
+                    jarPath = jarPath.substring(0, jarPath.indexOf("!"));
+                    u = new URL(jarPath);
+                }
+                InputStream in = u.openStream();
+                in = new BufferedInputStream(in, 1024 * 50);
+                stream = new JarInputStream(in);
+                nonClosable = new NonClosable(stream);
+            } catch (IOException e) {
+                throw new IllegalStateException(e);
             }
         }
-    }
 
-    private List<String> jar(JarFile jarFile) {
-        List<String> classNames = new ArrayList<String>();
+        private boolean advance() {
+            if (next != null) return true;
+
+            try {
+                final JarEntry entry = stream.getNextJarEntry();
+
+                if (entry == null) {
+                    next = null;
+                    return false;
+                }
+
+                if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
+                    return advance();
+                }
+
+                final String className = entry.getName().replaceFirst(".class$", "");
+
+                if (className.contains(".")) {
+                    return advance();
+                }
+
+                next = new ClassEntry(className.replace('/', '.'));
 
-        Enumeration<? extends JarEntry> jarEntries =jarFile.entries();
-        while (jarEntries.hasMoreElements()) {
-            JarEntry entry = jarEntries.nextElement();
-            addClassName(classNames, entry);
+                return true;
+            } catch (IOException e) {
+                throw new IllegalStateException(e);
+            }
         }
 
-        return classNames;
-    }
+        public boolean hasNext() {
+            return advance();
+        }
 
-    private List<String> jar(JarInputStream jarStream) throws IOException {
-        List<String> classNames = new ArrayList<String>();
+        public Entry next() {
+            if (!hasNext()) throw new NoSuchElementException();
+            Entry entry = next;
+            next = null;
+            return entry;
+        }
 
-        JarEntry entry;
-        while ((entry = jarStream.getNextJarEntry()) != null) {
-            addClassName(classNames, entry);
+        public void remove() {
+            throw new UnsupportedOperationException("remove");
         }
 
-        return classNames;
+        private class ClassEntry implements Entry {
+            private final String name;
+
+            private ClassEntry(String name) {
+                this.name = name;
+            }
+
+            public String getName() {
+                return name;
+            }
+
+            public InputStream getBytecode() throws IOException {
+                return nonClosable;
+            }
+        }
     }
 
-    private void addClassName(List<String> classNames, JarEntry entry) {
-        if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
-            return;
+    public static class NonClosable extends FilterInputStream {
+        public NonClosable(InputStream in) {
+            super(in);
         }
-        String className = entry.getName();
-        className = className.replaceFirst(".class$", "");
-        if (className.contains(".")) {
-            return;
+
+        @Override
+        public void close() throws IOException {
         }
-        className = className.replace('/', '.');
-        classNames.add(className);
     }
 }
 

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/Archives.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/Archives.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/Archives.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/Archives.java
Sun Apr 15 06:52:40 2012
@@ -93,7 +93,7 @@ public class Archives {
         return classpath;
     }
 
-    public static File jarArchive(Class[] classes) throws IOException {
+    public static File jarArchive(Class... classes) throws IOException {
         return jarArchive(new HashMap<String, String>(), classes);
     }
 

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/ClassesArchiveTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/ClassesArchiveTest.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/ClassesArchiveTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/ClassesArchiveTest.java
Sun Apr 15 06:52:40 2012
@@ -61,8 +61,8 @@ public class ClassesArchiveTest extends 
 
     public void testIterator() throws Exception {
         List<String> classes = new ArrayList<String>();
-        for (String classname : archive) {
-            classes.add(classname);
+        for (Archive.Entry entry : archive) {
+            classes.add(entry.getName());
         }
 
         assertFalse(0 == classes.size());

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java
Sun Apr 15 06:52:40 2012
@@ -65,8 +65,8 @@ public class CompositeArchiveTest extend
 
     public void testIterator() throws Exception {
         List<String> classes = new ArrayList<String>();
-        for (String classname : archive) {
-            classes.add(classname);
+        for (Archive.Entry entry : archive) {
+            classes.add(entry.getName());
         }
 
         assertFalse(0 == classes.size());

Copied: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeJarArchiveTest.java
(from r1326253, geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java)
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeJarArchiveTest.java?p2=geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeJarArchiveTest.java&p1=geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java&r1=1326253&r2=1326261&rev=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeArchiveTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/CompositeJarArchiveTest.java
Sun Apr 15 06:52:40 2012
@@ -17,22 +17,28 @@
 package org.apache.xbean.finder.archive;
 
 import junit.framework.TestCase;
+import org.apache.xbean.finder.filter.Filter;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * @version $Rev$ $Date$
  */
-public class CompositeArchiveTest extends TestCase {
+public class CompositeJarArchiveTest extends TestCase {
     private CompositeArchive archive;
     Class[] classes = {Blue.class, Green.class, Red.class};
 
     @Override
     protected void setUp() throws Exception {
+
+        final File one = Archives.jarArchive(Red.class, Green.class);
+        final File two = Archives.jarArchive(Blue.class);
+
         archive = new CompositeArchive(
-                new ClassesArchive(Red.class, Green.class),
-                new ClassesArchive(Blue.class)
+                new FilteredArchive(new CompositeArchive(new JarArchive(this.getClass().getClassLoader(),
one.toURI().toURL())), new MyFilter()),
+                new FilteredArchive(new CompositeArchive(new JarArchive(this.getClass().getClassLoader(),
two.toURI().toURL())), new MyFilter())
         );
     }
 
@@ -65,8 +71,8 @@ public class CompositeArchiveTest extend
 
     public void testIterator() throws Exception {
         List<String> classes = new ArrayList<String>();
-        for (String classname : archive) {
-            classes.add(classname);
+        for (Archive.Entry entry : archive) {
+            classes.add(entry.getName());
         }
 
         assertFalse(0 == classes.size());
@@ -86,4 +92,9 @@ public class CompositeArchiveTest extend
     public static class Blue {
     }
 
+    private static class MyFilter implements Filter {
+        public boolean accept(String name) {
+            return true;
+        }
+    }
 }

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
Sun Apr 15 06:52:40 2012
@@ -90,8 +90,8 @@ public class FileArchiveTest {
     @Test
     public void testIterator() throws Exception {
         List<String> actual = new ArrayList<String>();
-        for (String classname : archive) {
-            actual.add(classname);
+        for (Archive.Entry entry : archive) {
+            actual.add(entry.getName());
         }
 
         assertFalse(0 == actual.size());

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FilteredArchiveTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FilteredArchiveTest.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FilteredArchiveTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FilteredArchiveTest.java
Sun Apr 15 06:52:40 2012
@@ -49,13 +49,13 @@ public class FilteredArchiveTest extends
         assertEquals(0, list.size());
     }
 
-    public static void assertEquals(Iterable<?> expectedList, Iterable<?> actualList)
{
-        final Iterator<?> expected = expectedList.iterator();
-        final Iterator<?> actual = actualList.iterator();
+    public static void assertEquals(Iterable<Archive.Entry> expectedList, Iterable<Archive.Entry>
actualList) {
+        final Iterator<Archive.Entry> expected = expectedList.iterator();
+        final Iterator<Archive.Entry> actual = actualList.iterator();
 
         int i = 0;
         while (expected.hasNext() && actual.hasNext()) {
-            assertEquals(expected.next(), actual.next());
+            assertEquals(expected.next().getName(), actual.next().getName());
             i++;
         }
 
@@ -85,11 +85,11 @@ public class FilteredArchiveTest extends
         }
     }
 
-    public static <T> List<T> list(Iterable<T> iterable) {
-        List<T> list = new ArrayList<T>();
+    public static List<String> list(Iterable<Archive.Entry> iterable) {
+        List<String> list = new ArrayList<String>();
 
-        for (T t : iterable) {
-            list.add(t);
+        for (Archive.Entry t : iterable) {
+            list.add(t.getName());
         }
 
         return list;

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/JarArchiveTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/JarArchiveTest.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/JarArchiveTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/JarArchiveTest.java
Sun Apr 15 06:52:40 2012
@@ -91,8 +91,8 @@ public class JarArchiveTest {
     @Test
     public void testIterator() throws Exception {
         List<String> actual = new ArrayList<String>();
-        for (String classname : archive) {
-            actual.add(classname);
+        for (Archive.Entry entry : archive) {
+            actual.add(entry.getName());
         }
 
         assertFalse(0 == actual.size());

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/MockArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/MockArchive.java?rev=1326261&r1=1326260&r2=1326261&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/MockArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/MockArchive.java
Sun Apr 15 06:52:40 2012
@@ -49,8 +49,8 @@ public class MockArchive implements Arch
         return null;
     }
 
-    public Iterator<String> iterator() {
-        return list.iterator();
+    public Iterator<Entry> iterator() {
+        return new ArchiveIterator(this, list.iterator());
     }
 
 }



Mime
View raw message