[jboss-cvs] JBossAS SVN: r71553 - in projects/microcontainer/trunk: aop-mc-int/src/main/org/jboss/aop/microcontainer/integration and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 1 09:21:14 EDT 2008


Author: alesj
Date: 2008-04-01 09:21:14 -0400 (Tue, 01 Apr 2008)
New Revision: 71553

Added:
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.xml
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ContainsIA.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SomeNonIA.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.java
Modified:
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jmx/JMX.java
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java
   projects/microcontainer/trunk/build/pom.xml
Log:
[JBMICROCONT-279] ignoring annotations marked with InstanceAnnotation.
TODO on tests, putting previous behavior back is uncommenting single line - see AOPConstructorJoinpoint.
Using JBoss-MDR snapshot.

Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jmx/JMX.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jmx/JMX.java	2008-04-01 12:58:46 UTC (rev 71552)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jmx/JMX.java	2008-04-01 13:21:14 UTC (rev 71553)
@@ -26,6 +26,8 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import org.jboss.metadata.spi.annotation.InstanceAnnotation;
+
 /**
  * A temporary home for this annotation interface
  * 
@@ -36,6 +38,7 @@
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
+ at InstanceAnnotation(false)
 public @interface JMX 
 {
    /**

Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java	2008-04-01 12:58:46 UTC (rev 71552)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java	2008-04-01 13:21:14 UTC (rev 71553)
@@ -21,7 +21,12 @@
 */
 package org.jboss.aop.microcontainer.integration;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 import org.jboss.aop.Advisor;
 import org.jboss.aop.AspectManager;
@@ -34,7 +39,10 @@
 import org.jboss.aop.proxy.container.GeneratedAOPProxyFactory;
 import org.jboss.joinpoint.plugins.BasicConstructorJoinPoint;
 import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.annotation.InstanceAnnotation;
 import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.CommonLevelsUtil;
+import org.jboss.metadata.spi.scope.ScopeLevel;
 import org.jboss.metadata.spi.signature.MethodSignature;
 import org.jboss.metadata.spi.stack.MetaDataStack;
 import org.jboss.reflect.spi.ClassInfo;
@@ -74,7 +82,7 @@
       MetaDataStack.mask();
       try
       {
-         boolean hasInstanceMetaData = hasInstanceOrJoinpointMetaData(metaData);
+         boolean hasInstanceMetaData = rootHasSubInstanceMetaData(metaData);
          ContainerCache cache = ContainerCache.initialise(manager, clazz, metaData, hasInstanceMetaData);
          AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
          Object target = createTarget(cache, params);
@@ -92,23 +100,35 @@
       }
    }
 
-   private boolean hasInstanceOrJoinpointMetaData(MetaData metaData)
+   /**
+    * Check for metadata at INSTANCE level and below.
+    *
+    * @param metaData the metadata
+    * @return true if there is some metadata that needs to be considered
+    */
+   private boolean rootHasSubInstanceMetaData(MetaData metaData)
    {
       if (metaData == null)
       {
          return false;
       }
 
-      if (hasMetaDataAtInstanceLevel(metaData))
+      if (checkForMetaDataAtSubInstanceLevel(metaData))
       {
          return true;
       }
       
       //Check for method annotations
-      return hasMethodMetaData(metaData);
+      return rootHasMethodWithSubInstanceMetaData(metaData);
    }
