openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1859064 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/ webbeans-impl/src/main/java/org/apache/webbeans/intercept/ webbeans-impl/src/main/java/o...
Date Fri, 10 May 2019 07:31:44 GMT
Author: rmannibucau
Date: Fri May 10 07:31:43 2019
New Revision: 1859064

URL: http://svn.apache.org/viewvc?rev=1859064&view=rev
Log:
OWB-1287 SPI for injection point factory + support of constructors for implicit injection

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/service/DefaultInjectionPointService.java
    openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/InjectionPointService.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/config/WebBeansContext.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/intercept/InterceptorResolutionService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.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

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=1859064&r1=1859063&r2=1859064&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
Fri May 10 07:31:43 2019
@@ -122,9 +122,6 @@ 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";
 
@@ -244,8 +241,6 @@ public class OpenWebBeansConfiguration
      */
     private Map<String, Set<String>> configuredLists = new HashMap<>();
 
-    private boolean implicitQualifierInjection;
-
 
     /**
      * you can configure this externally as well.
@@ -288,8 +283,6 @@ public class OpenWebBeansConfiguration
 
             configProperties.putAll(newConfigProperties);
         }
-
-        implicitQualifierInjection = Boolean.parseBoolean(getProperty(APPLICATION_SUPPORTS_IMPLICIT_QUALIFIER_INJECTION));
     }
 
     /**
@@ -544,9 +537,4 @@ public class OpenWebBeansConfiguration
 
         return generatorJavaVersion;
     }
-
-    public boolean supportsImplicitQualifierInjection()
-    {
-        return implicitQualifierInjection;
-    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1859064&r1=1859063&r2=1859064&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Fri May 10 07:31:43 2019
@@ -57,6 +57,7 @@ import org.apache.webbeans.portable.even
 import org.apache.webbeans.proxy.SubclassProxyFactory;
 import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
 import org.apache.webbeans.proxy.NormalScopeProxyFactory;
+import org.apache.webbeans.service.DefaultInjectionPointService;
 import org.apache.webbeans.service.DefaultLoaderService;
 import org.apache.webbeans.spi.BeanArchiveService;
 import org.apache.webbeans.spi.ApplicationBoundaryService;
@@ -100,7 +101,7 @@ public class WebBeansContext
     private final SerializableBeanVault serializableBeanVault = new SerializableBeanVault();
     private final StereoTypeManager stereoTypeManager = new StereoTypeManager();
     private final AnnotationManager annotationManager;
-    private final InjectionPointFactory injectionPointFactory = new InjectionPointFactory(this);
+    private final InjectionPointFactory injectionPointFactory;
     private final InterceptorUtil interceptorUtil = new InterceptorUtil(this);
     private final SecurityService securityService;
     private final LoaderService loaderService;
@@ -156,6 +157,7 @@ public class WebBeansContext
                 serviceMap.put(entry.getKey(), entry.getValue());
             }
         }
+        injectionPointFactory = new InjectionPointFactory(this);
         loaderService = getService(LoaderService.class);
         securityService = getService(SecurityService.class);
         applicationBoundaryService = getService(ApplicationBoundaryService.class);
@@ -384,7 +386,37 @@ public class WebBeansContext
 
     private Object get(String singletonName)
     {
-        //Load class
+        // skip reflection for these services
+        if (DefaultInjectionPointService.class.getName().equals(singletonName))
+        {
+            return new DefaultInjectionPointService(this);
+        }
+        if (SimpleSecurityService.class.getName().equals(singletonName))
+        {
+            return new SimpleSecurityService();
+        }
+        if (DefaultApplicationBoundaryService.class.getName().equals(singletonName))
+        {
+            return new DefaultApplicationBoundaryService();
+        }
+        if (DefaultBeanArchiveService.class.getName().equals(singletonName))
+        {
+            return new DefaultBeanArchiveService();
+        }
+        if (DefaultJndiService.class.getName().equals(singletonName))
+        {
+            return new DefaultJndiService();
+        }
+        if (DefaultContextsService.class.getName().equals(singletonName))
+        {
+            return new DefaultContextsService(this);
+        }
+        if (DefaultConversationService.class.getName().equals(singletonName))
+        {
+            return new DefaultConversationService();
+        }
+
+        // Load class by reflection
         Class<?> clazz = ClassUtil.getClassFromName(singletonName);
         if (clazz == null)
         {

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=1859064&r1=1859063&r2=1859064&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
Fri May 10 07:31:43 2019
@@ -21,9 +21,9 @@ 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.spi.InjectionPointService;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 
@@ -31,7 +31,6 @@ 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;
@@ -56,10 +55,12 @@ import java.util.Set;
 public class InjectionPointFactory
 {
     private final WebBeansContext webBeansContext;
+    private final InjectionPointService service;
 
     public InjectionPointFactory(WebBeansContext webBeansContext)
     {
         this.webBeansContext = webBeansContext;
+        this.service = webBeansContext.getService(InjectionPointService.class);
     }
 
     public <X> Set<InjectionPoint> buildInjectionPoints(Bean<X> owner,
AnnotatedType<X> annotatedType)
@@ -80,6 +81,26 @@ public class InjectionPointFactory
                 buildInjectionPoints(owner, constructor, injectionPoints);
             }
         }
+        if (!constructorFound)
+        {
+            final AnnotatedConstructor<X>[] cons = annotatedType.getConstructors().stream()
+                    .filter(constructor -> constructor.getParameters().stream().anyMatch(service::hasInjection))
+                    .toArray(AnnotatedConstructor[]::new);
+            switch (cons.length)
+            {
+                case 0:
+                    break;
+                case 1:
+                {
+                    validateInitializerConstructor(cons[0]);
+                    buildInjectionPoints(owner, cons[0], injectionPoints);
+                    break;
+                }
+                default:
+                    throw new WebBeansConfigurationException(
+                            "There are more than one candidate constructor for injection
in : " + annotatedType);
+            }
+        }
         for (AnnotatedField<? super X> field: annotatedType.getFields())
         {
             if (owner != null && Modifier.isPublic(field.getJavaMember().getModifiers())
&& !field.isStatic())
@@ -90,14 +111,14 @@ public class InjectionPointFactory
                             + owner.getBeanClass().getName());
                 }
             }                
-            if (isInjecting(field))
+            if (service.hasInjection(field))
             {
                 injectionPoints.add(buildInjectionPoint(owner, field));
             }
         }
         for (AnnotatedMethod<? super X> method: webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType))
         {
-            if (!Modifier.isStatic(method.getJavaMember().getModifiers()) && isInjecting(method))
+            if (!Modifier.isStatic(method.getJavaMember().getModifiers()) && service.hasInjection(method))
             {
                 validateInitializerMethod(method);
                 buildInjectionPoints(owner, method, injectionPoints);
@@ -106,21 +127,6 @@ 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/intercept/InterceptorResolutionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1859064&r1=1859063&r2=1859064&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
Fri May 10 07:31:43 2019
@@ -206,17 +206,17 @@ public class InterceptorResolutionServic
         List<Interceptor<?>> cdiInterceptors = new ArrayList<>(allUsedCdiInterceptors);
         Collections.sort(cdiInterceptors, new InterceptorComparator(webBeansContext));
 
-        List<Interceptor<?>> cdiConstructorInterceptors = new ArrayList<>(allUsedConstructorCdiInterceptors);
-        Collections.sort(cdiConstructorInterceptors, new InterceptorComparator(webBeansContext));
-
-        boolean interceptedBean = !annotatedType.getJavaClass().isInterface() &&
(
-                                      allUsedEjbInterceptors.size() > 0 ||
-                                      allUsedCdiInterceptors.size() > 0 ||
-                                      lifecycleMethodInterceptorInfos.size() > 0
-                                  );
-
-        if ((interceptedBean || decorators.size() > 0) && Modifier.isFinal(annotatedType.getJavaClass().getModifiers()))
-        {
+        List<Interceptor<?>> cdiConstructorInterceptors = new ArrayList<>(allUsedConstructorCdiInterceptors);
+        Collections.sort(cdiConstructorInterceptors, new InterceptorComparator(webBeansContext));
+
+        boolean interceptedBean = !annotatedType.getJavaClass().isInterface() &&
(
+                                      allUsedEjbInterceptors.size() > 0 ||
+                                      allUsedCdiInterceptors.size() > 0 ||
+                                      lifecycleMethodInterceptorInfos.size() > 0
+                                  );
+
+        if ((interceptedBean || decorators.size() > 0) && Modifier.isFinal(annotatedType.getJavaClass().getModifiers()))
+        {
             throw new WebBeansDeploymentException("Cannot apply Decorators or Interceptors
on a final class: "
                                                      + annotatedType.getJavaClass().getName());
         }
@@ -284,21 +284,13 @@ public class InterceptorResolutionServic
             allUsedCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.PRE_DESTROY,
interceptorBindings));
         }
 
-        AnnotatedConstructor<?> constructorToUse = null;
-        if (!annotatedType.getConstructors().isEmpty()) // avoid to use class annotations
for not used constructors
+        AnnotatedConstructor<?> constructorToUse = webBeansContext.getWebBeansUtil().getInjectedConstructor(annotatedType);
+        if (constructorToUse == null)
         {
-            for (AnnotatedConstructor<?> c : annotatedType.getConstructors())
-            {
-                if (constructorToUse == null && c.getParameters().isEmpty())
-                {
-                    constructorToUse = c;
-                }
-                else if (c.getAnnotation(Inject.class) != null)
-                {
-                    constructorToUse = c;
-                    break;
-                }
-            }
+            constructorToUse = annotatedType.getConstructors().stream()
+                    .filter(it -> it.getParameters().isEmpty())
+                    .findFirst()
+                    .orElse(null);
         }
         if (constructorToUse != null)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java?rev=1859064&r1=1859063&r2=1859064&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
Fri May 10 07:31:43 2019
@@ -34,7 +34,6 @@ import org.apache.xbean.asm7.Type;
 
 import javax.enterprise.inject.spi.AnnotatedConstructor;
 import javax.enterprise.inject.spi.AnnotatedType;
-import javax.inject.Inject;
 
 /**
  * This factory creates subclasses for abstract classes.
@@ -123,15 +122,8 @@ public class SubclassProxyFactory extend
         List<Method> methods = ClassUtil.getNonPrivateMethods(classToProxy, true);
         Method[] businessMethods = methods.toArray(new Method[methods.size()]);
 
-        Constructor<T> cons = null;
-        for (AnnotatedConstructor<T> c : annotatedType.getConstructors())
-        {
-            if (c.isAnnotationPresent(Inject.class))
-            {
-                cons = c.getJavaMember();
-                break;
-            }
-        }
+        AnnotatedConstructor<T> aCons = webBeansContext.getWebBeansUtil().getInjectedConstructor(annotatedType);
+        Constructor<T> cons = aCons != null ? aCons.getJavaMember() : null;
 
         clazz = createProxyClass(classLoader, proxyClassName, classToProxy, businessMethods,
new Method[0], cons);
 

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/service/DefaultInjectionPointService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/service/DefaultInjectionPointService.java?rev=1859064&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/service/DefaultInjectionPointService.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/service/DefaultInjectionPointService.java
Fri May 10 07:31:43 2019
@@ -0,0 +1,95 @@
+/*
+ * 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.service;
+
+import javax.annotation.Priority;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Annotated;
+import javax.inject.Inject;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.spi.InjectionPointService;
+import org.apache.webbeans.util.ClassUtil;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import static java.util.Comparator.comparing;
+import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Enables to elect an annotated (field, constructor, method) as having (virtually) {@code
@Inject}.
+ * {@code implicitSupport} enables to use qualifiers as implicit markers for {@code @Inject}.
+ * It also supports a delegation chain through {@code delegateClasses} configuration
+ * which will look up services (from their class names) and they will be sorted by {@code
@Priority}.
+ */
+public class DefaultInjectionPointService implements InjectionPointService
+{
+    private final BeanManagerImpl manager;
+    private final boolean implicitSupport;
+    private final List<InjectionPointService> delegates;
+
+    public DefaultInjectionPointService(final WebBeansContext context)
+    {
+        this.manager = context.getBeanManagerImpl();
+        this.implicitSupport = Boolean.parseBoolean(context.getOpenWebBeansConfiguration().getProperty(
+                DefaultInjectionPointService.class.getName() + ".implicitSupport"));
+        this.delegates = ofNullable(context.getOpenWebBeansConfiguration().getProperty(
+                    DefaultInjectionPointService.class.getName() + ".delegateClasses"))
+                .map(Stream::of)
+                .orElseGet(Stream::empty)
+                .flatMap(it -> Stream.of(it.split(",")))
+                .map(String::trim)
+                .filter(it -> !it.isEmpty())
+                .map(ClassUtil::getClassFromName)
+                .filter(Objects::nonNull)
+                .map(context::getService)
+                .map(InjectionPointService.class::cast)
+                .sorted(comparing(it -> ofNullable(it.getClass().getAnnotation(Priority.class))
+                        .map(Priority::value)
+                        .orElse(Integer.MAX_VALUE)))
+                .collect(toList());
+    }
+
+    @Override
+    public boolean hasInjection(final Annotated annotated)
+    {
+        if (annotated.isAnnotationPresent(Inject.class))
+        {
+            return true;
+        }
+        if (!implicitSupport)
+        {
+            return false;
+        }
+        if (annotated.getAnnotations().stream().anyMatch(a -> manager.isQualifier(a.annotationType()))
+                && annotated.getAnnotations().stream().noneMatch(it -> it.annotationType()
== Produces.class))
+        {
+            return true;
+        }
+        if (delegates.isEmpty())
+        {
+            return false;
+        }
+        return delegates.stream().anyMatch(d -> d.hasInjection(annotated));
+    }
+}

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=1859064&r1=1859063&r2=1859064&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
Fri May 10 07:31:43 2019
@@ -83,6 +83,7 @@ import org.apache.webbeans.portable.even
 import org.apache.webbeans.portable.events.generics.GProcessSyntheticAnnotatedType;
 import org.apache.webbeans.portable.events.generics.GProcessSyntheticBean;
 import org.apache.webbeans.portable.events.generics.GProcessSyntheticObserverMethod;
