[jboss-cvs] JBossAS SVN: r105641 - in trunk/server/src/main/java/org/jboss: web/deployers and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 3 10:32:15 EDT 2010


Author: remy.maucherat at jboss.com
Date: 2010-06-03 10:32:13 -0400 (Thu, 03 Jun 2010)
New Revision: 105641

Modified:
   trunk/server/src/main/java/org/jboss/deployment/OptAnnotationMetaDataDeployer.java
   trunk/server/src/main/java/org/jboss/web/deployers/WarAnnotationMetaDataDeployer.java
Log:
- Use the ResourcesIndex if present to do the annotation scanning.

Modified: trunk/server/src/main/java/org/jboss/deployment/OptAnnotationMetaDataDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/deployment/OptAnnotationMetaDataDeployer.java	2010-06-03 14:30:18 UTC (rev 105640)
+++ trunk/server/src/main/java/org/jboss/deployment/OptAnnotationMetaDataDeployer.java	2010-06-03 14:32:13 UTC (rev 105641)
@@ -25,14 +25,18 @@
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.metadata.annotation.creator.AbstractCreator;
 import org.jboss.metadata.annotation.creator.AnnotationContext;
 import org.jboss.metadata.annotation.creator.client.ApplicationClient5MetaDataCreator;
 import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
-import org.jboss.metadata.annotation.creator.web.Web25MetaDataCreator;
 import org.jboss.metadata.annotation.finder.AnnotationFinder;
 import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
 import org.jboss.metadata.client.spec.ApplicationClientMetaData;
@@ -47,7 +51,6 @@
 /**
  * A POST_CLASSLOADER deployer which generates metadata from annotations.
  * Optimized option to its super class.
- * TODO: Will need to support per JAR annotations for Servlet 3.0
  *
  * @author Ales.Justin at jboss.org
  */
