[jboss-cvs] JBossAS SVN: r106423 - in trunk/weld-int/deployer-mc-int/src: test/java/org/jboss/test/deployers/support and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 5 07:15:02 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-07-05 07:15:01 -0400 (Mon, 05 Jul 2010)
New Revision: 106423

Added:
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/mc/
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/mc/SimpleBeanWithSimpleWebBean.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/weld/
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/weld/SimpleWebBean.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithConstructorAnnotation.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithInstallAnnotation.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithNoWeldAnnotations.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithPropertyAnnotation.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/WeldBeanMetaDataBuilderPluginUnitTestCase.java
   trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/
   trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/
   trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/MANIFEST.MF
   trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/simple-beans.xml
Modified:
   trunk/weld-int/deployer-mc-int/src/main/java/org/jboss/weld/integration/deployer/mc/WeldBeanMetaDataDeployerPlugin.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/mcandweld/mc/simple/SimpleBean.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationNoBootstrapBeanTestCase.java
   trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationTestCase.java
Log:
[JBAS-8106] Better determination of which beans should be installed as intermediate beans, leading to WeldKernelControllerContexts. Basically, look for the @WeldAnnotation

Modified: trunk/weld-int/deployer-mc-int/src/main/java/org/jboss/weld/integration/deployer/mc/WeldBeanMetaDataDeployerPlugin.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/main/java/org/jboss/weld/integration/deployer/mc/WeldBeanMetaDataDeployerPlugin.java	2010-07-05 09:50:21 UTC (rev 106422)
+++ trunk/weld-int/deployer-mc-int/src/main/java/org/jboss/weld/integration/deployer/mc/WeldBeanMetaDataDeployerPlugin.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -21,19 +21,32 @@
 */ 
 package org.jboss.weld.integration.deployer.mc;
 
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.jboss.beans.metadata.api.model.FromContext;
+import org.jboss.beans.metadata.spi.AnnotationMetaData;
 import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.ConstructorMetaData;
+import org.jboss.beans.metadata.spi.FeatureMetaData;
+import org.jboss.beans.metadata.spi.InstallMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
 import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.deployer.helpers.BeanMetaDataDeployerPlugin;
+import org.jboss.kernel.plugins.config.Configurator;
 import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.weld.metadata.api.annotations.Weld;
 import org.jboss.kernel.weld.plugins.annotations.WeldEnabledBeanAnnotationPluginInitializer;
+import org.jboss.reflect.spi.AnnotatedInfo;
+import org.jboss.reflect.spi.ClassInfo;
 import org.jboss.weld.integration.deployer.DeployersUtils;
 
 /**
@@ -56,8 +69,6 @@
    {
       WeldEnabledBeanAnnotationPluginInitializer.initialize();
    }
-   
-   //private final String[] ignoredSuffixes = new String[] {"_JBossDeployment", "_JBossEjbServices", "_WBInjector", "_JBossJpaServices", "_JBossValidationServices", "_WeldBootstrap", "_WeldBootstrapBean", "_WebCompJndiBinder", "_JavaModuleJndiBinder"};
 
    /** Map of real bean names and intermediate bean names */
    private final Map<Object, Object> intermediateBeans = new ConcurrentHashMap<Object, Object>();
@@ -96,24 +107,10 @@
          //Not a Weld deployment
          return null;
       }
-//      for (String suffix : ignoredSuffixes)
-//      {
-//         beanMetaData.getAnnotations()
-//         if (beanMetaData.getName().endsWith(suffix))
-//         {
-//            if (beanMetaData.getName().equals(unit.getTopLevel().getName() + suffix))
-//            {
-//               //Install Weld deployment bean as normal KernelControllerContext
-//               return null;
-//            }
-//         }
-//      }
-      if (isSystemBean(unit, beanMetaData))
-      {
-         //Install Weld deployment bean as normal KernelControllerContext
+      
+      if (!isMcBeanWithWeldAnnotatedInjectionPoints(controller, unit, beanMetaData))
          return null;
-      }
-         
+
       String beanName = unit.getTopLevel().getName() + "BootstrapBeanInstaller=" + beanMetaData.getName();
       BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanName, IntermediateWeldBootstrapBean.class.getName());
       builder.addPropertyMetaData("bootstrapBean", builder.createInject(DeployersUtils.getBootstrapBeanName(unit), null, ControllerState.CONFIGURED, ControllerState.CREATE));