+import org.apache.webbeans.spi.InjectionPointService;
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
 
@@ -406,23 +407,33 @@ public final class WebBeansUtil
      */
     public boolean isConstructorOk(AnnotatedType<?> annotatedType) throws WebBeansConfigurationException
     {
-        Class<?> clazz = annotatedType.getJavaClass();
+        final Class<?> clazz = annotatedType.getJavaClass();
+        return getNoArgConstructor(clazz) != null || getInjectedConstructor(annotatedType)
!= null;
+    }
 
-        Constructor<?> defaultCt = getNoArgConstructor(clazz);
-        if (defaultCt != null )
+    public <T> AnnotatedConstructor<T> getInjectedConstructor(final AnnotatedType<T>
type)
+    {
+        final Set<? extends AnnotatedConstructor<T>> constructors = type.getConstructors();
+        if (constructors.isEmpty())
         {
-            return true;
+            return null;
         }
-
-        Set<? extends AnnotatedConstructor<?>> constructors = annotatedType.getConstructors();
-        for (AnnotatedConstructor<?> constructor : constructors)
+        for (final AnnotatedConstructor<T> constructor : constructors)
         {
             if (constructor.getAnnotation(Inject.class) != null)
             {
-                return true;
+                return constructor;
             }
         }
-        return false;
+        final InjectionPointService service = webBeansContext.getService(InjectionPointService.class);
+        for (final AnnotatedConstructor<T> constructor : constructors)
+        {
+            if (constructor.getParameters().stream().anyMatch(service::hasInjection))
+            {
+                return constructor;
+            }
+        }
+        return null;
     }
 
     public <T> Bean<T> createNewComponent(Class<T> type)

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=1859064&r1=1859063&r2=1859064&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
Fri May 10 07:31:43 2019
@@ -97,15 +97,13 @@ 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
 # This will get overwritten in the web and jsf plugins
 org.apache.webbeans.spi.ConversationService=org.apache.webbeans.conversation.DefaultConversationService
