[jboss-cvs] JBossAS SVN: r110432 - in trunk: weld-int/assembly/src/main/assembly/resources/META-INF and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 24 00:23:09 EST 2011


Author: alesj
Date: 2011-01-24 00:23:08 -0500 (Mon, 24 Jan 2011)
New Revision: 110432

Added:
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPlugin.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPluginFactory.java
Modified:
   trunk/server/src/etc/deployers/scanning-deployers-jboss-beans.xml
   trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java
Log:
[JBAS-8828]; use MC' Scanning in Weld-int; initial commit.





Modified: trunk/server/src/etc/deployers/scanning-deployers-jboss-beans.xml
===================================================================
--- trunk/server/src/etc/deployers/scanning-deployers-jboss-beans.xml	2011-01-23 02:08:35 UTC (rev 110431)
+++ trunk/server/src/etc/deployers/scanning-deployers-jboss-beans.xml	2011-01-24 05:23:08 UTC (rev 110432)
@@ -178,7 +178,6 @@
     </property>
   </bean>
   <bean name="HierarchyScanningPluginFactory" class="org.jboss.scanning.hierarchy.plugins.HierarchyIndexScanningPluginFactory"/>
-  <!-- bean name="WeldScanningPluginFactory" class="org.jboss.scanning.weld.WeldScanningPluginFactory"/ -->
 
   <bean name="ScanningDeployer" class="org.jboss.scanning.deployers.ScanningDeployer">
     <property name="filter">

Modified: trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml
===================================================================
--- trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml	2011-01-23 02:08:35 UTC (rev 110431)
+++ trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml	2011-01-24 05:23:08 UTC (rev 110432)
@@ -40,10 +40,14 @@
   <bean name="ArchiveInfoDeployer" class="org.jboss.weld.integration.deployer.env.ArchiveInfoDeployer"/>
   <bean name="ArchiveDiscoveryDeployer" class="org.jboss.weld.integration.deployer.env.ArchiveDiscoveryDeployer"/>
 
-  <!-- Responsible for discovering Weld classes -->
+  <!-- Let the new MC scanning take over
+  <bean name="WeldScanningPluginFactory" class="org.jboss.weld.integration.deployer.scanning.WeldScanningPluginFactory"/>
+  -->
+
+  <!-- Responsible for Weld + EJB integration -->
   <bean name="EjbServicesDeployer" class="org.jboss.weld.integration.deployer.env.EjbServicesDeployer"/>
 
