Author: struberg
Date: Sat Apr 14 20:21:38 2018
New Revision: 1829167

URL: http://svn.apache.org/viewvc?rev=1829167&view=rev
Log:
OWB-1209 Custom alternative beans also need to get enabled

ported back from OWB-2.0.x

Added:
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/alternativebean/
      - copied from r1806330, 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/alternativebean/
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/tests/CustomAlternativeBeanTest.java
      - copied unchanged from r1806330, 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/tests/CustomAlternativeBeanTest.java
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/resources/org/apache/webbeans/test/alternatives/
      - copied from r1806330, 
openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/alternatives/
Modified:
    openwebbeans/branches/owb_1.7.x/   (props changed)
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
    
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java

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

Modified: 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java?rev=1829167&r1=1829166&r2=1829167&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
 Sat Apr 14 20:21:38 2018
@@ -151,16 +151,18 @@ public class AlternativesManager
         {
             return true;
         }
-        
-        for(Class<? extends Annotation> ann : stereotypes)
+
+        if (stereotypes != null && !stereotypes.isEmpty())
         {
-            if(configuredStereotypeAlternatives.contains(ann))
+            for (Class<? extends Annotation> ann : stereotypes)
             {
-                return true;
+                if (configuredStereotypeAlternatives.contains(ann))
+                {
+                    return true;
+                }
             }
         }
 
-
         return false;
     }
 

Modified: 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java?rev=1829167&r1=1829166&r2=1829167&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
 Sat Apr 14 20:21:38 2018
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.portable.events.discovery;
 
+import javax.annotation.Priority;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
@@ -80,6 +81,18 @@ public class AfterBeanDiscoveryImpl impl
             throw new IllegalStateException("Don't call 
AfterBeanDiscovery.addBean(bean) after the event is fired");
         }
 
+        if (bean.isAlternative() && 
!webBeansContext.getAlternativesManager().isAlternative(bean)
+            && !bean.getBeanClass().isAnnotationPresent(Priority.class))
+        {
+            // if the given Bean is an alternative, then at least one of the 
following
+            // conditions must be met:
+            // * Alternative is enabled via beans.xml
+            // * implements Prioritized
+            // * beanClass has a @Priority annotation
+            // , otherwise the bean is not active
+            return;
+        }
+
         AnnotatedType<?> annotatedType = 
webBeansContext.getAnnotatedElementFactory().newAnnotatedType(bean.getBeanClass());
 
         //Fire Event

Modified: 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java?rev=1829167&r1=1829166&r2=1829167&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java
 Sat Apr 14 20:21:38 2018
@@ -73,18 +73,27 @@ public abstract class AbstractUnitTest
         shutDownContainer();
     }
 
+    /**
+     * Start OWB with the given Classes but with just an empty beans.xml
+     */
     protected void startContainer(Class<?>... beanClasses)
     {
-        startContainer(new ArrayList<Class<?>>(Arrays.asList(beanClasses)), 
null);
+        startContainer(new ArrayList<>(Arrays.asList(beanClasses)), null);
     }
 
-    protected void startContainer(String beansXml, Class<?>... beanClasses)
+    /**
+     * Start up OWB with a beansXml file name and the given classes
+     */
+    protected void startContainer(String beansXmlResourceName, Class<?>... 
beanClasses)
     {
         List<String> beansXmls = new ArrayList<String>(1);
-        beansXmls.add(getXmlUrl(beansXml));
+        beansXmls.add(getXmlUrl(beansXmlResourceName));
         startContainer(new ArrayList<Class<?>>(Arrays.asList(beanClasses)), 
beansXmls);
     }
 
+    /**
+     * Start OWB with the given Classes but with just an empty beans.xml
+     */
     protected void startContainer(Collection<Class<?>> beanClasses)
     {
         startContainer(beanClasses, null);


Reply via email to