+org.apache.webbeans.spi.InjectionPointService=org.apache.webbeans.service.DefaultInjectionPointService
+org.apache.webbeans.service.DefaultInjectionPointService.implicitSupport = true
 ################################################################################################
 
 ####################### Archive Centric Beans.xml Scanning #####################################

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java?rev=1859064&r1=1859063&r2=1859064&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/qualifier/QualifierWithOptionalInjectTest.java
Fri May 10 07:31:43 2019
@@ -20,6 +20,8 @@ package org.apache.webbeans.test.qualifi
 
 import org.apache.webbeans.config.OwbParametrizedTypeImpl;
 import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import javax.enterprise.context.Dependent;
@@ -33,20 +35,42 @@ import java.util.function.Supplier;
 
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 import static org.junit.Assert.assertEquals;
 
 public class QualifierWithOptionalInjectTest extends AbstractUnitTest
 {
+    @Before
+    public void before()
+    {
+        System.setProperty("org.apache.webbeans.service.DefaultInjectionPointService.implicitSupport",
"true");
+    }
+
+    @After
+    public void after()
+    {
+        System.clearProperty("org.apache.webbeans.service.DefaultInjectionPointService.implicitSupport");
+    }
+
     @Test
-    public void run()
+    public void fields()
     {
-        System.setProperty("org.apache.webbeans.application.supportsImplicitQualifierInjection",
"true");
         startContainer(Producing.class, Injected.class);
+        doCheck();
+    }
+
+    @Test
+    public void constructor()
+    {
+        startContainer(Producing.class, ConstructorInjected.class);
+        doCheck();
+    }
+
+    private void doCheck() {
         final OwbParametrizedTypeImpl type = new OwbParametrizedTypeImpl(null, Supplier.class,
String.class);
         final Supplier<String> injected = getInstance(type);
         assertEquals("yes/no", injected.get());
-        System.clearProperty("org.apache.webbeans.application.supportsImplicitQualifierInjection");
     }
 
     @Dependent
@@ -76,8 +100,24 @@ public class QualifierWithOptionalInject
         }
     }
 
