[jboss-cvs] JBossAS SVN: r67441 - trunk/server/src/main/org/jboss/deployment.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 26 08:14:54 EST 2007


Author: scott.stark at jboss.org
Date: 2007-11-26 08:14:53 -0500 (Mon, 26 Nov 2007)
New Revision: 67441

Added:
   trunk/server/src/main/org/jboss/deployment/AnnotatedClassFilter.java
   trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java
Log:
Checkpoint the annotation deployer

Added: trunk/server/src/main/org/jboss/deployment/AnnotatedClassFilter.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/AnnotatedClassFilter.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/deployment/AnnotatedClassFilter.java	2007-11-26 13:14:53 UTC (rev 67441)
@@ -0,0 +1,135 @@
+/*
+ * 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.deployment;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class AnnotatedClassFilter extends SuffixMatchFilter
+{
+   private static Logger log = Logger.getLogger(AnnotatedClassFilter.class);
+   private ClassLoader loader;
+   private List<VirtualFile> classpath;
+   private HashMap<VirtualFile, Class<?>> pathToClasses = new HashMap<VirtualFile, Class<?>>();
+
+   public AnnotatedClassFilter(ClassLoader loader, List<VirtualFile> classpath)
+   {
+      super(".class", VisitorAttributes.RECURSE);
+      this.loader = loader;
+      this.classpath = classpath;
+   }
+
+   public Map<VirtualFile, Class<?>> getAnnotatedClasses()
+   {
+      return pathToClasses;
+   }
+
+   @Override
+   public boolean accepts(VirtualFile file)
+   {
+      boolean accepts = super.accepts(file);
+      if(accepts)
+      {
+         accepts = false;
+         String className = null;
+         // TODO: 
+         try
+         {
+            className = getClassName(file);
+            System.out.println("Checking class: "+className);
+            Class<?> c = loader.loadClass(className);
+            Annotation[] annotations = c.getAnnotations();
+            if(annotations != null && annotations.length > 0)
+            {
+               pathToClasses.put(file, c);
+               accepts = true;
+            }
+         }
+         catch(NoClassDefFoundError ignored)
+         {
+            log.debug("Incomplete class: "+className+", NCDFE: "+ignored);
+         }
+         catch(Exception ignored)
+         {
+            ignored.printStackTrace();
+         }
+      }
+      return accepts;
+   }
+
+   /**
+    * Search the classpaths for the root of this file
+    * @param classFile
+    * @return
+    */
+   protected String getClassName(VirtualFile classFile)
+      throws IOException
+   {
+      String pathName = classFile.getPathName();
+      String name = pathName.substring(0, pathName.length()-6);
+      /*
+      for(VirtualFile root : classpath)
+      {
+         String rootPath = root.getPathName();
+         if(pathName.startsWith(rootPath))
+         {
+            name = pathName.substring(rootPath.length()+1, pathName.length()-6);
+            name = name.replace('/', '.');
+         }
+      }
+      */
+      return name;
+   }
+
+   public static void main(String[] args)
+      throws Exception
+   {
+      URI rootURI = new URI("file:/Users/svn/JBossHead/jboss-head/build/output/jboss-5.0.0.Beta3/server/default/deployers/jbossws.deployer");
+      VirtualFile deploy = VFS.getRoot(rootURI);
+      VirtualFile j1 = deploy.findChild("jbossws-common.jar");
+      VirtualFile j2 = deploy.findChild("jbossws-framework.jar");
+      VirtualFile j3 = deploy.findChild("jbossws-jboss50.jar");
+      ArrayList<VirtualFile> cp = new ArrayList<VirtualFile>();
+      cp.add(j1);
+      cp.add(j2);
+      cp.add(j3);
+      ClassLoader loader = AnnotatedClassFilter.class.getClassLoader();
+      AnnotatedClassFilter classVisitor = new AnnotatedClassFilter(loader, cp);
+      List<VirtualFile> classes = deploy.getChildren(classVisitor);
+      System.out.println(classes);
+   }
+}

Added: trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java	                        (rev 0)
+++ trunk/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java	2007-11-26 13:14:53 UTC (rev 67441)
@@ -0,0 +1,124 @@
+/*
+ * 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.deployment;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+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.virtual.VirtualFile;
+
+/**
+ * A POST_CLASSLOADER deployer which generates metadata from
+ * annotations
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class AnnotationMetaDataDeployer extends AbstractDeployer
+{
+
+   public AnnotationMetaDataDeployer()
+   {
+      setStage(DeploymentStages.POST_CLASSLOADER);
+   }
+
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      if (unit instanceof VFSDeploymentUnit == false)
+         return;
+      
+      VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+      deploy(vfsDeploymentUnit);
+   }
+
+   public void undeploy(DeploymentUnit unit)
+   {
+      if (unit instanceof VFSDeploymentUnit == false)
+         return;
+      
+      VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+      undeploy(vfsDeploymentUnit);
+   }
+
+   /**
+    * Deploy a vfs deployment
+    * 
+    * @param unit the unit
+    * @throws DeploymentException for any error
+    */
+   protected void deploy(VFSDeploymentUnit unit)
+      throws DeploymentException
+   {
+      VirtualFile root = unit.getRoot();
+      boolean isLeaf = true;
+      try
+      {
+         isLeaf = root.isLeaf();
+      }
+      catch(IOException ignore)
+      {
+      }
+      if(isLeaf == true)
+         return;
+
+      ClassLoader loader = unit.getClassLoader();
+      List<VirtualFile> classpath = unit.getClassPath();
+      if(classpath == null)
+         return;
+
+      AnnotatedClassFilter classVisitor = new AnnotatedClassFilter(loader, classpath);
+      try
+      {
+         ArrayList<VirtualFile> classpathClasses = new ArrayList<VirtualFile>();
+         for(VirtualFile path : classpath)
+         {
+            List<VirtualFile> classes = path.getChildren(classVisitor);
+            if(classes != null && classes.size() > 0)
+            {
+               log.info("Annotated classes: "+classes);
+               classpathClasses.addAll(classes);
+            }
+         }
+      }
+      catch(IOException e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+   /**
+    * Undeploy a vfs deployment
+    * 
+    * @param unit the unit
+    */
+   protected void undeploy(VFSDeploymentUnit unit)
+   {
+      // Nothing
+   }
+}
+




More information about the jboss-cvs-commits mailing list