[jboss-cvs] JBossAS SVN: r105722 - trunk/server/src/main/java/org/jboss/web/deployers.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 4 09:17:21 EDT 2010


Author: remy.maucherat at jboss.com
Date: 2010-06-04 09:17:20 -0400 (Fri, 04 Jun 2010)
New Revision: 105722

Removed:
   trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java
Modified:
   trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java
Log:
- Migrate SCI to scanning, dropping the horrible classloading hack. SCI HandlesTypes is not a very critical feature, so no legacy failover.

Deleted: trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java	2010-06-04 13:11:43 UTC (rev 105721)
+++ trunk/server/src/main/java/org/jboss/web/deployers/HandlesTypesClassFilter.java	2010-06-04 13:17:20 UTC (rev 105722)
@@ -1,183 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * 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.web.deployers;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.servlet.ServletContainerInitializer;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.VirtualFileFilter;
-import org.jboss.vfs.VirtualFileVisitor;
-import org.jboss.vfs.VisitorAttributes;
-
-/**
- * A VirtualFileVisitor that traverses unit root and determines the
- * class files that extend, implement, or are annotated by HandlesTypes.
- * 
- * @author Scott.Stark at jboss.org
- * @author Remy Maucherat
- * @version $Revision: 82920 $
- */
-public class HandlesTypesClassFilter implements VirtualFileVisitor
-{
-   private static Logger log = Logger.getLogger(HandlesTypesClassFilter.class);
-   private ClassLoader loader;
-   private int rootLength;
-   private HashSet<String> childPaths = new HashSet<String>();
-   private Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes;
-   private Class<?>[] typesArray;
-   private Map<Class<?>, Set<ServletContainerInitializer>> typesMap;
-
-   public HandlesTypesClassFilter(VFSDeploymentUnit unit, ClassLoader loader,
-         VirtualFile classpathRoot, Class<?>[] typesArray, Map<Class<?>, Set<ServletContainerInitializer>> typesMap,
-         Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes)
-   {
-      this.loader = loader;
-      this.handlesTypes = handlesTypes;
-      this.typesArray = typesArray;
-      this.typesMap = typesMap;
-
-      // Work out the root length. If there is a root, we need to add one to jump across the next /
-      String rootName = classpathRoot.getPathName();
-      rootLength = rootName.length();
-      if (rootLength > 0)
-         rootLength += 1;
-      List<DeploymentUnit> children = unit.getChildren();
-      if(children != null)
-      {
-         for(DeploymentUnit cu : children)
-         {
-            String path = cu.getName();
-            childPaths.add(path);
-         }
-      }
-   }
-
-   public VisitorAttributes getAttributes()
-   {
-      VisitorAttributes attributes = new VisitorAttributes();
-      attributes.setIncludeRoot(true);
-      attributes.setRecurseFilter(new NoChildFilter());
-      return attributes;
-   }
-
-   public void visit(VirtualFile file)
-   {
-      if(file.isFile())
-      {
-         accepts(file);
-      }
-   }
-
-   @SuppressWarnings("unchecked")
-   public boolean accepts(VirtualFile file)
-   {
-      boolean accepts = file.getPathName().endsWith(".class");
-      if(accepts)
-      {
-         accepts = false;
-         String className = null;
-         try
-         {
-            className = getClassName(file);
-            Class<?> c = loader.loadClass(className);
-            for (Class<?> clazz : typesArray)
-            {
-               if ((clazz.isAnnotation() && c.isAnnotationPresent((Class<? extends Annotation>) clazz))
-                     || clazz.isAssignableFrom(c))
-               {
-                  Set<ServletContainerInitializer> sciSet = typesMap.get(clazz);
-                  for (ServletContainerInitializer sci : sciSet)
-                  {
-                     handlesTypes.get(sci).add(c);
-                  }
-               }
-            }
-         }
-         catch(NoClassDefFoundError ignored)
-         {
-            log.debug("Incomplete class: "+className+", NCDFE: "+ignored);
-         }
-         catch(Exception ignored)
-         {
-            if(log.isTraceEnabled())
-               log.trace("Failed to load class: "+className, ignored);
-         }
-      }
-      return accepts;
-   }
-
-   protected String getFilePath(VirtualFile file)
-   {
-      String path = null;
-      try
-      {
-         path = file.toURI().toString();
-      }
-      catch(Exception e)
-      {
-      }
-      return path;
-   }
-
-   /**
-    * Search the classpaths for the root of this file.
-    *
-    * @param classFile the class file
-    * @return fqn class name
-    * @throws IOException for any error
-    */
-   protected String getClassName(VirtualFile classFile) throws IOException
-   {
-      String pathName = classFile.getPathName();
-      String name = pathName.substring(rootLength, pathName.length()-6);
-      name = name.replace('/', '.');
-      return name;
-   }
-
-   class NoChildFilter implements VirtualFileFilter
-   {
-      public boolean accepts(VirtualFile file)
-      {
-         String path = getFilePath(file);
-         boolean accepts = false;
-         try
-         {
-            accepts = file.isLeaf() == false && childPaths.contains(path) == false;
-         }
-         catch(Exception e)
-         {
-         }
-         return accepts;
-      }
-      
-   }
-}