-   
-   private boolean hasMethodMetaData(MetaData metaData)
+      
+   /**
+    * Check for metadata at INSTANCE level and below for methods.
+    *
+    * @param metaData the metadata
+    * @return true if there is some metadata that needs to be considered
+    */
+   private boolean rootHasMethodWithSubInstanceMetaData(MetaData metaData)
    {
       //Check for method annotations
       ClassInfo info = constructorInfo.getDeclaringClass();
@@ -119,7 +139,7 @@
          {
             for (MethodInfo mi : methods)
             {
-               if (methodHasAnnotations(metaData, mi))
+               if (methodHasSubInstanceMetaData(metaData, mi))
                {
                   return true;
                }
@@ -130,32 +150,93 @@
       
       return false;
    }
-   
-   private boolean methodHasAnnotations(MetaData metaData, MethodInfo mi)
+
+   /**
+    * Check for metadata at INSTANCE level and below for methods.
+    *
+    * @param metaData the metadata
+    * @param mi the method to check
+    * @return true if there is some metadata that needs to be considered
+    */
+   private boolean methodHasSubInstanceMetaData(MetaData metaData, MethodInfo mi)
    {
       MethodSignature sig = new MethodSignature(mi);
       MetaData methodMD = metaData.getComponentMetaData(sig);
 
-      if (hasMetaDataAtInstanceLevel(methodMD))
+      if (checkForMetaDataAtSubInstanceLevel(methodMD))
       {
          return true;
       }
       return false;
    }
-   
-   private boolean hasMetaDataAtInstanceLevel(MetaData metaData)
+
+   /**
+    * Check for metadata at INSTANCE level and below.
+    *
+    * @param metaData the metadata
+    * @return true if there is some metadata that needs to be considered
+    */
+   private boolean checkForMetaDataAtSubInstanceLevel(MetaData metaData)
    {
       if (metaData != null)
       {
-         MetaData instanceMetaData = metaData.getScopeMetaData(CommonLevels.INSTANCE);
-         if (instanceMetaData != null && instanceMetaData.isEmpty() == false)
+         // TODO - remove this after making tests work again
+         // uncomment this for previous behavior
+         // List<ScopeLevel> levels = Collections.singletonList(CommonLevels.INSTANCE);
+         List<ScopeLevel> levels = CommonLevelsUtil.getSubLevels(CommonLevels.INSTANCE);
+         for (ScopeLevel level : levels)
          {
-            return true;  
+            if (hasMetaDataAtLevel(metaData, level))
+               return true;
          }
       }
       return false;
    }
-   
+
+   /**
+    * Check for metadata at level param.
+    *
+    * @param metaData the metadata
+    * @param level the scope level
+    * @return true if there is some metadata that needs to be considered
+    */
+   protected boolean hasMetaDataAtLevel(MetaData metaData, ScopeLevel level)
+   {
+      MetaData levelMetaData = metaData.getScopeMetaData(level);
+      if (levelMetaData != null && levelMetaData.isEmpty() == false)
+      {
+         Set<Object> checkSet = new HashSet<Object>();
+         Object[] allMetaData = levelMetaData.getMetaData();
+         Annotation[] annotations = levelMetaData.getAnnotations();
+         // all meta data is not null, since instance metadata is not empty
+         checkSet.addAll(Arrays.asList(allMetaData));
+         checkSet.removeAll(Arrays.asList(annotations));
+
+         // do we have something else than annotations
+         if (checkSet.isEmpty() == false)
+            return true;
+         else
+         {
+            // do we have an annotation that's not marked with IA
+            for (Annotation annotation : annotations)
+            {
+               InstanceAnnotation ia = annotation.annotationType().getAnnotation(InstanceAnnotation.class);
+               if (ia == null || ia.value())
+                  return true;
+            }
+         }
+      }
+      return false;
+   }
+
+   /**
+    * Create the target.
+    *
+    * @param cache the cache
+    * @param params the parameters
+    * @return target instance
+    * @throws Throwable for any error
+    */
    private Object createTarget(ContainerCache cache, AOPProxyFactoryParameters params) throws Throwable
    {
       Advisor advisor = cache.getAdvisor();
@@ -200,6 +281,12 @@
       return super.dispatch();
    }
 
+   /**
+    * Find constructor info.
+    *
+    * @param advisor the advisor
+    * @return matched constructor or null if no match
+    */
    private org.jboss.aop.ConstructorInfo findAopConstructorInfo(Advisor advisor)
    {
       org.jboss.aop.ConstructorInfo[] infos = advisor.getConstructorInfos();
@@ -212,7 +299,13 @@
       }
       return null;
    }
-   
+
+   /**
+    * Match constructor.
+    *
+    * @param ctor the constructor
+    * @return true if we have a match
+    */
    private boolean matchConstructor(Constructor<?> ctor)
    {
       TypeInfo[] params = constructorInfo.getParameterTypes();
@@ -236,5 +329,4 @@
       }
       return false;
    }
-
 }

Copied: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.xml (from rev 71479, projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXDecoratedTestCase.xml)
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.xml	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.xml	2008-04-01 13:21:14 UTC (rev 71553)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="Bean1" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+    <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="",exposedInterface=org.jboss.test.microcontainer.support.SimpleBean.class)</annotation>
+  </bean>
+
+  <bean name="Bean2" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+    <property name="property">
+      <annotation>@org.jboss.test.microcontainer.support.ContainsIA</annotation>
+      <value>123</value>
+    </property>
+  </bean>
+
+  <bean name="Bean3" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+    <annotation>@org.jboss.test.microcontainer.support.SomeNonIA</annotation>
+  </bean>
+
+  <bean name="Bean4" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+    <property name="property">
+      <annotation>@org.jboss.test.microcontainer.support.SomeNonIA</annotation>
+      <value>123</value>
+    </property>
+  </bean>
+
+  <bean name="Bean5" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+    <annotation>@org.jboss.test.microcontainer.support.ContainsIA</annotation>
+    <annotation>@org.jboss.test.microcontainer.support.SomeNonIA</annotation>
+  </bean>
+
+  <bean name="Bean6" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+    <property name="property">
+      <annotation>@org.jboss.test.microcontainer.support.SomeNonIA</annotation>
+      <annotation>@org.jboss.test.microcontainer.support.ContainsIA</annotation>
+      <value>123</value>
+    </property>
+  </bean>
+
+</deployment>