@@ -72,21 +75,6 @@
    }
 
    /**
-    * Process jboss web meta data.
-    *
-    * @param unit the deployment unit
-    * @param finder the finder
-    */
-   protected void processJBossWebMetaData(VFSDeploymentUnit unit, AnnotationFinder<AnnotatedElement> finder)
-   {
-      Web25MetaDataCreator creator = new Web25MetaDataCreator(finder);
-      Collection<Class<?>> classes = getClasses(unit, creator);
-      WebMetaData annotationMetaData = creator.create(classes);
-      if(annotationMetaData != null)
-         unit.addAttachment(WEB_ANNOTATED_ATTACHMENT_NAME, annotationMetaData, WebMetaData.class);
-   }
-
-   /**
     * Process jboss app client meta data.
     *
     * @param unit the deployment unit
@@ -139,7 +127,6 @@
       {
          if (trace)
             log.trace("Cannot scan classes, missing AnnotationRepository as attachment: " + unit.getName());
-
          return Collections.emptySet();
       }
 

Modified: trunk/server/src/main/java/org/jboss/web/deployers/WarAnnotationMetaDataDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/WarAnnotationMetaDataDeployer.java	2010-06-03 14:30:18 UTC (rev 105640)
+++ trunk/server/src/main/java/org/jboss/web/deployers/WarAnnotationMetaDataDeployer.java	2010-06-03 14:32:13 UTC (rev 105641)
@@ -22,11 +22,14 @@
 package org.jboss.web.deployers;
 
 import java.io.IOException;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.annotations.ScanningMetaData;
@@ -35,10 +38,12 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.deployment.AnnotatedClassFilter;
+import org.jboss.metadata.annotation.creator.AnnotationContext;
 import org.jboss.metadata.annotation.creator.web.Web30MetaDataCreator;
 import org.jboss.metadata.annotation.finder.AnnotationFinder;
 import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
 import org.jboss.metadata.web.spec.WebMetaData;
+import org.jboss.scanning.web.spi.ResourcesIndex;
 import org.jboss.vfs.VirtualFile;
 
 /**
@@ -59,6 +64,7 @@
       setStage(DeploymentStages.POST_CLASSLOADER);
       addInput(WebMetaData.class);
       addInput(ScanningMetaData.class);
+      addInput(ResourcesIndex.class);
       addOutput(WEB_ANNOTATED_ATTACHMENT_NAME);
    }
 
@@ -133,7 +139,71 @@
     */
    protected void processMetaData(VFSDeploymentUnit unit, List<VirtualFile> classpath) throws Exception
    {
+      ResourcesIndex ri = unit.getAttachment(ResourcesIndex.class);
+      if (ri == null)
+      {
+         log.warn("Cannot scan classes, missing ResourcesIndex as attachment: " + unit.getName());
+         processMetaData1(unit, classpath);
+         return;
+      }
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      Web30MetaDataCreator creator = new Web30MetaDataCreator(finder);
+      // Merge processed annotations from all scopes 
+      Set<Class<? extends Annotation>> annotations = new HashSet<Class<? extends Annotation>>();
+      AnnotationContext annotationContext = creator.getAnnotationContext();
+      if (annotationContext.getTypeAnnotations() != null)
+         annotations.addAll(annotationContext.getTypeAnnotations());
+      if (annotationContext.getMethodAnnotations() != null)
+         annotations.addAll(annotationContext.getMethodAnnotations());
+      if (annotationContext.getFieldAnnotations() != null)
+         annotations.addAll(annotationContext.getFieldAnnotations());
+
+      boolean metaData = false;
       ScanningMetaData scanningMetaData = unit.getAttachment(ScanningMetaData.class);
+      for (VirtualFile path : classpath)
+      {
+         if (scanningMetaData == null 
+               || !(scanningMetaData.getPaths() == null 
+                     || !scanningMetaData.getPaths().contains(path.getName())))
+         {
+            Set<Class<?>> annotatedClasses = new HashSet<Class<?>>();
+            for (Class<? extends Annotation> annotation : annotations)
+            {
+               annotatedClasses.addAll(ri.getAnnotatedClasses(path, annotation));
+            }
+            WebMetaData annotationMetaData = creator.create(annotatedClasses);
+            if (annotationMetaData != null)
+            {
+               unit.addAttachment(WEB_ANNOTATED_ATTACHMENT_NAME + ":" + path.getName(), annotationMetaData, WebMetaData.class);
+               metaData = true;
+            }
+         }
+      }
+      if (metaData)
+         unit.addAttachment(WEB_ANNOTATED_ATTACHMENT_NAME, Boolean.TRUE);
+   }
+
+   /**
+    * Undeploy a vfs deployment
+    * 
+    * @param unit the unit
+    */
+   protected void undeploy(VFSDeploymentUnit unit)
+   {
+      // Nothing
+   }
+
+   /**
+    * Process metadata.
+    *
+    * @param unit the deployment unit
+    * @param classpath the classpath
+    * @throws Exception for any error
+    * @deprecated
+    */
+   protected void processMetaData1(VFSDeploymentUnit unit, List<VirtualFile> classpath) throws Exception
+   {
+      ScanningMetaData scanningMetaData = unit.getAttachment(ScanningMetaData.class);
       Map<VirtualFile, Collection<Class<?>>> classesPerJar = new HashMap<VirtualFile, Collection<Class<?>>>();
       boolean foundAnnotations = false;
       for (VirtualFile path : classpath)
@@ -165,6 +235,7 @@
     * @param classpath the classpath
     * @return possible classes containing metadata annotations
     * @throws IOException for any error
+    * @deprecated
     */
    protected Collection<Class<?>> getClasses(VFSDeploymentUnit unit, VirtualFile classpath) throws IOException
    {
@@ -184,21 +255,12 @@
    }
 
    /**
-    * Undeploy a vfs deployment
-    * 
-    * @param unit the unit
-    */
-   protected void undeploy(VFSDeploymentUnit unit)
-   {
-      // Nothing
-   }
-
-   /**
     * Process annotations.
     *
     * @param unit the deployment unit
     * @param finder the annotation finder
     * @param classes the candidate classes
+    * @deprecated
     */
    protected void processJBossWebMetaData(VFSDeploymentUnit unit,
          AnnotationFinder<AnnotatedElement> finder, Map<VirtualFile, Collection<Class<?>>> classes)




More information about the jboss-cvs-commits mailing list