geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1144600 - in /geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder: AbstractFinder.java BundleAnnotationFinder.java
Date Sat, 09 Jul 2011 06:13:25 GMT
Author: djencks
Date: Sat Jul  9 06:13:25 2011
New Revision: 1144600

URL: http://svn.apache.org/viewvc?rev=1144600&view=rev
Log:
GERONIMO-6043 start providing a way to filter which bits of bundle classpath we look at annotated
classes from

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

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AbstractFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AbstractFinder.java?rev=1144600&r1=1144599&r2=1144600&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AbstractFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AbstractFinder.java
Sat Jul  9 06:13:25 2011
@@ -27,7 +27,6 @@ import java.lang.reflect.AnnotatedElemen
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.lang.reflect.Type;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -41,7 +40,6 @@ import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.commons.EmptyVisitor;
-import org.objectweb.asm.signature.SignatureReader;
 import org.objectweb.asm.signature.SignatureVisitor;
 
 /**
@@ -577,8 +575,12 @@ public abstract class AbstractFinder imp
     }
 
     protected void readClassDef(InputStream in) throws IOException {
+        readClassDef(in, null);
+    }
+
+    protected void readClassDef(InputStream in, String path) throws IOException {
         ClassReader classReader = new ClassReader(in);
-        classReader.accept(new InfoBuildingVisitor(), ASM_FLAGS);
+        classReader.accept(new InfoBuildingVisitor(path), ASM_FLAGS);
     }
 
     protected void readClassDef(Class clazz) {
@@ -721,6 +723,8 @@ public abstract class AbstractFinder imp
         private final List<ClassInfo> subclassInfos = new SingleLinkedList<ClassInfo>();
         private final List<String> interfaces = new SingleLinkedList<String>();
         private final List<FieldInfo> fields = new SingleLinkedList<FieldInfo>();
+        //e.g. bundle class path prefix.
+        private String path;
         private Class<?> clazz;
 
         public ClassInfo(Class clazz) {
@@ -782,6 +786,10 @@ public abstract class AbstractFinder imp
         public String toString() {
             return name;
         }
+
+        public String getPath() {
+            return path;
+        }
     }
 
     public class MethodInfo extends Annotatable implements Info {
@@ -904,8 +912,10 @@ public abstract class AbstractFinder imp
 
     public class InfoBuildingVisitor extends EmptyVisitor {
         private Info info;
+        private String path;
 
-        public InfoBuildingVisitor() {
+        public InfoBuildingVisitor(String path) {
+            this.path = path;
         }
 
         public InfoBuildingVisitor(Info info) {
@@ -918,7 +928,7 @@ public abstract class AbstractFinder imp
                 info = new PackageInfo(javaName(name));
             } else {
                 ClassInfo classInfo = new ClassInfo(javaName(name), javaName(superName));
-
+                classInfo.path = path;
 //                if (signature == null) {
                     for (String interfce : interfaces) {
                         classInfo.getInterfaces().add(javaName(interfce));

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/BundleAnnotationFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/BundleAnnotationFinder.java?rev=1144600&r1=1144599&r2=1144600&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/BundleAnnotationFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/BundleAnnotationFinder.java
Sat Jul  9 06:13:25 2011
@@ -22,6 +22,11 @@ package org.apache.xbean.finder;
 
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.zip.ZipEntry;
 
 import org.apache.xbean.osgi.bundle.util.BundleResourceFinder;
@@ -34,15 +39,21 @@ import org.osgi.service.packageadmin.Pac
  */
 public class BundleAnnotationFinder extends AbstractFinder {
     private final Bundle bundle;
+    private final Set<String> paths;
 
     public BundleAnnotationFinder(PackageAdmin packageAdmin, Bundle bundle) throws Exception
{
         this(packageAdmin, bundle, BundleResourceFinder.FULL_DISCOVERY_FILTER);
     }
 
     public BundleAnnotationFinder(PackageAdmin packageAdmin, Bundle bundle, ResourceDiscoveryFilter
discoveryFilter) throws Exception {
+        this(packageAdmin, bundle, discoveryFilter, Collections.<String>emptySet());
+    }
+
+    public BundleAnnotationFinder(PackageAdmin packageAdmin, Bundle bundle, ResourceDiscoveryFilter
discoveryFilter, Set<String> paths) throws Exception {
         this.bundle = bundle;
         BundleResourceFinder bundleResourceFinder = new BundleResourceFinder(packageAdmin,
bundle, "", ".class", discoveryFilter);
         bundleResourceFinder.find(new AnnotationFindingCallback());
+        this.paths = paths;
     }
 
     @Override
@@ -55,12 +66,23 @@ public class BundleAnnotationFinder exte
         return bundle.loadClass(s);
     }
 
+    @Override
+    public List<String> getAnnotatedClassNames() {
+        List<String> classNames = new ArrayList<String>(originalInfos.size());
+        for (Map.Entry<String, ClassInfo> entry: originalInfos.entrySet()) {
+            if (paths.contains(entry.getValue().getPath())) {
+                classNames.add(entry.getKey());
+            }
+        }
+        return classNames;
+    }
+
     private class AnnotationFindingCallback implements BundleResourceFinder.ResourceFinderCallback
{
       
         public boolean foundInDirectory(Bundle bundle, String baseDir, URL url) throws Exception
{
             InputStream in = url.openStream();
             try {
-                readClassDef(in);
+                readClassDef(in, baseDir);
             } finally {
                 in.close();
             }
@@ -69,7 +91,7 @@ public class BundleAnnotationFinder exte
 
        
         public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream
in) throws Exception {
-            readClassDef(in);
+            readClassDef(in, jarName);
             return true;
         }
     }



Mime
View raw message