openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1817306 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/inject/ webbeans-impl/src/main/ja...
Date Wed, 06 Dec 2017 15:59:13 GMT
Author: struberg
Date: Wed Dec  6 15:59:13 2017
New Revision: 1817306

URL: http://svn.apache.org/viewvc?rev=1817306&view=rev
Log:
OWB-1171 enable alternative Stereotypes with @Priority on class

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative3.java
      - copied, changed from r1817226, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/OriginalBean.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/SomeInterface.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/tests/AlternativeInstanceTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/strict/AlternativesTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative1.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
Wed Dec  6 15:59:13 2017
@@ -581,7 +581,10 @@ public abstract class BeanAttributesBuil
     // these alternatives can be not activated
     protected void defineAlternative()
     {
-        alternative = alternative == null || !alternative ? WebBeansUtil.isAlternative(annotated,
stereotypes) : alternative;
+        if (alternative == null)
+        {
+            alternative = WebBeansUtil.isAlternative(annotated, stereotypes);
+        }
     }
 
 

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=1817306&r1=1817305&r2=1817306&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
Wed Dec  6 15:59:13 2017
@@ -450,8 +450,7 @@ public class BeansDeployer
                     {
                         BeanAttributesImpl beanAttributes = BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(at,
onlyScopedBeans).build();
                         if (beanAttributes != null &&
-                                (!beanAttributes.isAlternative() || webBeansContext.getAlternativesManager()
-                                        .isAlternative(at.getJavaClass(), beanAttributes.getStereotypes())))
+                                (!beanAttributes.isAlternative() || isEnabledAlternative(at,
beanAttributes.getStereotypes())))
                         {
                             ProcessBeanAttributesImpl<?> processBeanAttributes
                                 = webBeansContext.getWebBeansUtil().fireProcessBeanAttributes(at,
at.getJavaClass(), beanAttributes);
@@ -492,6 +491,28 @@ public class BeansDeployer
         return beanAttributesPerBda;
     }
 
+    private boolean isEnabledAlternative(AnnotatedType<?> at, Set<Class<? extends
Annotation>> stereotypes)
+    {
+        AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
+
+        if (alternativesManager.isAlternative(at.getJavaClass(), stereotypes))
+        {
+            return true;
+        }
+        if (stereotypes != null && !stereotypes.isEmpty() && at.getAnnotations(Priority.class)
!= null)
+        {
+            for (Class<? extends Annotation> stereotype : stereotypes)
+            {
+                if (alternativesManager.isAlternativeStereotype(stereotype))
+                {
+                    return true;
+                }
+            }
+
+        }
+        return false;
+    }
+
     private void validateDisposeParameters()
     {
         WebBeansUtil webBeansUtil = webBeansContext.getWebBeansUtil();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
Wed Dec  6 15:59:13 2017
@@ -19,8 +19,10 @@
 package org.apache.webbeans.inject;
 
 import java.lang.annotation.Annotation;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.annotation.Priority;
@@ -67,6 +69,13 @@ public class AlternativesManager
      */
     private final Set<Class<? extends Annotation>> configuredStereotypeAlternatives
= new HashSet<>();
 
+    /**
+     * Contains all Alternative Stereotypes which are NOT enabled via beans.xml
+     * We need those for classes which  have a @Priority.
+     */
+    private final Map<Class<? extends Annotation>, Boolean> notEnabledStereotypeAlternatives
= new HashMap<>();
+
+
     private final PriorityClasses priorityAlternatives = new PriorityClasses();
 
     public AlternativesManager(WebBeansContext webBeansContext)
@@ -192,11 +201,24 @@ public class AlternativesManager
         return configuredAlternatives;
     }
 
+    public boolean isAlternativeStereotype(Class<? extends Annotation> stereo)
+    {
+        Boolean isAlternative = notEnabledStereotypeAlternatives.get(stereo);
+        if (isAlternative == null)
+        {
+            isAlternative = AnnotationUtil.hasClassAnnotation(stereo, Alternative.class);
+            notEnabledStereotypeAlternatives.putIfAbsent(stereo, isAlternative);
+        }
+
+        return isAlternative;
+    }
+
     public void clear()
     {
         configuredAlternatives.clear();
         configuredStereotypeAlternatives.clear();
         priorityAlternatives.clear();
+        notEnabledStereotypeAlternatives.clear();
     }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Wed Dec  6 15:59:13 2017