Modified: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java	2008-04-01 12:58:46 UTC (rev 71552)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java	2008-04-01 13:21:14 UTC (rev 71553)
@@ -21,11 +21,11 @@
 */
 package org.jboss.test.aop.junit;
 
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.test.AbstractTestCaseWithSetup;
 import org.jboss.test.AbstractTestDelegate;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
 
 /**
  * AbstractTypeTest.
@@ -71,10 +71,16 @@
       return getController().getContext(name, state);
    }
 
+   protected ControllerContext assertControllerContext(String name, ControllerState state) throws Throwable
+   {
+      ControllerContext context = getControllerContext(name, state);
+      assertNotNull(context);
+      return context;
+   }
+
    protected <T> T getBean(String name, Class<T> expectedType) throws Throwable
    {
-      ControllerContext context = getControllerContext(name);
-      assertNotNull(context);
+      ControllerContext context = assertControllerContext(name, null);
       Object target = context.getTarget();
       assertNotNull(target);
       return assertInstanceOf(target, expectedType);
@@ -88,4 +94,25 @@
          throw new IllegalArgumentException("No such context installed by name: " + name);
       return type;
    }
+
+   protected void assertIsProxy(Object name)
+   {
+      assertEquals(name + " is not proxy.", AbstractTypeTestDelegate.Type.PROXY, getType(name));
+   }
+
+   protected void assertIsPojo(Object name)
+   {
+      assertEquals(name + " is not pojo.", AbstractTypeTestDelegate.Type.POJO, getType(name));
+   }
+
+   protected void assertIsWoven(Object name)
+   {
+      assertEquals(name + " is not woven.", AbstractTypeTestDelegate.Type.WOVEN, getType(name));
+   }
+
+   protected void assertIsAspectized(Object name)
+   {
+      AbstractTypeTestDelegate.Type type = getType(name);
+      assertTrue(name + " is not aspectized.", AbstractTypeTestDelegate.Type.WOVEN == type || AbstractTypeTestDelegate.Type.PROXY == type);
+   }
 }

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ContainsIA.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ContainsIA.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/ContainsIA.java	2008-04-01 13:21:14 UTC (rev 71553)
@@ -0,0 +1,39 @@
+/*
+* 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.test.microcontainer.support;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+import org.jboss.metadata.spi.annotation.InstanceAnnotation;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE, ElementType.METHOD})
+ at InstanceAnnotation(false)
+public @interface ContainsIA
+{
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SomeNonIA.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SomeNonIA.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SomeNonIA.java	2008-04-01 13:21:14 UTC (rev 71553)
@@ -0,0 +1,36 @@
+/*
+* 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.test.microcontainer.support;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE, ElementType.METHOD})
+public @interface SomeNonIA
+{
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/HasInstanceAnnotationTestCase.java	2008-04-01 13:21:14 UTC (rev 71553)
@@ -0,0 +1,55 @@
+/*
+* 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.test.microcontainer.test;
+
+import junit.framework.Test;
+import org.jboss.test.aop.junit.AbstractTypeTest;
+
+/**
+ * Test instance annotations, do we require aop proxy for them.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class HasInstanceAnnotationTestCase extends AbstractTypeTest
+{
+   public HasInstanceAnnotationTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(HasInstanceAnnotationTestCase.class);
+   }
+
+   public void testInstanceAnnotation() throws Throwable
+   {
+      assertIsPojo("Bean1");
+      assertIsPojo("Bean2");
+
+      assertIsAspectized("Bean3");
+      assertIsAspectized("Bean4");
+
+      assertIsAspectized("Bean5");
+      assertIsAspectized("Bean6");
+   }
+}

Modified: projects/microcontainer/trunk/build/pom.xml
===================================================================
--- projects/microcontainer/trunk/build/pom.xml	2008-04-01 12:58:46 UTC (rev 71552)
+++ projects/microcontainer/trunk/build/pom.xml	2008-04-01 13:21:14 UTC (rev 71553)
@@ -41,7 +41,7 @@
     <version.javassist>3.7.1.GA</version.javassist>
     <version.jboss.aop>2.0.0.CR8</version.jboss.aop>
     <version.org.jboss.reflect>2.0.0.Beta12</version.org.jboss.reflect>
-    <version.org.jboss.mdr>2.0.0.Beta13</version.org.jboss.mdr>
+    <version.org.jboss.mdr>2.0.0-SNAPSHOT</version.org.jboss.mdr>
     <version.org.jboss.test>1.0.5.GA</version.org.jboss.test>
     <version.junit>4.4</version.junit>
     <version.jboss.profiler.jvmti>1.0.0.CR5</version.jboss.profiler.jvmti>




More information about the jboss-cvs-commits mailing list