Author: rmannibucau
Date: Thu May 9 16:52:01 2019
New Revision: 1859029
URL: http://svn.apache.org/viewvc?rev=1859029&view=rev
Log:
OWB-1287 enable to omit @Inject when a qualifier is already present on a
field/method
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java
- copied, changed from r1858344,
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/CacheUsesQualifierOverridesTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
openwebbeans/trunk/webbeans-tck/testng-dev.xml
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
Thu May 9 16:52:01 2019
@@ -122,6 +122,9 @@ public class OpenWebBeansConfiguration
/**Supports conversations*/
public static final String APPLICATION_SUPPORTS_CONVERSATION =
"org.apache.webbeans.application.supportsConversation";
+ public static final String
APPLICATION_SUPPORTS_IMPLICIT_QUALIFIER_INJECTION =
+
"org.apache.webbeans.application.supportsImplicitQualifierInjection";
+
/** @Produces with interceptor/decorator support */
public static final String PRODUCER_INTERCEPTION_SUPPORT =
"org.apache.webbeans.application.supportsProducerInterception";
@@ -241,6 +244,8 @@ public class OpenWebBeansConfiguration
*/
private Map<String, Set<String>> configuredLists = new HashMap<>();
+ private boolean implicitQualifierInjection;
+
/**
* you can configure this externally as well.
@@ -284,6 +289,7 @@ public class OpenWebBeansConfiguration
configProperties.putAll(newConfigProperties);
}
+ implicitQualifierInjection =
Boolean.parseBoolean(getProperty(APPLICATION_SUPPORTS_IMPLICIT_QUALIFIER_INJECTION));
}
/**
@@ -538,4 +544,9 @@ public class OpenWebBeansConfiguration
return generatorJavaVersion;
}
+
+ public boolean supportsImplicitQualifierInjection()
+ {
+ return implicitQualifierInjection;
+ }
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
Thu May 9 16:52:01 2019
@@ -21,6 +21,7 @@ package org.apache.webbeans.inject.impl;
import org.apache.webbeans.annotation.AnnotationManager;
import org.apache.webbeans.annotation.NamedLiteral;
import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.portable.events.generics.GProcessInjectionPoint;
import org.apache.webbeans.util.AnnotationUtil;
@@ -30,6 +31,7 @@ import javax.enterprise.event.Observes;
import javax.enterprise.event.ObservesAsync;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedCallable;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedField;
@@ -88,14 +90,14 @@ public class InjectionPointFactory
+ owner.getBeanClass().getName());
}
}
- if (field.isAnnotationPresent(Inject.class))
+ if (isInjecting(field))
{
injectionPoints.add(buildInjectionPoint(owner, field));
}
}
for (AnnotatedMethod<? super X> method:
webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType))
{
- if (method.isAnnotationPresent(Inject.class) &&
!Modifier.isStatic(method.getJavaMember().getModifiers()))
+ if (!Modifier.isStatic(method.getJavaMember().getModifiers()) &&
isInjecting(method))
{
validateInitializerMethod(method);
buildInjectionPoints(owner, method, injectionPoints);
@@ -104,6 +106,21 @@ public class InjectionPointFactory
return injectionPoints;
}
+ private boolean isInjecting(final Annotated field)
+ {
+ if (field.isAnnotationPresent(Inject.class))
+ {
+ return true;
+ }
+ if
(!webBeansContext.getOpenWebBeansConfiguration().supportsImplicitQualifierInjection())
+ {
+ return false;
+ }
+ final BeanManagerImpl mgr = webBeansContext.getBeanManagerImpl();
+ return field.getAnnotations().stream().anyMatch(a ->
mgr.isQualifier(a.annotationType()))
+ && field.getAnnotations().stream().noneMatch(it ->
it.annotationType() == Produces.class);
+ }
+
public <X> InjectionPoint buildInjectionPoint(Bean<?> owner,
AnnotatedField<X> annotField, boolean fireEvent)
{
Asserts.assertNotNull(annotField, "annotField");
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
Thu May 9 16:52:01 2019
@@ -59,7 +59,7 @@ public class InjectionPointImpl implemen
{
private static final long serialVersionUID = 1047233127758068484L;
- private Set<Annotation> qualifierAnnotations = new HashSet<>();
+ private Set<Annotation> qualifierAnnotations;
private Bean<?> ownerBean;
Modified:
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Thu May 9 16:52:01 2019
@@ -97,6 +97,10 @@ org.apache.webbeans.spi.deployer.useEjbM
org.apache.webbeans.application.supportsConversation=false
################################################################################################
+################################# Injection Support
#########################################
+org.apache.webbeans.application.supportsImplicitQualifierInjection=true
+################################################################################################
+
################################### Default Conversation Service
###############################
# Default implementation of org.apache.webbeans.corespi.ConversationService.
# This one does not support conversation propagation. It's basically a no-op
implementation
Modified:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
Thu May 9 16:52:01 2019
@@ -228,9 +228,7 @@ public class AnnotatedTypeConfiguratorIm
{
checkAnnotatedType(pat -> pat.configureAnnotatedType()
.filterFields(af ->
"field2".equals(af.getJavaMember().getName()))
- .findFirst()
- .get()
- .remove(a -> a.annotationType() ==
TheQualifier.class),
+ .forEach(c -> c.remove(a ->
a.annotationType() == TheQualifier.class)),
pba ->
{
Assert.assertTrue(pba.getAnnotated() instanceof
AnnotatedType);
Copied:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java
(from r1858344,
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/CacheUsesQualifierOverridesTest.java)
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/CacheUsesQualifierOverridesTest.java&r1=1858344&r2=1859029&rev=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/CacheUsesQualifierOverridesTest.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java
Thu May 9 16:52:01 2019
@@ -18,93 +18,70 @@
*/
package org.apache.webbeans.test.qualifier;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import java.util.function.Supplier;
+import org.apache.webbeans.config.OwbParametrizedTypeImpl;
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
import javax.enterprise.context.Dependent;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.BeforeBeanDiscovery;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.util.AnnotationLiteral;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.util.Nonbinding;
import javax.inject.Qualifier;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.util.function.Supplier;
-import org.apache.webbeans.config.OwbParametrizedTypeImpl;
-import org.apache.webbeans.test.AbstractUnitTest;
-import org.junit.Test;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.junit.Assert.assertEquals;
-public class CacheUsesQualifierOverridesTest extends AbstractUnitTest
+public class QualifierWithOptionalInjectTest extends AbstractUnitTest
{
@Test
public void run()
{
- addExtension(new Extension() {
- void changeQualifier(@Observes final BeforeBeanDiscovery
beforeBeanDiscovery) {
- beforeBeanDiscovery.configureQualifier(TheQualifier.class)
- .methods().forEach(m -> m.remove(it ->
it.annotationType() == Nonbinding.class));
- }
- });
- startContainer(Impl1.class, Impl2.class);
+
System.setProperty("org.apache.webbeans.application.supportsImplicitQualifierInjection",
"true");
+ startContainer(Producing.class, Injected.class);
final OwbParametrizedTypeImpl type = new OwbParametrizedTypeImpl(null,
Supplier.class, String.class);
- final Supplier<String> uno = getInstance(type, new
TheQualifier.Literal("uno"));
- final Supplier<String> due = getInstance(type, new
TheQualifier.Literal("due"));
- assertEquals("1", uno.get());
- assertEquals("2", due.get());
- // redundant but this is the real test here, previous are just nicer
to read in the output
- assertNotEquals(uno.getClass(), due.getClass());
+ final Supplier<String> injected = getInstance(type);
+ assertEquals("yes/no", injected.get());
+
System.clearProperty("org.apache.webbeans.application.supportsImplicitQualifierInjection");
}
@Dependent
- @TheQualifier("uno")
- public static class Impl1 implements Supplier<String>
+ public static class Producing
{
- @Override
- public String get()
- {
- return "1";
+ @Produces
+ @TheQualifier("whatever")
+ String yes(final InjectionPoint injectionPoint) {
+ return new StringBuilder(
+
injectionPoint.getAnnotated().getAnnotation(TheQualifier.class).value()).reverse().toString();
}
}
@Dependent
- @TheQualifier("due")
- public static class Impl2 implements Supplier<String>
+ public static class Injected implements Supplier<String>
{
+ @TheQualifier("sey")
+ private String yes;
+
+ @TheQualifier("on")
+ private String no;
+
@Override
public String get()
{
- return "2";
+ return yes + '/' + no;
}
}
@Qualifier
- @Target({FIELD, TYPE})
+ @Target({FIELD, METHOD})
@Retention(RUNTIME)
public @interface TheQualifier
{
@Nonbinding
String value();
-
- class Literal extends AnnotationLiteral<TheQualifier> implements
TheQualifier
- {
- private final String value;
-
- public Literal(final String value)
- {
- this.value = value;
- }
-
- @Override
- public String value()
- {
- return value;
- }
- }
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++
openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
Thu May 9 16:52:01 2019
@@ -32,3 +32,7 @@ org.apache.webbeans.spi.deployer.MetaDat
org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler
org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler
+
+
+# some tests misused that so revert it to ensure they pass
+org.apache.webbeans.application.supportsImplicitQualifierInjection=false
\ No newline at end of file
Modified:
openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++
openwebbeans/trunk/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Thu May 9 16:52:01 2019
@@ -42,3 +42,6 @@ org.apache.webbeans.proxy.mapping.javax.
org.apache.webbeans.container.InjectionResolver.fastMatching = false
+# only
org.jboss.cdi.tck.tests.extensions.beanManager.beanAttributes.CreateBeanAttributesTest
currently
+# we can write an arquillian extension to avoid to set it globally
+org.apache.webbeans.application.supportsImplicitQualifierInjection=false
Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1859029&r1=1859028&r2=1859029&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Thu May 9 16:52:01 2019
@@ -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.alternative.selection.stereotype.SelectedBeanWithUnselectedStereotypeTest"
/>
+ <class
name="org.jboss.cdi.tck.tests.extensions.beanManager.beanAttributes.CreateBeanAttributesTest"
/>
<!--
<class
name="org.jboss.cdi.tck.tests.event.parameterized.ParameterizedEventTest" />