[jboss-cvs] JBossAS SVN: r76378 - projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 29 06:49:52 EDT 2008


Author: alesj
Date: 2008-07-29 06:49:52 -0400 (Tue, 29 Jul 2008)
New Revision: 76378

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ScopedGenericAnnotationDeployer.java
Modified:
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
Log:
Fix few class pool issues.
Add usage of scoped class pool.

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.java	2008-07-29 10:48:38 UTC (rev 76377)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.java	2008-07-29 10:49:52 UTC (rev 76378)
@@ -34,7 +34,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class FilteredGenericAnnotationDeployer extends GenericAnnotationDeployer
+public class FilteredGenericAnnotationDeployer extends ScopedGenericAnnotationDeployer
 {
    private ResourceFilter resourceFilter;
    private ResourceFilter recurseFilter;

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java	2008-07-29 10:48:38 UTC (rev 76377)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java	2008-07-29 10:49:52 UTC (rev 76378)
@@ -21,7 +21,9 @@
 */
 package org.jboss.deployers.plugins.annotations;
 
+import javassist.ClassPath;
 import javassist.ClassPool;
+import javassist.LoaderClassPath;
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
@@ -38,6 +40,7 @@
 {
    private boolean forceAnnotations;
    private boolean keepAnnotations;
+   private boolean checkInterfaces = true;
 
    public GenericAnnotationDeployer()
    {
@@ -67,6 +70,16 @@
    }
 
    /**
+    * Should we check interfaces for annotations as well.
+    *
+    * @param checkInterfaces the check interfaces flag
+    */
+   public void setCheckInterfaces(boolean checkInterfaces)
+   {
+      this.checkInterfaces = checkInterfaces;
+   }
+
+   /**
     * Create GenericAnnotationResourceVisitor.
     *
     * Can be used change existing GARV's filter.
@@ -82,10 +95,25 @@
       GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(pool, classLoader);
       visitor.setForceAnnotations(forceAnnotations);
       visitor.setKeepAnnotations(keepAnnotations);
+      visitor.setCheckInterfaces(checkInterfaces);
       return visitor;
    }
 
    /**
+    * Create class pool.
+    *
+    * @param classLoader the class loader
+    * @return javassist class pool
+    */
+   protected ClassPool createClassPool(ClassLoader classLoader)
+   {
+      ClassPool pool = new ClassPool();
+      ClassPath classPath = new LoaderClassPath(classLoader);
+      pool.insertClassPath(classPath);
+      return pool;
+   }
+
+   /**
     * Visit module.
     *
     * Util method to add some behavior to Module
@@ -105,10 +133,12 @@
       if (log.isTraceEnabled())
          log.trace("Creating AnnotationEnvironment for " + unit + ", module: " + module + ", force annotations: " + forceAnnotations);
 
-      ClassPool pool = ClassPool.getDefault();
       ClassLoader classLoader = unit.getClassLoader();
+
+      ClassPool pool = createClassPool(classLoader);
       GenericAnnotationResourceVisitor visitor = createGenericAnnotationResourceVisitor(unit, pool, classLoader);
 
+      // something in javassist uses TCL
       ClassLoader tcl = Thread.currentThread().getContextClassLoader();
       Thread.currentThread().setContextClassLoader(classLoader);
       try

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java	2008-07-29 10:48:38 UTC (rev 76377)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java	2008-07-29 10:49:52 UTC (rev 76378)
@@ -56,6 +56,7 @@
    private ResourceFilter resourceFilter = ClassFilter.INSTANCE;
    private ClassPool pool;
    private boolean forceAnnotations;
+   private boolean checkInterfaces = true;
    private DefaultAnnotationEnvironment env;
    private CtClass objectCtClass;
 
@@ -150,6 +151,9 @@
       if (ctClass == null || objectCtClass.equals(ctClass))
          return;
 
+      if (checkInterfaces == false && ctClass.isInterface())
+         return;
+
       if (log.isTraceEnabled())
          log.trace("Scanning class " + ctClass + " for annotations, resource url: " + resource.getUrl());
 
@@ -159,12 +163,15 @@
       handleCtMembers(ElementType.METHOD, ctClass.getDeclaredMethods(), resource);
       handleCtMembers(ElementType.FIELD, ctClass.getDeclaredFields(), resource);
 
-      // interfaces
-      CtClass[] interfaces = ctClass.getInterfaces();
-      if (interfaces != null && interfaces.length > 0)
+      if (checkInterfaces)
       {
-         for (CtClass intf : interfaces)
-            handleCtClass(intf, resource);
+         // interfaces
+         CtClass[] interfaces = ctClass.getInterfaces();
+         if (interfaces != null && interfaces.length > 0)
+         {
+            for (CtClass intf : interfaces)
+               handleCtClass(intf, resource);
+         }
       }
 
       // super class
@@ -292,6 +299,16 @@
    }
 
    /**
+    * Should we check interfaces for annotations as well.
+    *
+    * @param checkInterfaces the check interfaces flag
+    */
+   public void setCheckInterfaces(boolean checkInterfaces)
+   {
+      this.checkInterfaces = checkInterfaces;
+   }
+
+   /**
     * Get the built environment.
     *
     * @return the annoattion environment

Copied: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ScopedGenericAnnotationDeployer.java (from rev 76244, projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ScopedGenericAnnotationDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/ScopedGenericAnnotationDeployer.java	2008-07-29 10:49:52 UTC (rev 76378)
@@ -0,0 +1,62 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.plugins.annotations;
+
+import javassist.scopedpool.ScopedClassPoolRepository;
+import javassist.ClassPool;
+
+/**
+ * Scoped generic annotation deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ScopedGenericAnnotationDeployer extends GenericAnnotationDeployer
+{
+   private ScopedClassPoolRepository repository;
+
+   public ScopedGenericAnnotationDeployer()
+   {
+   }
+
+   public ScopedGenericAnnotationDeployer(ScopedClassPoolRepository repository)
+   {
+      this.repository = repository;
+   }
+
+   /**
+    * Set scoped class pool repository.
+    *
+    * @param repository the scoped class pool repository
+    */
+   public void setRepository(ScopedClassPoolRepository repository)
+   {
+      this.repository = repository;
+   }
+
+   protected ClassPool createClassPool(ClassLoader classLoader)
+   {
+      if (repository != null)
+         return repository.findClassPool(classLoader);
+
+      return super.createClassPool(classLoader);
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list