You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2016/02/11 11:41:43 UTC

svn commit: r1729796 - in /openwebbeans/trunk: ./ webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/event/ webbeans-impl/src/main/java/org/apache/webbeans/util/ webbeans-impl/src/test/java/org/apach...

Author: struberg
Date: Thu Feb 11 10:41:43 2016
New Revision: 1729796

URL: http://svn.apache.org/viewvc?rev=1729796&view=rev
Log:
OWB-1102 OWB-1116 fix generics issue and ProcessBeanAttributes#veto()

There is still an issue left in the spec. But this must get clarified 
before we can fix it: https://issues.jboss.org/browse/CDI-581


Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeProcessBeanAttributesExtension.java
      - copied, changed from r1727751, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeExtension.java
Modified:
    openwebbeans/trunk/pom.xml
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/DisabledSpecializationTest.java

Modified: openwebbeans/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/pom.xml?rev=1729796&r1=1729795&r2=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/pom.xml (original)
+++ openwebbeans/trunk/pom.xml Thu Feb 11 10:41:43 2016
@@ -83,7 +83,7 @@
         <myfaces.version>2.0.23</myfaces.version>
         <xbean.version>4.3</xbean.version>
         <arquillian.version>1.1.2.Final</arquillian.version>
-        <cdi.tck.version>1.2.4.Final</cdi.tck.version>
+        <cdi.tck.version>1.2.8.Final</cdi.tck.version>
         <httpclient.version>4.2.1</httpclient.version>
     </properties>
     

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1729796&r1=1729795&r2=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java Thu Feb 11 10:41:43 2016
@@ -251,22 +251,22 @@ public class BeansDeployer
                 // Also configures deployments, interceptors, decorators.
                 deployFromXML(scanner);
 
-                SpecializationUtil specializationUtil = new SpecializationUtil(webBeansContext);
-                specializationUtil.removeDisabledTypes(annotatedTypesPerBda, null, true);
-
                 final Map<BeanArchiveInformation, Map<AnnotatedType<?>, ExtendedBeanAttributes<?>>> beanAttributesPerBda
                     = getBeanAttributes(annotatedTypesPerBda);
 
                 // shouldn't be used anymore, view is now beanAttributes
                 annotatedTypesPerBda.clear();
 
+                SpecializationUtil specializationUtil = new SpecializationUtil(webBeansContext);
+                specializationUtil.removeDisabledBeanAttributes(beanAttributesPerBda, null, true);
+
 
                 //Checking stereotype conditions
                 checkStereoTypes(scanner);
 
                 // Handle Specialization