@@ -128,21 +125,90 @@
       return ctx;
    }
    
-   private boolean isSystemBean(DeploymentUnit unit, BeanMetaData beanMetaData)
+   private boolean isMcBeanWithWeldAnnotatedInjectionPoints(Controller controller, DeploymentUnit unit, BeanMetaData beanMetaData)
    {
-      String name = beanMetaData.getName();
-      String topLevelName = unit.getTopLevel().getName();
-      if (name.contains(topLevelName) ||
-            name.contains(unit.getSimpleName()) ||
-            name.startsWith("jboss.j2ee:") ||
-            name.startsWith("jboss.naming:") ||
-            name.startsWith("jboss.ejb3") ||
-            name.endsWith("_CompJndiBinder"))
+      ConstructorMetaData con = beanMetaData.getConstructor();
+      if (con != null)
+      {
+         if (hasWeldAnnotation(unit, con))
+            return true;
+      }
+      
+      List<InstallMetaData> installs = beanMetaData.getInstalls();
+      if (installs != null && installs.size() > 0)
+      {
+         for (InstallMetaData install : installs)
+         {
+            if (hasWeldAnnotation(unit, install))
+               return true;
+         }
+      }
+      
+      Set<PropertyMetaData> properties = beanMetaData.getProperties();
+      if (properties != null && properties.size() > 0)
+      {
+         for (PropertyMetaData property : properties)
+         {
+            if (hasWeldAnnotation(unit, property))
+               return true;
+         }
+      }
+      
+      //TODO - use the annotation scanner instead
+      if (controller instanceof KernelController == false)
+         throw new IllegalArgumentException(controller + " is not a KernelController");
+      ClassInfo classInfo; 
+      try
+      {
+         KernelConfigurator config = ((KernelController)controller).getKernel().getConfigurator(); 
+         classInfo = config.getClassInfo(beanMetaData.getBean(), Configurator.getClassLoader(beanMetaData));
+      }
+      catch (Throwable e)
+      {
+         throw new RuntimeException(e);
+      }      
+      if (hasWeldAnnotation(classInfo.getDeclaredConstructors()))
          return true;
       
+      while (!classInfo.getName().startsWith("java.lang."))
+      {
+         if (hasWeldAnnotation(classInfo.getDeclaredFields()))
+            return true;
+         if (hasWeldAnnotation(classInfo.getDeclaredMethods()))
+            return true;
+         
+         classInfo = classInfo.getSuperclass();
+      }
+      
       return false;
    }
    