Modified: trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	2010-06-04 13:11:43 UTC (rev 105721)
+++ trunk/server/src/main/java/org/jboss/web/deployers/ServletContainerInitializerDeployer.java	2010-06-04 13:17:20 UTC (rev 105722)
@@ -25,6 +25,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.lang.annotation.Annotation;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.HashMap;
@@ -38,13 +39,13 @@
 import javax.servlet.annotation.HandlesTypes;
 
 import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.annotations.ScanningMetaData;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
 import org.jboss.metadata.web.spec.WebMetaData;
+import org.jboss.scanning.web.spi.ResourcesIndex;
 import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 
@@ -78,7 +79,7 @@
    {
       setStage(DeploymentStages.POST_CLASSLOADER);
       setInput(JBossWebMetaData.class);
-      addInput(ScanningMetaData.class);
+      addInput(ResourcesIndex.class);
       addInput(MergedJBossWebMetaDataDeployer.WEB_ORDER_ATTACHMENT_NAME);
       addInput(MergedJBossWebMetaDataDeployer.WEB_SCIS_ATTACHMENT_NAME);
       addOutput(SCI_ATTACHMENT_NAME);
@@ -146,6 +147,8 @@
             }
          }
       }
+      unit.addAttachment(SCI_ATTACHMENT_NAME, scis);
+
       // Process HandlesTypes for ServletContainerInitializer
       Map<Class<?>, Set<ServletContainerInitializer>> typesMap = 
          new HashMap<Class<?>, Set<ServletContainerInitializer>>();
@@ -174,7 +177,13 @@
          }
       }
       
-      ScanningMetaData scanningMetaData = unit.getAttachment(ScanningMetaData.class);
+      ResourcesIndex ri = unit.getAttachment(ResourcesIndex.class);
+      if (ri == null)
+      {
+         log.warn("Cannot process SCI HandlesTypes, missing ResourcesIndex as attachment: " + unit.getName());
+         unit.addAttachment(SCI_HANDLESTYPES_ATTACHMENT_NAME, handlesTypes);
+         return;
+      }
       Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
       // Find classes which extend, implement, or are annotated by HandlesTypes
       if (typesArray.length > 0 && unit instanceof VFSDeploymentUnit)
@@ -185,13 +194,30 @@
          {
             for (VirtualFile classpathItem : classpath)
             {
-               if (scanningMetaData == null 
-                     || !(scanningMetaData.getPaths() == null 
-                           || !scanningMetaData.getPaths().contains(classpathItem.getName())))
+               for (Class<?> type : typesArray)
                {
-                  HandlesTypesClassFilter classVisitor = new HandlesTypesClassFilter(vfsUnit, unit.getClassLoader(), 
-                        classpathItem, typesArray, typesMap, handlesTypes);
-                  classpathItem.visit(classVisitor);
+                  if (type.isAnnotation())
+                  {
+                     Set<Class<?>> classes = ri.getAnnotatedClasses(classpathItem, (Class<Annotation>) type);
+                     Set<ServletContainerInitializer> sciSet = typesMap.get(type);
+                     for (ServletContainerInitializer sci : sciSet)
+                     {
+                        handlesTypes.get(sci).addAll(classes);
+                     }
+                  }
+                  else
+                  {
+                     Set classes = ri.getInheritedClasses(classpathItem, type);
+                     Set<ServletContainerInitializer> sciSet = typesMap.get(type);
+                     for (ServletContainerInitializer sci : sciSet)
+                     {
+                        Set<Class<?>> sciClasses = handlesTypes.get(sci);
+                        for (Object clazz : classes)
+                        {
+                           sciClasses.add((Class<?>) clazz);
+                        }
+                     }
+                  }
                }
             }
          }
@@ -200,10 +226,8 @@
             DeploymentException.rethrowAsDeploymentException("Deployment error scanning HandlesTypes", e);
          }
       }
-      
-      unit.addAttachment(SCI_ATTACHMENT_NAME, scis);
       unit.addAttachment(SCI_HANDLESTYPES_ATTACHMENT_NAME, handlesTypes);
-  }
+   }
    
    
    private ServletContainerInitializer loadSci(DeploymentUnit unit, VirtualFile sci, String jar, boolean error)



More information about the jboss-cvs-commits mailing list