-                specializationUtil.removeDisabledTypes(
-                        annotatedTypesPerBda,
+                specializationUtil.removeDisabledBeanAttributes(
+                        beanAttributesPerBda,
                         new SpecializationUtil.BeanAttributesProvider()
                         {
                             @Override
@@ -1717,7 +1717,7 @@ public class BeansDeployer
         webBeansContext.getWebBeansUtil().setInjectionTargetBeanEnableFlag(bean);
     }
 
-    private static class ExtendedBeanAttributes<T>
+    public static class ExtendedBeanAttributes<T>
     {
         private final BeanAttributes<T> beanAttributes;
         private final boolean isEjb;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1729796&r1=1729795&r2=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java Thu Feb 11 10:41:43 2016
@@ -531,7 +531,7 @@ public final class NotificationManager
             if(checkEventTypeParameterForExtensions(beanClass, actualArgs[0])
                     && (secondParam == null || actualArgs.length == 1
                             || checkEventTypeParameterForExtensions(secondParam, actualArgs[1])
-                            || GenericsUtil.isAssignableFrom(false, false, actualArgs[1], secondParam)))
+                            || GenericsUtil.isAssignableFrom(true, false, actualArgs[1], secondParam)))
             {
                 addToMatching(type, matching);   
             }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java?rev=1729796&r1=1729795&r2=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java Thu Feb 11 10:41:43 2016
@@ -194,6 +194,14 @@ public final class GenericsUtil
         {
             return false; //raw types don't match
         }
+
+        if (isDelegateOrEvent)
+        {
+            // for delegate and events we match 'in reverse' kind off
+            // @Observes ProcessInjectionPoint<?, Instance> does also match Instance<SomeBean>
+            return isAssignableFrom(true, injectionPointType, beanType.getRawType());
+        }
+
         for (Type typeArgument: beanType.getActualTypeArguments())
         {
             if (typeArgument == Object.class)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java?rev=1729796&r1=1729795&r2=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java Thu Feb 11 10:41:43 2016
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.webbeans.config.BeansDeployer;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
@@ -64,16 +65,21 @@ public class SpecializationUtil
     }
 
     /**
+     * This method iterates over all given BeanAttributes and removes those which are 'Specialised away'.
+     * This methods gets invoked twice.
+     * The first pass is over the plain scanned classes.
+     * The second pass is for any specialised producer fields and methods.
+     * We need to do this twice as producers of 'disabled beans' must not get taken into consideration.
      *
-     * @param annotatedTypesPerBda all annotatypes sliced by BDA
-     * @param attributeProvider if not null provides bean attributes to be able to validate types contains superclass
+     * @param beanAttributesPerBda all annotatypes sliced by BDA
+     * @param attributeProvider if not null provides bean attributes to be able to validate types contains superclass. Needed for producers.
      * @param notSpecializationOnly first pass/2nd pass. First one removes only root beans, second one handles inheritance even in @Spe
      */
-    public void removeDisabledTypes( Map<BeanArchiveService.BeanArchiveInformation, List<AnnotatedType<?>>> annotatedTypesPerBda,
-                                    BeanAttributesProvider attributeProvider,
-                                    boolean notSpecializationOnly)
+    public void removeDisabledBeanAttributes(Map<BeanArchiveService.BeanArchiveInformation, Map<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>>> beanAttributesPerBda,
+                                             BeanAttributesProvider attributeProvider,
+                                             boolean notSpecializationOnly)
     {
-        Set<AnnotatedType<?>> allAnnotatedTypes = getAllAnnotatedTypes(annotatedTypesPerBda);
+        Set<AnnotatedType<?>> allAnnotatedTypes = getAllAnnotatedTypes(beanAttributesPerBda);
 
         if (allAnnotatedTypes != null && !allAnnotatedTypes.isEmpty())
         {
@@ -162,32 +168,34 @@ public class SpecializationUtil
             }
 
             // and now remove all AnnotatedTypes of those collected disabledClasses
-            removeAllDisabledClasses(annotatedTypesPerBda, disabledClasses);
+            removeAllDisabledClasses(beanAttributesPerBda, disabledClasses);
         }
     }
 
-    private void removeAllDisabledClasses(Map<BeanArchiveService.BeanArchiveInformation, List<AnnotatedType<?>>> annotatedTypesPerBda, Set<Class<?>> disabledClasses)
+    private void removeAllDisabledClasses(Map<BeanArchiveService.BeanArchiveInformation, Map<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>>> beanAttributesPerBda,
+                                          Set<Class<?>> disabledClasses)
     {
-        for (List<AnnotatedType<?>> annotatedTypes : annotatedTypesPerBda.values())
+        for (Map<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>> beanAttributeMap : beanAttributesPerBda.values())
         {
-            Iterator<AnnotatedType<?>> annotatedTypeIterator = annotatedTypes.iterator();
-            while (annotatedTypeIterator.hasNext())
+            Iterator<Map.Entry<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>>> beanAttributeEntryIterator = beanAttributeMap.entrySet().iterator();
+            while (beanAttributeEntryIterator.hasNext())
             {
-                AnnotatedType<?> annotatedType = annotatedTypeIterator.next();
-                if (disabledClasses.contains(annotatedType.getJavaClass()))
+                Map.Entry<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>> beanAttributesEntry = beanAttributeEntryIterator.next();
+                if (disabledClasses.contains(beanAttributesEntry.getKey().getJavaClass()))
                 {
-                    annotatedTypeIterator.remove();
+                    beanAttributeEntryIterator.remove();
                 }
             }
         }
     }
 
