[jboss-cvs] JBossAS SVN: r95048 - in projects/jboss-deployers/trunk: deployers-vfs and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 16 12:18:49 EDT 2009


Author: alesj
Date: 2009-10-16 12:18:48 -0400 (Fri, 16 Oct 2009)
New Revision: 95048

Added:
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiRepositoryDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiScannerDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/util/
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/util/ClasspathUtils.java
Modified:
   projects/jboss-deployers/trunk/deployers-vfs/pom.xml
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/FilteredAnnotationEnvironmentDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classpool/test/ClassPoolTestCase.java
   projects/jboss-deployers/trunk/pom.xml
Log:
Initial Papaki usage.

Modified: projects/jboss-deployers/trunk/deployers-vfs/pom.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/pom.xml	2009-10-16 16:15:36 UTC (rev 95047)
+++ projects/jboss-deployers/trunk/deployers-vfs/pom.xml	2009-10-16 16:18:48 UTC (rev 95048)
@@ -175,6 +175,17 @@
       </exclusions>
     </dependency>
     <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-reflect</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.papaki</groupId>
+      <artifactId>papaki-core</artifactId>
+    </dependency>
+
+    <!-- tests -->
+
+    <dependency>
       <groupId>org.jboss.logging</groupId>
       <artifactId>jboss-logging-log4j</artifactId>
       <scope>test</scope>
@@ -191,12 +202,8 @@
     </dependency>
     <dependency>
       <groupId>org.jboss</groupId>
-      <artifactId>jboss-reflect</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss</groupId>
       <artifactId>jboss-classpool</artifactId>
       <scope>test</scope>
     </dependency>
-  </dependencies>  
+  </dependencies>
 </project>

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java	2009-10-16 16:15:36 UTC (rev 95047)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java	2009-10-16 16:18:48 UTC (rev 95048)
@@ -21,13 +21,6 @@
 */
 package org.jboss.deployers.vfs.plugins.annotations;
 
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import javassist.ClassPath;
-import javassist.ClassPool;
-import javassist.LoaderClassPath;
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.deployers.plugins.annotations.GenericAnnotationResourceVisitor;
 import org.jboss.deployers.spi.DeploymentException;
@@ -35,11 +28,17 @@
 import org.jboss.deployers.spi.annotations.ScanningMetaData;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.plugins.util.ClasspathUtils;
 import org.jboss.deployers.vfs.spi.deployer.AbstractOptionalVFSRealDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnitFilter;
-import org.jboss.virtual.VirtualFile;
 