-  <!-- Responsible for discovering Weld classes -->
+  <!-- Responsible for hierarchy deployment creation -->
    <bean name="DeploymentDeployer" class="org.jboss.weld.integration.deployer.env.JBossDeploymentDeployer"/>
 
   <!-- Responsible for dynamic ejb dependency creation -->

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java	2011-01-23 02:08:35 UTC (rev 110431)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java	2011-01-24 05:23:08 UTC (rev 110432)
@@ -52,7 +52,7 @@
    /**
     * Add weld class.
     *
-    * @param clazz the weld class
+    * @param className the weld class
     */
    public void addWeldClass(String className)
    {
@@ -74,6 +74,7 @@
     *
     * @return the weld classes
     */
+   @Deprecated
    public Collection<String> getWeldClasses()
    {
       // FIXME WELDINT-1 old classes that use this method should get an Unmodifiable

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java	2011-01-23 02:08:35 UTC (rev 110431)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java	2011-01-24 05:23:08 UTC (rev 110432)
@@ -26,8 +26,12 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.weld.integration.deployer.env.WeldDiscoveryEnvironment;
+import org.jboss.weld.integration.util.EjbDiscoveryUtils;
 
+import com.google.common.collect.ForwardingCollection;
+
 /**
  * Contains information necessary for the creation of an Archive.
  * All the information contained in a ArchiveInfo is gathered during deployment and is
@@ -35,6 +39,7 @@
  * BeanDeploymentArchive and Deployment creation) 
  * 
  * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision$
  */
 public class ArchiveInfo
@@ -76,6 +81,33 @@
     * Creates an ArchiveInfo to keep track of all data related to an archive
     * during deployment.
     * 
+    * @param unit the deployment unit
+    */
+   public ArchiveInfo(final DeploymentUnit unit)
+   {
+      this(unit.getClassLoader(), new ForwardingCollection<String>()
+      {
+         private Collection<String> ejbs;
+
+         protected Collection<String> delegate()
+         {
+            if (ejbs == null)
+            {
+               synchronized (this)
+               {
+                  if (ejbs == null)
+                     ejbs = EjbDiscoveryUtils.getVisibleEJbNames(unit);
+               }
+            }
+            return ejbs;
+         }
+      });
+   }
+
+   /**
+    * Creates an ArchiveInfo to keep track of all data related to an archive
+    * during deployment.
+    *
     * @param classLoader the classLoader that is loading the archive under deployment.
     * @param ejbNames the names of the EJBs that are deployed in this archive
     */
@@ -121,7 +153,9 @@
    }
 
    /**
-    * Gets the EJBs of this archive
+    * Gets the EJBs of this archive.
+    *
+    * @return ejb names
     */
    public Collection<String> getEjbNames()
    {

Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPlugin.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPlugin.java	                        (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPlugin.java	2011-01-24 05:23:08 UTC (rev 110432)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.weld.integration.deployer.scanning;
+
+import java.net.URL;
+import java.util.Collection;
+
+import org.jboss.classloading.spi.visitor.ClassFilter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.scanning.plugins.helpers.VoidScanningHandle;
+import org.jboss.scanning.spi.helpers.AbstractScanningPlugin;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.weld.integration.deployer.env.WeldDiscoveryEnvironment;
+
+/**
+ * Weld scanning plugin.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WeldScanningPlugin extends AbstractScanningPlugin<VoidScanningHandle, Object>
+{
+   private ResourceVisitor visitor;
+   private Collection<VirtualFile> cpFiles;
+
+   public WeldScanningPlugin(WeldDiscoveryEnvironment environment, Collection<VirtualFile> cpFiles)
+   {
+      this.visitor = new WBDiscoveryVisitor(environment);
+      this.cpFiles = cpFiles;
+   }
+
+   @Override
+   protected VoidScanningHandle doCreateHandle()
+   {
+      return VoidScanningHandle.INSTANCE;
+   }
+
+   public Class<Object> getHandleInterface()
+   {
+      return Object.class;
+   }
+
+   @Override
+   public void cleanupHandle(Object handle)
+   {
+      visitor = null;
+   }
+
+   @Override
+   public ResourceFilter getRecurseFilter()
+   {
+      return new ResourceFilter()
+      {
+         public boolean accepts(ResourceContext resource)
+         {
+            try
+            {
+               URL url = resource.getUrl();
+               VirtualFile file = VFS.getChild(url.toURI());
+               VirtualFile[] parents = file.getParentFiles();
+               // we're going from the end, from API the first element is the leafmost.
+               for (VirtualFile parent : parents)
+               {
+                  // is our resource part of weld's classpath
+                  if (cpFiles.contains(parent))
+                     return true;
+               }
+               return false;
+            }
+            catch (Exception e)
+            {
+               throw new RuntimeException(e);
+            }
+         }
+      };
+   }
+
+   public ResourceFilter getFilter()
+   {
+      return visitor.getFilter();
+   }
+
+   public void visit(ResourceContext resource)
+   {
+      visitor.visit(resource);
+   }
+
+   private static class WBDiscoveryVisitor implements ResourceVisitor
+   {
+      private WeldDiscoveryEnvironment env;
+
+      private WBDiscoveryVisitor(WeldDiscoveryEnvironment wbdi)
+      {
+         this.env = wbdi;
+      }
+
+      public ResourceFilter getFilter()
+      {
+         return ClassFilter.INSTANCE;
+      }
+
+      public void visit(ResourceContext resource)
+      {
+         env.addWeldClass(resource.loadClass().getName());
+      }
+   }
+}
\ No newline at end of file

Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPluginFactory.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPluginFactory.java	                        (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/scanning/WeldScanningPluginFactory.java	2011-01-24 05:23:08 UTC (rev 110432)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.weld.integration.deployer.scanning;
+
+import java.util.Collection;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
+import org.jboss.scanning.plugins.helpers.VoidScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.weld.integration.deployer.DeployersUtils;
+import org.jboss.weld.integration.deployer.env.WeldDiscoveryEnvironment;
+import org.jboss.weld.integration.deployer.env.bda.ArchiveInfo;
+
+/**
+ * Add Weld scanning plugin.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WeldScanningPluginFactory implements DeploymentScanningPluginFactory<VoidScanningHandle, Object>
+{
+   /**
+    * Get Weld discovery environment.
+    *
+    * @param unit the current deployment unit
+    * @return weld discovery env
+    */
+   protected WeldDiscoveryEnvironment getEnv(DeploymentUnit unit)
+   {
+      DeploymentUnit moduleUnit = unit;
+      Module module = moduleUnit.getAttachment(Module.class);
+      while (moduleUnit != null && module == null)
+      {
+         moduleUnit = moduleUnit.getParent();
+         module = moduleUnit.getAttachment(Module.class);
+      }
+      if (module == null)
+         throw new IllegalStateException("No module in deployment unit's hierarchy: " + unit.getName());
+
+      ArchiveInfo archive = moduleUnit.getAttachment(ArchiveInfo.class);
+      if (archive == null)
+         throw new IllegalStateException("Archive attachment expected for unit " + unit);
+
+      return archive.getEnvironment();
+   }
+
+   public boolean isRelevant(DeploymentUnit unit)
+   {
+      if (DeployersUtils.checkForWeldFilesAcrossDeployment(unit) == false)
+         return false;
+
+      // only create ArchiveInfo for deployments with own classloader/module
+      if (unit.isAttachmentPresent(Module.class))
+      {
+         unit.addAttachment(ArchiveInfo.class, new ArchiveInfo(unit));
+      }
+
+      @SuppressWarnings("unchecked")
+      Collection<VirtualFile> wbFiles = unit.getAttachment(DeployersUtils.WELD_FILES, Collection.class);
+      boolean hasWB = (wbFiles != null && wbFiles.isEmpty() == false);
+
+      if (hasWB)
+      {
+         WeldDiscoveryEnvironment environment = getEnv(unit);
+         try
+         {
+            for (VirtualFile file : wbFiles)
+               environment.addWeldXmlURL(file.toURL());
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+
+      @SuppressWarnings("unchecked")
+      Collection<VirtualFile> cpFiles = unit.getAttachment(DeployersUtils.WELD_CLASSPATH, Collection.class);
+      return (cpFiles != null && cpFiles.isEmpty() == false);
+   }
+
+   public String getPluginOutput()
+   {
+      return ArchiveInfo.class.getName(); // we depend on this attachment
+   }
+
+   public ScanningPlugin<VoidScanningHandle, Object> create(DeploymentUnit unit)
+   {
+      @SuppressWarnings("unchecked")
+      Collection<VirtualFile> cpFiles = unit.getAttachment(DeployersUtils.WELD_CLASSPATH, Collection.class);
+      WeldDiscoveryEnvironment environment = getEnv(unit);
+      return new WeldScanningPlugin(environment, cpFiles);
+   }
+}



More information about the jboss-cvs-commits mailing list