Author: struberg
Date: Sat Apr 14 20:05:22 2018
New Revision: 1829165

URL: http://svn.apache.org/viewvc?rev=1829165&view=rev
Log:
OWB-1205 omit sending ProcessInjectionPoint when parsing Extension 

lifecycle observer methods.

ported back from OWB-2.0.x

Modified:
    openwebbeans/branches/owb_1.7.x/   (props changed)
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java

Propchange: openwebbeans/branches/owb_1.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Apr 14 20:05:22 2018
@@ -1 +1,2 @@
 /openwebbeans/branches/owb_1.2.x:1640945,1641609,1641684
+/openwebbeans/trunk:1803385

Modified: 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java?rev=1829165&r1=1829164&r2=1829165&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
 Sat Apr 14 20:05:22 2018
@@ -37,7 +37,9 @@ public class ContainerEventObserverMetho
     public ContainerEventObserverMethodImpl(final AbstractOwbBean<?> bean, 
final AnnotatedMethod<T> annotatedObserverMethod,
                                             final AnnotatedParameter<T> 
annotatedObservesParameter)
     {
-        super(bean, annotatedObserverMethod, annotatedObservesParameter);
+        // we do NOT fire any further events while building this 
ObserverMethod, e.g for ProcessInjectionPoint...
+        super(bean, annotatedObserverMethod, annotatedObservesParameter, 
false);
+
         WithAnnotations withAnnotationsAnn = 
annotatedObservesParameter.getAnnotation(WithAnnotations.class);
         if (withAnnotationsAnn != null)
         {

Modified: 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1829165&r1=1829164&r2=1829165&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
 Sat Apr 14 20:05:22 2018
@@ -24,7 +24,6 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -54,7 +53,6 @@ import org.apache.webbeans.container.Bea
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.WebBeansException;
-import org.apache.webbeans.inject.impl.InjectionPointFactory;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.proxy.OwbNormalScopeProxy;
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
@@ -87,7 +85,7 @@ public class ObserverMethodImpl<T> imple
     private static final Logger logger = 
WebBeansLoggerFacade.getLogger(ObserverMethodImpl.class);
 
     /**Observer owner bean that defines observer method*/
-    private final AbstractOwbBean<?> bean;
+    private final AbstractOwbBean<?> ownerBean;
 
     /**Using existing bean instance or not*/
     private final boolean ifExist;
@@ -125,12 +123,17 @@ public class ObserverMethodImpl<T> imple
 
     /**
      * used if the qualifiers and event type are already known, e.g. from the 
XML.
-     * @param bean
+     * @param ownerBean
      * @param annotatedObserverMethod
      */
-    public ObserverMethodImpl(AbstractOwbBean<?> bean, AnnotatedMethod<T> 
annotatedObserverMethod, AnnotatedParameter<T> annotatedObservesParameter)
+    public ObserverMethodImpl(AbstractOwbBean<?> ownerBean, AnnotatedMethod<T> 
annotatedObserverMethod, AnnotatedParameter<T> annotatedObservesParameter)
     {
-        this.bean = bean;
+        this(ownerBean, annotatedObserverMethod, annotatedObservesParameter, 
true);
+    }
+
+    protected ObserverMethodImpl(AbstractOwbBean<?> ownerBean, 
AnnotatedMethod<T> annotatedObserverMethod, AnnotatedParameter<T> 
annotatedObservesParameter, boolean fireEvent)
+    {
+        this.ownerBean = ownerBean;
         this.annotatedObservesParameter = annotatedObservesParameter;
         this.annotatedObserverMethod = annotatedObserverMethod;
         observedEventType = annotatedObservesParameter.getBaseType();
@@ -140,16 +143,16 @@ public class ObserverMethodImpl<T> imple
         observedQualifiers = new HashSet<Annotation>();
         for (Annotation annotation: 
annotatedObservesParameter.getAnnotations())
         {
-            if 
(bean.getWebBeansContext().getAnnotationManager().isQualifierAnnotation(annotation.annotationType()))
+            if 
(ownerBean.getWebBeansContext().getAnnotationManager().isQualifierAnnotation(annotation.annotationType()))
             {
                 observedQualifiers.add(annotation);
             }
         }
         
         final OpenWebBeansEjbPlugin ejbPlugin = 
getWebBeansContext().getPluginLoader().getEjbPlugin();
-        if (ejbPlugin != null && 
ejbPlugin.isNewSessionBean(bean.getBeanClass()))
+        if (ejbPlugin != null && 
ejbPlugin.isNewSessionBean(ownerBean.getBeanClass()))
         {
-            view = ejbPlugin.resolveViewMethod(bean , 
annotatedObserverMethod.getJavaMember());
+            view = ejbPlugin.resolveViewMethod(ownerBean , 
annotatedObserverMethod.getJavaMember());
         }
         else
         {
@@ -161,9 +164,7 @@ public class ObserverMethodImpl<T> imple
         {
             if (!parameter.isAnnotationPresent(Observes.class))
             {
-                Collection<Annotation> qualifierAnnots = 
getWebBeansContext().getAnnotationManager().getQualifierAnnotations(parameter.getAnnotations());
-
-                
injectionPoints.add(InjectionPointFactory.getPartialInjectionPoint(bean, 
parameter, qualifierAnnots));
+                
injectionPoints.add(getWebBeansContext().getInjectionPointFactory().buildInjectionPoint(ownerBean,
 parameter, fireEvent));
             }
         }
 
@@ -204,8 +205,8 @@ public class ObserverMethodImpl<T> imple
     @SuppressWarnings("unchecked")
     public void notify(T event, EventMetadata metadata)
     {
-        AbstractOwbBean<Object> component = (AbstractOwbBean<Object>) bean;
-        if (!bean.isEnabled())
+        AbstractOwbBean<Object> component = (AbstractOwbBean<Object>) 
ownerBean;
+        if (!ownerBean.isEnabled())
         {
             return;
         }
@@ -214,7 +215,7 @@ public class ObserverMethodImpl<T> imple
         
         List<ObserverParams> methodArgsMap = getMethodArguments(event, 
metadata);
         
-        BeanManagerImpl manager = 
bean.getWebBeansContext().getBeanManagerImpl();
+        BeanManagerImpl manager = 
ownerBean.getWebBeansContext().getBeanManagerImpl();
         CreationalContextImpl<Object> creationalContext = 
manager.createCreationalContext(component);
         if (metadata != null)
         {
@@ -258,7 +259,7 @@ public class ObserverMethodImpl<T> imple
                         return;
                     }
                     // this may happen if we try to e.g. send an event to a 
@ConversationScoped bean from a ServletListener
-                    logger.log(Level.INFO, OWBLogConst.INFO_0010, bean);
+                    logger.log(Level.INFO, OWBLogConst.INFO_0010, ownerBean);
                     return;
                 }
                 
@@ -296,7 +297,7 @@ public class ObserverMethodImpl<T> imple
                 {
                     if (!view.isAccessible())
                     {
-                        
bean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(view, 
true);
+                        
ownerBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(view,
 true);
                     }
 
                     if (Modifier.isPrivate(view.getModifiers()))
@@ -361,7 +362,7 @@ public class ObserverMethodImpl<T> imple
             param.instance = event;
             list.add(param);
         }
-        final WebBeansContext webBeansContext = bean.getWebBeansContext();
+        final WebBeansContext webBeansContext = ownerBean.getWebBeansContext();
         final BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
 
         for (InjectionPoint injectionPoint: injectionPoints)
@@ -411,7 +412,7 @@ public class ObserverMethodImpl<T> imple
     @SuppressWarnings("unchecked")
     public Class<?> getBeanClass()
     {
-        return bean.getBeanClass();
+        return ownerBean.getBeanClass();
     }
 
     /** 
@@ -454,7 +455,7 @@ public class ObserverMethodImpl<T> imple
 
     protected WebBeansContext getWebBeansContext()
     {
-        return bean.getWebBeansContext();
+        return ownerBean.getWebBeansContext();
     }
     
     /**

Modified: 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java?rev=1829165&r1=1829164&r2=1829165&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessInjectionPointTest.java
 Sat Apr 14 20:05:22 2018
@@ -20,6 +20,8 @@ import javax.enterprise.context.Dependen
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessInjectionPoint;
 import javax.inject.Inject;
@@ -30,6 +32,15 @@ import org.junit.Test;
 
 public class ProcessInjectionPointTest extends AbstractUnitTest
 {
+    @Test
+    public void testBeforeBeanDiscoveryMustNotTriggerProcessInjectionPoint()
+    {
+        addExtension(new TestExtension2());
+        startContainer(X.class);
+
+        TestExtension2 extensionBeanInstance = 
getInstance(TestExtension2.class);
+        Assert.assertNotNull(extensionBeanInstance);
+    }
 
     @Test
     public void testConsumerAScanning()
@@ -43,6 +54,9 @@ public class ProcessInjectionPointTest e
 
         Assert.assertFalse(extension.isBInjectionPointParsed());
         Assert.assertFalse(extension.isOtherInjectionPointParsed());
+
+        TestExtension extensionBeanInstance = getInstance(TestExtension.class);
+        Assert.assertNotNull(extensionBeanInstance);
     }
 
     @Test
@@ -110,11 +124,13 @@ public class ProcessInjectionPointTest e
         Assert.assertTrue(extension.isRawInstanceInjectionPointParsed());
     }
 
-    public interface SomeInterface {
+    public interface SomeInterface
+    {
         void doSomething();
     }
 
-    public static class SomeImpl implements SomeInterface {
+    public static class SomeImpl implements SomeInterface
+    {
         @Override
         public void doSomething()
         {
@@ -276,4 +292,21 @@ public class ProcessInjectionPointTest e
             return explicitInstanceInjectionPointParsed;
         }
     }
-}
+
+    public static class TestExtension2 implements Extension
+    {
+        void TestWeirdBeforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, 
BeanManager unusedBeanManager)
+        {
+            // all fine, this is just to test an old problem with firing
+            // ProcessInjectionPoint for Extension observers as well.
+            // Which created a problem because the Extensions are not yet 
ready.
+        }
+
+        void testExplicitInstance(@Observes ProcessInjectionPoint<?, ?> pip, 
BeanManager unusedBeanManager)
+        {
+            // nothing to do
+        }
+
+
+    }
+}
\ No newline at end of file


Reply via email to