+import java.net.URL;
+
+import javassist.ClassPath;
+import javassist.ClassPool;
+import javassist.LoaderClassPath;
+
 /**
  * A POST_CLASSLOADER deployer which creates AnnotationEnvironment for sub-deployments.
  *
@@ -58,6 +57,7 @@
       super(Module.class);
       setStage(DeploymentStages.POST_CLASSLOADER);
       addInput(ScanningMetaData.class);
+      addInput(AnnotationEnvironment.class);
       setOutput(AnnotationEnvironment.class);
       checkInterfaces = true;
    }
@@ -169,7 +169,8 @@
    {
       try
       {
-         module.visit(visitor, visitor.getFilter(), null, getUrls(unit));
+         URL[] urls = ClasspathUtils.getUrls(unit);
+         module.visit(visitor, visitor.getFilter(), null, urls);
       }
       catch (Exception e)
       {
@@ -177,42 +178,12 @@
       }
    }
 
-   /**
-    * Get the matching urls.
-    *
-    * @param unit the deployment unit
-    * @return matching urls
-    * @throws Exception for any error
-    */
-   protected URL[] getUrls(VFSDeploymentUnit unit) throws Exception
-   {
-      List<VirtualFile> classpath = unit.getClassPath();
-      if (classpath != null && classpath.isEmpty() == false)
-      {
-         List<URL> urls = new ArrayList<URL>();
-         VirtualFile root = unit.getRoot();
-         for (VirtualFile cp : classpath)
-         {
-            VirtualFile check = cp;
-            while(check != null && check.equals(root) == false)
-               check = check.getParent();
-
-            if (check != null)
-               urls.add(cp.toURL());
-         }
-         if (urls.isEmpty() == false)
-         {
-            if (log.isTraceEnabled())
-               log.trace("Explicit urls: " + urls);
-
-            return urls.toArray(new URL[urls.size()]);
-         }
-      }
-      return new URL[0];
-   }
-
    public void deploy(VFSDeploymentUnit unit, Module module) throws DeploymentException
    {
+      // we already used Papaki or some other mechanism to create env
+      if (unit.isAttachmentPresent(AnnotationEnvironment.class))
+         return;
+
       // running this deployer is costly, check if it should be run
       if (filter != null && filter.accepts(unit) == false)
          return;

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/FilteredAnnotationEnvironmentDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/FilteredAnnotationEnvironmentDeployer.java	2009-10-16 16:15:36 UTC (rev 95047)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/FilteredAnnotationEnvironmentDeployer.java	2009-10-16 16:18:48 UTC (rev 95048)
@@ -24,10 +24,13 @@
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.deployers.plugins.annotations.GenericAnnotationResourceVisitor;
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.vfs.plugins.util.ClasspathUtils;
 
+import java.net.URL;
+
 /**
  * Filtered annotation environment deployer.
  *
@@ -85,7 +88,8 @@
       ResourceFilter recurse = getFilter(unit, ResourceFilter.class, "recurse", recurseFilter);
       try
       {
-         module.visit(visitor, filter, recurse, getUrls(unit));
+         URL[] urls = ClasspathUtils.getUrls(unit);
+         module.visit(visitor, filter, recurse, urls);
       }
       catch (Exception e)
       {

Copied: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiRepositoryDeployer.java (from rev 95008, projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/FilteredAnnotationEnvironmentDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiRepositoryDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiRepositoryDeployer.java	2009-10-16 16:18:48 UTC (rev 95048)
@@ -0,0 +1,51 @@
+/*
+* 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.vfs.plugins.annotations;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.papaki.AnnotationRepository;
+
+/**
+ * Papaki repository deployer.
+ *
+ * It creates AnnotationEnvironment based on Papaki's AnnotationRepository.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PapakiRepositoryDeployer extends AbstractSimpleVFSRealDeployer<AnnotationRepository>
+{
+   public PapakiRepositoryDeployer()
+   {
+      super(AnnotationRepository.class);
+      setOutput(AnnotationEnvironment.class);
+      setStage(DeploymentStages.POST_CLASSLOADER);
+   }
+
+   public void deploy(VFSDeploymentUnit unit, AnnotationRepository deployment) throws DeploymentException
+   {
+      // TODO; AR --> AE
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiScannerDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiScannerDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/annotations/PapakiScannerDeployer.java	2009-10-16 16:18:48 UTC (rev 95048)
@@ -0,0 +1,90 @@
+/*
+* 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.vfs.plugins.annotations;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.vfs.plugins.util.ClasspathUtils;
+import org.jboss.deployers.vfs.spi.deployer.AbstractOptionalVFSRealDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.AnnotationScanner;
+import org.jboss.papaki.AnnotationScannerCreator;
+import org.jboss.papaki.Configuration;
+import org.jboss.papaki.ScanStrategy;
+
+import java.net.URL;
+
+/**
+ * Papaki scanning deployer.
+ *
+ * This deployer creates Papaki's AnnotationRepository based on .ser file.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PapakiScannerDeployer extends AbstractOptionalVFSRealDeployer<Configuration>
+{
+   /**
+    * The scanner creator.
+    */
+   private AnnotationScannerCreator creator = ScanStrategy.JAVASSIST_INPUT_STREAM;
+
+   public PapakiScannerDeployer()
+   {
+      super(Configuration.class);
+      setOutput(AnnotationRepository.class);
+      setStage(DeploymentStages.POST_CLASSLOADER);
+   }
+
+   public void deploy(VFSDeploymentUnit unit, Configuration configuration) throws DeploymentException
+   {
+      // let's first verify creator
+      creator.verify();
+
+      try
+      {
+         AnnotationScanner scanner = creator.create(configuration);
+         URL[] urls = ClasspathUtils.getUrls(unit);
+         ClassLoader cl = unit.getClassLoader();
+         // TODO - this needs filtering notion
+         AnnotationRepository repository = scanner.scan(urls, cl);
+         unit.addAttachment(AnnotationRepository.class, repository);
+      }
+      catch (Exception e)
+      {
+         throw DeploymentException.rethrowAsDeploymentException("Cannot create AnnotationRepository.", e);
+      }
+   }
+
+   /**
+    * Set the annotation scanner creator.
+    *
+    * @param creator the annotation scanner creator
+    */
+   public void setCreator(AnnotationScannerCreator creator)
+   {
+      if (creator == null)
+         throw new IllegalArgumentException("Null creator");
+
+      this.creator = creator;
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/util/ClasspathUtils.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/util/ClasspathUtils.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/util/ClasspathUtils.java	2009-10-16 16:18:48 UTC (rev 95048)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.vfs.plugins.util;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Classpath utils.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ClasspathUtils
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(ClasspathUtils.class);
+
+   /**
+    * Get the classpath urls that only belong to the unit.
+    *
+    * @param unit the deployment unit
+    * @return matching urls
+    * @throws Exception for any error
+    */
+   public static URL[] getUrls(VFSDeploymentUnit unit) throws Exception
+   {
+      List<VirtualFile> classpath = unit.getClassPath();
+      if (classpath != null && classpath.isEmpty() == false)
+      {
+         List<URL> urls = new ArrayList<URL>();
+         VirtualFile root = unit.getRoot();
+         for (VirtualFile cp : classpath)
+         {
+            VirtualFile check = cp;
+            while(check != null && check.equals(root) == false)
+               check = check.getParent();
+
+            if (check != null)
+               urls.add(cp.toURL());
+         }
+         if (urls.isEmpty() == false)
+         {
+            if (log.isTraceEnabled())
+               log.trace("Explicit urls: " + urls);
+
+            return urls.toArray(new URL[urls.size()]);
+         }
+      }
+      return new URL[0];
+   }
+}

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classpool/test/ClassPoolTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classpool/test/ClassPoolTestCase.java	2009-10-16 16:15:36 UTC (rev 95047)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classpool/test/ClassPoolTestCase.java	2009-10-16 16:18:48 UTC (rev 95048)
@@ -21,7 +21,6 @@
  */
 package org.jboss.test.deployers.vfs.classpool.test;
 
-import junit.framework.Test;
 import org.jboss.test.deployers.vfs.classpool.support.crm.CrmFacade;
 import org.jboss.test.deployers.vfs.classpool.support.ejb.MySLSBean;
 import org.jboss.test.deployers.vfs.classpool.support.ext.External;
@@ -33,6 +32,8 @@
 import org.jboss.test.deployers.vfs.classpool.support.web.AnyServlet;
 import org.jboss.virtual.AssembledDirectory;
 
+import junit.framework.Test;
+
 /**
  * Test case for ClassPool.
  * 
@@ -93,6 +94,7 @@
    public void testWarInEar() throws Exception 
    {
       AssembledDirectory directory = createWarInEar();
+      // TODO - make proper .war CL check --> MockWarCLDeployer
       assertClassPool(directory, AnyServlet.class);
    }
    

Modified: projects/jboss-deployers/trunk/pom.xml
===================================================================
--- projects/jboss-deployers/trunk/pom.xml	2009-10-16 16:15:36 UTC (rev 95047)
+++ projects/jboss-deployers/trunk/pom.xml	2009-10-16 16:18:48 UTC (rev 95048)
@@ -40,6 +40,7 @@
     <version.jboss.byteman>1.0.2</version.jboss.byteman>
     <version.jboss.reflect>2.2.0-SNAPSHOT</version.jboss.reflect>
     <version.jboss.classpool>1.0.0-SNAPSHOT</version.jboss.classpool>
+    <version.jboss.papaki>1.0.0-SNAPSHOT</version.jboss.papaki>
   </properties>
 
   <modules>
@@ -363,6 +364,11 @@
         <artifactId>jboss-classpool</artifactId>
         <version>${version.jboss.classpool}</version>
       </dependency>
+      <dependency>
+          <groupId>org.jboss.papaki</groupId>
+          <artifactId>papaki-core</artifactId>
+          <version>${version.jboss.papaki}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 




More information about the jboss-cvs-commits mailing list