-    private Set<AnnotatedType<?>> getAllAnnotatedTypes(Map<BeanArchiveService.BeanArchiveInformation, List<AnnotatedType<?>>> annotatedTypesPerBda)
+    private Set<AnnotatedType<?>> getAllAnnotatedTypes(
+        Map<BeanArchiveService.BeanArchiveInformation, Map<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>>> beanAttributesPerBda)
     {
-        Set<AnnotatedType<?>> allAnnotatedTypes = new HashSet<AnnotatedType<?>>(annotatedTypesPerBda.size()*50);
-        for (List<AnnotatedType<?>> annotatedTypes : annotatedTypesPerBda.values())
+        Set<AnnotatedType<?>> allAnnotatedTypes = new HashSet<AnnotatedType<?>>(beanAttributesPerBda.size()*50);
+        for (Map<AnnotatedType<?>, BeansDeployer.ExtendedBeanAttributes<?>> annotatedTypeMap : beanAttributesPerBda.values())
         {
-            allAnnotatedTypes.addAll(annotatedTypes);
+            allAnnotatedTypes.addAll(annotatedTypeMap.keySet());
         }
         return allAnnotatedTypes;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java?rev=1729796&r1=1729795&r2=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java Thu Feb 11 10:41:43 2016
@@ -18,6 +18,7 @@ package org.apache.webbeans.test.events.
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.Typed;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessInjectionPoint;
@@ -58,6 +59,68 @@ public class ProcessInjectionPointTest e
         Assert.assertFalse(extension.isOtherInjectionPointParsed());
     }
 
+    @Test
+    public void testConsumerInterfaceScanning()
+    {
+        TestExtension extension = new TestExtension();
+        addExtension(extension);
+        startContainer(SomeInterface.class, SomeImpl.class, ConsumerInterface.class);
+
+        Assert.assertFalse(extension.isXInjectionPointParsed());
+        Assert.assertFalse(extension.isAInjectionPointParsed());
+        Assert.assertFalse(extension.isBInjectionPointParsed());
+        Assert.assertFalse(extension.isOtherInjectionPointParsed());
+
+        Assert.assertTrue(extension.isInterfaceInjectionPointParsed());
+        Assert.assertFalse(extension.isImplInjectionPointParsed());
+    }
+
+    @Test
+    public void testConsumerImplScanning()
+    {
+        TestExtension extension = new TestExtension();
+        addExtension(extension);
+        startContainer(SomeInterface.class, SomeImpl.class, ConsumerImpl.class);
+
+        Assert.assertFalse(extension.isXInjectionPointParsed());
+        Assert.assertFalse(extension.isAInjectionPointParsed());
+        Assert.assertFalse(extension.isBInjectionPointParsed());
+        Assert.assertFalse(extension.isOtherInjectionPointParsed());
+
+        Assert.assertTrue(extension.isInterfaceInjectionPointParsed());
+        Assert.assertTrue(extension.isImplInjectionPointParsed());
+    }
+
+    @Test
+    public void testConsumerRawInstanceScanning()
+    {
+        TestExtension extension = new TestExtension();
+        addExtension(extension);
+        startContainer(SomeInterface.class, SomeImpl.class, ConsumerRawInstance.class);
+
+        Assert.assertFalse(extension.isXInjectionPointParsed());
+        Assert.assertFalse(extension.isAInjectionPointParsed());
+        Assert.assertFalse(extension.isBInjectionPointParsed());
+        Assert.assertFalse(extension.isOtherInjectionPointParsed());
+        Assert.assertFalse(extension.isInterfaceInjectionPointParsed());
+        Assert.assertFalse(extension.isImplInjectionPointParsed());
+
+        Assert.assertTrue(extension.isWildcardInstanceInjectionPointParsed());
+        Assert.assertTrue(extension.isExplicitInstanceInjectionPointParsed());
+        Assert.assertTrue(extension.isRawInstanceInjectionPointParsed());
+    }
+
+    public interface SomeInterface {
+        void doSomething();
+    }
+
+    public static class SomeImpl implements SomeInterface {
+        @Override
+        public void doSomething()
+        {
+            // nop
+        }
+    }
 
     @Dependent
     public static class X
@@ -90,12 +153,36 @@ public class ProcessInjectionPointTest e
         private @Inject B b;
     }
 