+   private boolean hasWeldAnnotation(AnnotatedInfo[] infos)
+   {
+      if (infos == null || infos.length == 0)
+         return false;
+      for (AnnotatedInfo info : infos)
+      {
+         if (info.isAnnotationPresent(Weld.class))
+            return true;
+      }
+      return false;
+   }
+   
+   private boolean hasWeldAnnotation(DeploymentUnit unit, FeatureMetaData fmd)
+   {
+      Set<AnnotationMetaData> anns = fmd.getAnnotations();
+      if (anns != null && anns.size() > 0)
+      {
+         for (AnnotationMetaData ann : anns)
+         {
+            if (ann.getAnnotationInstance(unit.getClassLoader()).annotationType() == Weld.class)
+               return true;
+         }
+      }
+      return false;
+   }
+   
    public boolean uninstallContext(Controller controller, DeploymentUnit unit, BeanMetaData beanMetaData)
    {
       //Only remove the intermediate bean if there is one

Modified: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/mcandweld/mc/simple/SimpleBean.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/mcandweld/mc/simple/SimpleBean.java	2010-07-05 09:50:21 UTC (rev 106422)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/mcandweld/mc/simple/SimpleBean.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -30,8 +30,8 @@
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
+ at WeldEnabled
 @Default
- at WeldEnabled
 public class SimpleBean
 {
 }

Added: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/mc/SimpleBeanWithSimpleWebBean.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/mc/SimpleBeanWithSimpleWebBean.java	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/mc/SimpleBeanWithSimpleWebBean.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.deployers.support.nobootstrap.mc;
+
+import javax.inject.Inject;
+
+import org.jboss.kernel.weld.metadata.api.annotations.Weld;
+import org.jboss.test.deployers.support.nobootstrap.weld.SimpleWebBean;
+
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleBeanWithSimpleWebBean
+{
+   @Weld @Inject
+   SimpleWebBean simple;
+}

Added: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/weld/SimpleWebBean.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/weld/SimpleWebBean.java	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/nobootstrap/weld/SimpleWebBean.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.deployers.support.nobootstrap.weld;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleWebBean
+{
+
+}

Added: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithConstructorAnnotation.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithConstructorAnnotation.java	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithConstructorAnnotation.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.deployers.support.unit;
+
+import javax.inject.Inject;
+
+import org.jboss.kernel.weld.metadata.api.annotations.Weld;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class McBeanWithConstructorAnnotation
+{
+   @Weld @Inject
+   public McBeanWithConstructorAnnotation(Object o)
+   {
+      
+   }
+}

Added: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithInstallAnnotation.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithInstallAnnotation.java	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithInstallAnnotation.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.deployers.support.unit;
+
+import javax.inject.Inject;
+
+import org.jboss.kernel.weld.metadata.api.annotations.Weld;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class McBeanWithInstallAnnotation
+{
+   @Weld @Inject
+   public void install()
+   {
+      
+   }
+}

Added: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithNoWeldAnnotations.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithNoWeldAnnotations.java	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithNoWeldAnnotations.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.deployers.support.unit;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class McBeanWithNoWeldAnnotations
+{
+   public McBeanWithNoWeldAnnotations()
+   {
+      
+   }
+   
+   public McBeanWithNoWeldAnnotations(Object o)
+   {
+      
+   }
+   
+   public void install()
+   {
+      
+   }
+   
+   public void setProperty(Object o)
+   {
+      
+   }
+}

Added: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithPropertyAnnotation.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithPropertyAnnotation.java	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/support/unit/McBeanWithPropertyAnnotation.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.deployers.support.unit;
+
+import javax.inject.Inject;
+
+import org.jboss.kernel.weld.metadata.api.annotations.Weld;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class McBeanWithPropertyAnnotation
+{
+   public McBeanWithPropertyAnnotation(Object o)
+   {
+      
+   }
+   
+   @Weld @Inject
+   public void setProperty(Object o)
+   {
+      
+   }
+}

Modified: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationNoBootstrapBeanTestCase.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationNoBootstrapBeanTestCase.java	2010-07-05 09:50:21 UTC (rev 106422)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationNoBootstrapBeanTestCase.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -27,8 +27,8 @@
 import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.test.deployers.support.mcandweld.mc.simple.SimpleBean;
-import org.jboss.test.deployers.support.mcandweld.weld.simple.SimpleWebBean;
+import org.jboss.test.deployers.support.nobootstrap.mc.SimpleBeanWithSimpleWebBean;
+import org.jboss.test.deployers.support.nobootstrap.weld.SimpleWebBean;
 import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 import org.jboss.weld.integration.deployer.DeployersUtils;
@@ -57,7 +57,7 @@
       VirtualFile ear = VFS.getChild("top-level.ear");
       createAssembledDirectory(ear)
          .addPath("/weld/mcandweld/ear/weldandmc");
-      createMcLib(ear, "/weld/mcandweld/mc/simple", SimpleBean.class);
+      createMcLib(ear, "/weld/mcandweld/mc/nobootstrap", SimpleBeanWithSimpleWebBean.class);
       createWeldLib(ear, "/weld/mcandweld/weld", SimpleWebBean.class);
       
       Deployment deployment = createVFSDeployment(ear);

Modified: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationTestCase.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationTestCase.java	2010-07-05 09:50:21 UTC (rev 106422)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/McIntegrationTestCase.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -114,7 +114,7 @@
       {
          public void runTest(BeanManager manager, DeploymentUnit unit) throws Exception
          {
-            assertInstanceOf(getControllerContext("SimpleBean"), WeldKernelControllerContext.class);
+            assertNotNull(getControllerContext("SimpleBean"));
             Object o = getBean("SimpleBean");
             assertNotNull(o);
             assertWebBean(manager, unit, SimpleWebBean.class.getName());

Added: trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/WeldBeanMetaDataBuilderPluginUnitTestCase.java
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/WeldBeanMetaDataBuilderPluginUnitTestCase.java	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/java/org/jboss/test/deployers/test/WeldBeanMetaDataBuilderPluginUnitTestCase.java	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,477 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.deployers.test;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestSuite;
+
+import org.jboss.beans.metadata.plugins.AbstractAnnotationMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractInstallMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.spi.AnnotationMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.InstallMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnitVisitor;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.weld.metadata.api.annotations.Weld;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.deployers.support.unit.McBeanWithConstructorAnnotation;
+import org.jboss.test.deployers.support.unit.McBeanWithInstallAnnotation;
+import org.jboss.test.deployers.support.unit.McBeanWithNoWeldAnnotations;
+import org.jboss.test.deployers.support.unit.McBeanWithPropertyAnnotation;
+import org.jboss.weld.integration.deployer.mc.WeldBeanMetaDataDeployerPlugin;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class WeldBeanMetaDataBuilderPluginUnitTestCase extends AbstractTestCaseWithSetup
+{
+   public WeldBeanMetaDataBuilderPluginUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static TestSuite suite()
+   {
+      return new TestSuite(WeldBeanMetaDataBuilderPluginUnitTestCase.class);
+   }
+   
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      return new WeldBeanMetaDataBuilderPluginTestDelegate(clazz);
+   }
+   
+   public void testNonWeldMcBeanMinimalMetaData()
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Test", McBeanWithNoWeldAnnotations.class.getName());
+      checkMcBean(builder.getBeanMetaData(), false);
+   }
+   
+   public void testNonWeldMcBeanMetaDataNoAnnotations()
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Test", McBeanWithNoWeldAnnotations.class.getName());
+      builder.addConstructorParameter(Object.class.getName(), "Test");
+      builder.addInstall("install");
+      builder.addPropertyMetaData("property", "Test");
+      checkMcBean(builder.getBeanMetaData(), false);
+   }
+   
+   public void testWeldMcBeanConstructorMetaDataAnnotation()
+   {
+      AbstractBeanMetaData bmd = new AbstractBeanMetaData("Test", McBeanWithNoWeldAnnotations.class.getName());
+      AbstractConstructorMetaData cmd = new AbstractConstructorMetaData();
+      AbstractParameterMetaData pmd = new AbstractParameterMetaData(Object.class.getName(), "Test");
+      cmd.setParameters(Collections.singletonList((ParameterMetaData)pmd));
+      cmd.setAnnotations(createWeldAnnotationMetaData());
+      bmd.setConstructor(cmd);
+      
+      checkMcBean(bmd, true);
+   }
+   
+   public void testWeldMcBeanInstallMetaDataAnnotation()
+   {
+      AbstractBeanMetaData bmd = new AbstractBeanMetaData("Test", McBeanWithNoWeldAnnotations.class.getName());
+      AbstractInstallMetaData imd = new AbstractInstallMetaData();
+      imd.setMethodName("install");
+      imd.setAnnotations(createWeldAnnotationMetaData());
+      bmd.setInstalls(Collections.singletonList((InstallMetaData)imd));
+      
+      checkMcBean(bmd, true);
+   }
+   
+   public void testWeldMcPropertyMetaDataAnnotation()
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Test", McBeanWithNoWeldAnnotations.class.getName());
+      builder.addPropertyMetaData("property", "Test");
+      builder.addPropertyAnnotation("property", "@" + Weld.class.getName());
+      
+      checkMcBean(builder.getBeanMetaData(), true);
+   }
+   
+   public void testWeldConstructorSourceAnnotation()
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Test", McBeanWithConstructorAnnotation.class.getName());
+      checkMcBean(builder.getBeanMetaData(), true);
+   }
+   
+   public void testWeldInstallSourceAnnotation()
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Test", McBeanWithInstallAnnotation.class.getName());
+      checkMcBean(builder.getBeanMetaData(), true);
+   }
+   
+   public void testWeldPropertySourceAnnotation()
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Test", McBeanWithPropertyAnnotation.class.getName());
+      checkMcBean(builder.getBeanMetaData(), true);
+   }
+   
+   private void checkMcBean(BeanMetaData bmd, boolean isWeld)
+   {
+      ControllerContext ctx = getPlugin().createContext(getController(), new MockDeploymentUnit(), bmd);
+      if (isWeld) 
+         assertNotNull(ctx);
+      else
+         assertNull(ctx);
+   }
+   
+   private Set<AnnotationMetaData> createWeldAnnotationMetaData()
+   {
+      AbstractAnnotationMetaData amd = new AbstractAnnotationMetaData();
+      amd.setAnnotation("@" + Weld.class.getName());
+      return Collections.singleton((AnnotationMetaData)amd);
+   }
+
+   private WeldBeanMetaDataBuilderPluginTestDelegate getMyDelegate()
+   {
+      return (WeldBeanMetaDataBuilderPluginTestDelegate)getDelegate();
+   }
+   
+   private Controller getController()
+   {
+      return getMyDelegate().kernel.getController();
+   }
+   
+   private WeldBeanMetaDataDeployerPlugin getPlugin()
+   {
+      return getMyDelegate().plugin;
+   }
+   
+   private static class WeldBeanMetaDataBuilderPluginTestDelegate extends AbstractTestDelegate
+   {
+      Kernel kernel;
+      WeldBeanMetaDataDeployerPlugin plugin;
+      
+      public WeldBeanMetaDataBuilderPluginTestDelegate(Class<?> clazz)
+      {
+         super(clazz);
+      }
+
+      @Override
+      public void setUp() throws Exception
+      {
+         super.setUp();
+         BasicBootstrap bootstrap = new BasicBootstrap();
+         bootstrap.run();
+         kernel = bootstrap.getKernel();
+         
+         plugin = new WeldBeanMetaDataDeployerPlugin();
+      }
+
+      @Override
+      public void tearDown() throws Exception
+      {
+         super.tearDown();
+      }
+   }
+
+   private class MockDeploymentUnit implements DeploymentUnit
+   {
+      public DeploymentUnit addComponent(String name)
+      {
+         return null;
+      }
+
+      public void addControllerContextName(Object name)
+      {
+      }
+
+      public void addIDependOn(DependencyItem dependency)
+      {
+      }
+
+      public boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException
+      {
+         return false;
+      }
+
+      public <T> Set<? extends T> getAllMetaData(Class<T> type)
+      {
+         return null;
+      }
+
+      public List<DeploymentUnit> getChildren()
+      {
+         return null;
+      }
+
+      public ClassLoader getClassLoader()
+      {
+         return Thread.currentThread().getContextClassLoader();
+      }
+
+      public DeploymentUnit getComponent(String name)
+      {
+         return null;
+      }
+
+      public List<DeploymentUnit> getComponents()
+      {
+         return null;
+      }
+
+      public Object getControllerContextName()
+      {
+         return null;
+      }
+
+      public Set<Object> getControllerContextNames()
+      {
+         return null;
+      }
+
+      public DependencyInfo getDependencyInfo()
+      {
+         return null;
+      }
+
+      public MainDeployer getMainDeployer()
+      {
+         return null;
+      }
+
+      public MetaData getMetaData()
+      {
+         return null;
+      }
+
+      public MutableMetaData getMutableMetaData()
+      {
+         return null;
+      }
+
+      public ScopeKey getMutableScope()
+      {
+         return null;
+      }
+
+      public String getName()
+      {
+         return "Test";
+      }
+
+      public DeploymentUnit getParent()
+      {
+         return null;
+      }
+
+      public String getRelativePath()
+      {
+         return null;
+      }
+
+      public DeploymentStage getRequiredStage()
+      {
+         return null;
+      }
+
+      public ClassLoader getResourceClassLoader()
+      {
+         return null;
+      }
+
+      public DeploymentResourceLoader getResourceLoader()
+      {
+         return null;
+      }
+
+      public ScopeKey getScope()
+      {
+         return null;
+      }
+
+      public String getSimpleName()
+      {
+         return null;
+      }
+
+      public DeploymentUnit getTopLevel()
+      {
+         return this;
+      }
+
+      public MutableAttachments getTransientManagedObjects()
+      {
+         return null;
+      }
+
+      public boolean isComponent()
+      {
+         return false;
+      }
+
+      public boolean isTopLevel()
+      {
+         return false;
+      }
+
+      public void removeClassLoader(ClassLoaderFactory factory)
+      {
+      }
+
+      public boolean removeComponent(String name)
+      {
+         return false;
+      }
+
+      public void removeControllerContextName(Object name)
+      {
+      }
+
+      public void removeIDependOn(DependencyItem dependency)
+      {
+      }
+
+      public void setMutableScope(ScopeKey key)
+      {
+      }
+
+      public void setRequiredStage(DeploymentStage stage)
+      {
+      }
+
+      public void setScope(ScopeKey key)
+      {
+      }
+
+      public void visit(DeploymentUnitVisitor visitor) throws DeploymentException
+      {
+      }
+
+      public Object addAttachment(String name, Object attachment)
+      {
+         return null;
+      }
+
+      public <T> T addAttachment(Class<T> type, T attachment)
+      {
+         return null;
+      }
+
+      public <T> T addAttachment(String name, T attachment, Class<T> expectedType)
+      {
+         return null;
+      }
+
+      public void clear()
+      {
+      }
+
+      public void clearChangeCount()
+      {
+      }
+
+      public int getChangeCount()
+      {
+         return 0;
+      }
+
+      public Object removeAttachment(String name)
+      {
+         return null;
+      }
+
+      public <T> T removeAttachment(Class<T> type)
+      {
+         return null;
+      }
+
+      public <T> T removeAttachment(String name, Class<T> expectedType)
+      {
+         return null;
+      }
+
+      public void setAttachments(Map<String, Object> map)
+      {
+      }
+
+      public Object getAttachment(String name)
+      {
+         return null;
+      }
+
+      public <T> T getAttachment(Class<T> type)
+      {
+         return null;
+      }
+
+      public <T> T getAttachment(String name, Class<T> expectedType)
+      {
+         return null;
+      }
+
+      public Map<String, Object> getAttachments()
+      {
+         return null;
+      }
+
+      public boolean hasAttachments()
+      {
+         return false;
+      }
+
+      public boolean isAttachmentPresent(String name)
+      {
+         if (name.equals("Test_WeldBootstrapBean_BeanMetaData"))
+            return true;
+         return false;
+      }
+
+      public boolean isAttachmentPresent(Class<?> type)
+      {
+         return false;
+      }
+
+      public boolean isAttachmentPresent(String name, Class<?> expectedType)
+      {
+         return false;
+      }
+      
+   }
+   
+}

Added: trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/MANIFEST.MF
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/MANIFEST.MF	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/MANIFEST.MF	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Created-By: hand

Added: trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/simple-beans.xml
===================================================================
--- trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/simple-beans.xml	                        (rev 0)
+++ trunk/weld-int/deployer-mc-int/src/test/resources/weld/mcandweld/mc/nobootstrap/META-INF/simple-beans.xml	2010-07-05 11:15:01 UTC (rev 106423)
@@ -0,0 +1,3 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+  <bean name="SimpleBean" class="org.jboss.test.deployers.support.nobootstrap.mc.SimpleBeanWithSimpleWebBean"/>
+</deployment>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list