@@ -1143,8 +1143,29 @@ public final class WebBeansUtil
     public boolean isBeanEnabled(AnnotatedType<?> at, Set<Class<? extends Annotation>>
stereotypes)
     {
         boolean isAlternative = isAlternative(at, stereotypes);
+        if (!isAlternative)
+        {
+            return true;
+        }
+
+        AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
+        if (alternativesManager.isAlternative(at.getJavaClass(), stereotypes))
+        {
+            return true;
+        }
+        if (stereotypes != null && !stereotypes.isEmpty() && at.getAnnotation(Priority.class)
!= null)
+        {
+            for (Class<? extends Annotation> stereotype : stereotypes)
+            {
+                if (alternativesManager.isAlternativeStereotype(stereotype))
+                {
+                    return true;
+                }
+            }
+
+        }
+        return false;
 
-        return !isAlternative || webBeansContext.getAlternativesManager().isAlternative(at.getJavaClass(),
stereotypes);
     }
 
     public static boolean isAlternative(Annotated annotated, Set<Class<? extends Annotation>>
stereotypes)

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/tests/AlternativeInstanceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/tests/AlternativeInstanceTest.java?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/tests/AlternativeInstanceTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/concepts/alternatives/tests/AlternativeInstanceTest.java
Wed Dec  6 15:59:13 2017
@@ -43,13 +43,7 @@ public class AlternativeInstanceTest ext
     @Test
     public void testAlternativeDisabled()
     {
-        Collection<String> beanXmls = new ArrayList<String>();
-        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(SimpleBean.class);
-        beanClasses.add(AlternativeBean.class);
-        beanClasses.add(SimpleInjectionTarget.class);
-
-        startContainer(beanClasses, beanXmls);
+        startContainer(SimpleBean.class, AlternativeBean.class, SimpleInjectionTarget.class);
 
         Bean<?> simpleInjectionTargetBean = getBeanManager().getBeans(SimpleInjectionTarget.class).iterator().next();
         CreationalContext<?> context = getBeanManager().createCreationalContext(simpleInjectionTargetBean);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/strict/AlternativesTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/strict/AlternativesTest.java?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/strict/AlternativesTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/strict/AlternativesTest.java
Wed Dec  6 15:59:13 2017
@@ -21,6 +21,10 @@ package org.apache.webbeans.test.unittes
 
 import javax.enterprise.inject.spi.Bean;
 
+import org.apache.webbeans.test.xml.strict.Alternative3;
+import org.apache.webbeans.test.xml.strict.AlternativeStereotype;
+import org.apache.webbeans.test.xml.strict.OriginalBean;
+import org.apache.webbeans.test.xml.strict.SomeInterface;
 import org.junit.Assert;
 
 import org.apache.webbeans.config.WebBeansContext;
@@ -50,6 +54,16 @@ public class AlternativesTest extends Ab
         manager.clear();
         
     }
+
+    @Test
+    public void testPriorityEnabledStereotypeAlternative()
+    {
+        startContainer(Alternative3.class, AlternativeStereotype.class, OriginalBean.class);
+
+        SomeInterface instance = getInstance(SomeInterface.class);
+        Assert.assertNotNull(instance);
+        Assert.assertTrue(instance instanceof Alternative3);
+    }
     
     @Test(expected=WebBeansConfigurationException.class)
     public void testDoubleAlternativeClass()
@@ -86,5 +100,5 @@ public class AlternativesTest extends Ab
     {        
         startContainer("org/apache/webbeans/test/xml/strict/alternatives_failed6.xml");
     }
-    
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative1.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative1.java?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative1.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative1.java
Wed Dec  6 15:59:13 2017
@@ -21,7 +21,7 @@ package org.apache.webbeans.test.xml.str
 import javax.enterprise.inject.Alternative;
 
 @Alternative
-public class Alternative1
+public class Alternative1 implements SomeInterface
 {
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java
Wed Dec  6 15:59:13 2017
@@ -19,7 +19,7 @@
 package org.apache.webbeans.test.xml.strict;
 
 @AlternativeStereotype
-public class Alternative2
+public class Alternative2 implements SomeInterface
 {
 
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative3.java
(from r1817226, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative3.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative3.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java&r1=1817226&r2=1817306&rev=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative2.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/Alternative3.java
Wed Dec  6 15:59:13 2017
@@ -18,8 +18,11 @@
  */
 package org.apache.webbeans.test.xml.strict;
 
+import javax.annotation.Priority;
+
 @AlternativeStereotype
-public class Alternative2
+@Priority(1000)
+public class Alternative3 implements SomeInterface
 {
 
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/OriginalBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/OriginalBean.java?rev=1817306&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/OriginalBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/OriginalBean.java
Wed Dec  6 15:59:13 2017
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.test.xml.strict;
+
+public class OriginalBean implements SomeInterface
+{
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/OriginalBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/SomeInterface.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/SomeInterface.java?rev=1817306&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/SomeInterface.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/SomeInterface.java
Wed Dec  6 15:59:13 2017
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.test.xml.strict;
+
+public interface SomeInterface
+{
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/strict/SomeInterface.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1817306&r1=1817305&r2=1817306&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Wed Dec  6 15:59:13 2017
@@ -18,7 +18,7 @@
 <suite name="JSR-346-TCK" verbose="2" configfailurepolicy="continue">
   <test name="JSR-346 TCK">
     <classes>
-          <class name="org.jboss.cdi.tck.tests.event.broken.raw.RawEventDisposerInjectionTest"
/>
+          <class name="org.jboss.cdi.tck.tests.alternative.selection.stereotype.SelectedBeanWithUnselectedStereotypeTest"
/>
       <!--
 
       <class name="org.jboss.cdi.tck.tests.event.parameterized.ParameterizedEventTest"
/>



Mime
View raw message