+    @Dependent
+    public static class ConsumerInterface
+    {
+        private @Inject SomeInterface someInterface;
+    }
+
+    @Dependent
+    public static class ConsumerImpl
+    {
+        private @Inject SomeImpl someImpl;
+    }
+
+    @Dependent
+    public static class ConsumerRawInstance
+    {
+        private @Inject Instance<SomeImpl> someImplInstance;
+    }
+
+
     public static class TestExtension implements Extension
     {
         private boolean xInjectionPointParsed = false;
         private boolean aInjectionPointParsed = false;
         private boolean bInjectionPointParsed = false;
         private boolean otherInjectionPointParsed = false;
+        private boolean interfaceInjectionPointParsed = false;
+        private boolean implInjectionPointParsed = false;
+        private boolean rawInstanceInjectionPointParsed = false;
+        private boolean wildcardInstanceInjectionPointParsed = false;
+        private boolean explicitInstanceInjectionPointParsed = false;
 
         void testX(@Observes ProcessInjectionPoint<?, X> pip)
         {
@@ -117,6 +204,31 @@ public class ProcessInjectionPointTest e
             otherInjectionPointParsed = true;
         }
 
+        void testInterface(@Observes ProcessInjectionPoint<?, SomeInterface> pip)
+        {
+            interfaceInjectionPointParsed = true;
+        }
+
+        void testImpl(@Observes ProcessInjectionPoint<?, SomeImpl> pip)
+        {
+            implInjectionPointParsed = true;
+        }
+
+        void testRawInstance(@Observes ProcessInjectionPoint<?, Instance> pip)
+        {
+            rawInstanceInjectionPointParsed = true;
+        }
+
+        void testRawInstanceWithWildCard(@Observes ProcessInjectionPoint<?, Instance<?>> pip)
+        {
+            wildcardInstanceInjectionPointParsed = true;
+        }
+
+        void testExplicitInstance(@Observes ProcessInjectionPoint<?, Instance<SomeImpl>> pip)
+        {
+            explicitInstanceInjectionPointParsed = true;
+        }
+
 
         public boolean isXInjectionPointParsed()
         {
@@ -138,5 +250,30 @@ public class ProcessInjectionPointTest e
         {
             return otherInjectionPointParsed;
         }
+
+        public boolean isInterfaceInjectionPointParsed()
+        {
+            return interfaceInjectionPointParsed;
+        }
+
+        public boolean isImplInjectionPointParsed()
+        {
+            return implInjectionPointParsed;
+        }
+
+        public boolean isRawInstanceInjectionPointParsed()
+        {
+            return rawInstanceInjectionPointParsed;
+        }
+
+        public boolean isWildcardInstanceInjectionPointParsed()
+        {
+            return wildcardInstanceInjectionPointParsed;
+        }
+
+        public boolean isExplicitInstanceInjectionPointParsed()
+        {
+            return explicitInstanceInjectionPointParsed;
+        }
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/DisabledSpecializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/DisabledSpecializationTest.java?rev=1729796&r1=1729795&r2=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/DisabledSpecializationTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/DisabledSpecializationTest.java Thu Feb 11 10:41:43 2016
@@ -30,11 +30,22 @@ public class DisabledSpecializationTest
 {
 
     @Test
-    public void testSpecialization() throws Exception{
+    public void testSpecializationPatVeto() throws Exception{
         addExtension(new VetoMeExtension());
         startContainer(LoginService.class, MockLoginService.class);
 
         LoginService loginService = getInstance(LoginService.class);
+        Assert.assertNotNull(loginService);
+
+        Assert.assertFalse(loginService.login("dummy"));
+    }
+
+    @Test
+    public void testSpecializationPbaVeto() throws Exception{
+        addExtension(new VetoMeProcessBeanAttributesExtension());
+        startContainer(LoginService.class, MockLoginService.class);
+
+        LoginService loginService = getInstance(LoginService.class);
         Assert.assertNotNull(loginService);
 
         Assert.assertFalse(loginService.login("dummy"));

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeProcessBeanAttributesExtension.java (from r1727751, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeExtension.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeProcessBeanAttributesExtension.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeProcessBeanAttributesExtension.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeExtension.java&r1=1727751&r2=1729796&rev=1729796&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeExtension.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/specalization/disabledspecialization/VetoMeProcessBeanAttributesExtension.java Thu Feb 11 10:41:43 2016
@@ -20,18 +20,19 @@ package org.apache.webbeans.test.specali
 
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.ProcessBeanAttributes;
 
 /**
  * A CDI Extension which handles the {@link VetoMe} annotations.
+ * But via ProcessBeanAttributes
  */
-public class VetoMeExtension implements Extension
+public class VetoMeProcessBeanAttributesExtension implements Extension
 {
-    public void vetoTheBeans(@Observes ProcessAnnotatedType pat)
+    public void vetoTheBeans(@Observes ProcessBeanAttributes pba)
     {
-        if (pat.getAnnotatedType().isAnnotationPresent(VetoMe.class))
+        if (pba.getAnnotated().isAnnotationPresent(VetoMe.class))
         {
-            pat.veto();
+            pba.veto();
         }
     }
 }