+    @Dependent
+    public static class ConstructorInjected implements Supplier<String>
+    {
+        private final String value;
+
+        public ConstructorInjected(@TheQualifier("sey") final String yes, @TheQualifier("on")
final String no) {
+            value = yes + '/' + no;
+        }
+
+        @Override
+        public String get()
+        {
+            return value;
+        }
+    }
+
     @Qualifier
-    @Target({FIELD, METHOD})
+    @Target({FIELD, METHOD, PARAMETER})
     @Retention(RUNTIME)
     public @interface TheQualifier
     {

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=1859064&r1=1859063&r2=1859064&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
Fri May 10 07:31:43 2019
@@ -35,4 +35,4 @@ org.apache.webbeans.proxy.mapping.javax.
 
 
 # some tests misused that so revert it to ensure they pass
-org.apache.webbeans.application.supportsImplicitQualifierInjection=false
\ No newline at end of file
+org.apache.webbeans.service.DefaultInjectionPointService.implicitSupport = false
\ No newline at end of file

Added: openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/InjectionPointService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/InjectionPointService.java?rev=1859064&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/InjectionPointService.java
(added)
+++ openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/InjectionPointService.java
Fri May 10 07:31:43 2019
@@ -0,0 +1,26 @@
+/*
+ * 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.spi;
+
+import javax.enterprise.inject.spi.Annotated;
+
+public interface InjectionPointService
+{
+    boolean hasInjection(Annotated annotated);
+}

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=1859064&r1=1859063&r2=1859064&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
Fri May 10 07:31:43 2019
@@ -44,4 +44,4 @@ org.apache.webbeans.container.InjectionR
 
 # 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
+org.apache.webbeans.service.DefaultInjectionPointService.implicitSupport = false



Mime
View raw message