You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2015/04/09 23:33:23 UTC
svn commit: r1672497 - in /openwebbeans/trunk:
webbeans-arquillian/owb-arquillian-standalone/ webbeans-clustering/
webbeans-impl/src/main/java/org/apache/webbeans/config/
webbeans-impl/src/main/java/org/apache/webbeans/container/
webbeans-impl/src/test...
Author: rmannibucau
Date: Thu Apr 9 21:33:23 2015
New Revision: 1672497
URL: http://svn.apache.org/r1672497
Log:
handling @Priority for producers
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/priority/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/priority/AlternativeWithBeanAndMethodProducerPriorityTest.java
Modified:
openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/pom.xml
openwebbeans/trunk/webbeans-clustering/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/container/InjectionResolver.java
openwebbeans/trunk/webbeans-web/pom.xml
Modified: openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/pom.xml?rev=1672497&r1=1672496&r2=1672497&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/pom.xml (original)
+++ openwebbeans/trunk/webbeans-arquillian/owb-arquillian-standalone/pom.xml Thu Apr 9 21:33:23 2015
@@ -49,6 +49,11 @@
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.2_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<scope>provided</scope>
</dependency>
Modified: openwebbeans/trunk/webbeans-clustering/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-clustering/pom.xml?rev=1672497&r1=1672496&r2=1672497&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-clustering/pom.xml (original)
+++ openwebbeans/trunk/webbeans-clustering/pom.xml Thu Apr 9 21:33:23 2015
@@ -34,6 +34,11 @@
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.2_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
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=1672497&r1=1672496&r2=1672497&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 Apr 9 21:33:23 2015
@@ -1541,6 +1541,8 @@ public class BeansDeployer
Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods =
new HashMap<ProducerMethodBean<?>, AnnotatedMethod<?>>();
+ final Priority priority = annotatedType.getAnnotation(Priority.class);
+
for(ProducerMethodBean<?> producerMethod : producerMethods)
{
AnnotatedMethod<?> method = webBeansContext.getAnnotatedElementFactory().newAnnotatedMethod(producerMethod.getCreatorMethod(), annotatedType);
@@ -1548,6 +1550,10 @@ public class BeansDeployer
+ "ProducerMethods. Look at logs for further details");
annotatedMethods.put(producerMethod, method);
+ if (priority != null)
+ {
+ webBeansContext.getAlternativesManager().addPriorityClazzAlternative(method.getJavaMember().getReturnType(), priority);
+ }
}
Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields =
@@ -1562,6 +1568,10 @@ public class BeansDeployer
webBeansContext.getAnnotatedElementFactory().newAnnotatedField(
producerField.getCreatorField(),
webBeansContext.getAnnotatedElementFactory().newAnnotatedType(producerField.getBeanClass())));
+ if (priority != null)
+ {
+ webBeansContext.getAlternativesManager().addPriorityClazzAlternative(producerField.getCreatorField().getType(), priority);
+ }
}
Map<ObserverMethod<?>,AnnotatedMethod<?>> observerMethodsMap =
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1672497&r1=1672496&r2=1672497&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java Thu Apr 9 21:33:23 2015
@@ -568,7 +568,8 @@ public class InjectionResolver
{
for (Bean<? extends X> bean: beans)
{
- if (alternativeClazz.equals(bean.getBeanClass()))
+ final Class<?> type = OwbBean.class.isInstance(bean) ? OwbBean.class.cast(bean) .getReturnType() : bean.getBeanClass();
+ if (alternativeClazz.equals(type))
{
return new SingleItemSet<Bean<? extends X>>(bean);
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/priority/AlternativeWithBeanAndMethodProducerPriorityTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/priority/AlternativeWithBeanAndMethodProducerPriorityTest.java?rev=1672497&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/priority/AlternativeWithBeanAndMethodProducerPriorityTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/priority/AlternativeWithBeanAndMethodProducerPriorityTest.java Thu Apr 9 21:33:23 2015
@@ -0,0 +1,70 @@
+/*
+ * 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.priority;
+
+import org.apache.webbeans.component.ProducerMethodBean;
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.Vetoed;
+
+import static org.junit.Assert.assertTrue;
+
+public class AlternativeWithBeanAndMethodProducerPriorityTest extends AbstractUnitTest
+{
+ @Test
+ public void run()
+ {
+ startContainer(Prod.class, Injected1.class, Injected2.class, Injected3.class);
+ assertTrue(ProducerMethodBean.class.isInstance(getBean(Injected1.class)));
+ }
+
+ @Priority(2001)
+ public static class Prod {
+ @Produces
+ @Alternative
+ public Injected1 getGreeting()
+ {
+ return new Injected1() {};
+ }
+ }
+
+ @Vetoed
+ public static class Injected1
+ {
+ // nothing
+ }
+
+ @Priority(1999)
+ @Alternative
+ public static class Injected2 extends Injected1
+ {
+ // nothing
+ }
+
+ @Priority(2000)
+ @Alternative
+ public static class Injected3 extends Injected1
+ {
+ // nothing
+ }
+}
Modified: openwebbeans/trunk/webbeans-web/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/pom.xml?rev=1672497&r1=1672496&r2=1672497&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/pom.xml (original)
+++ openwebbeans/trunk/webbeans-web/pom.xml Thu Apr 9 21:33:23 2015
@@ -33,6 +33,11 @@
<artifactId>geronimo-el_2.2_spec</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.2_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>