You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jo...@apache.org on 2017/08/04 23:33:09 UTC

svn commit: r1804164 - in /geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi: ConfigExtension.java ConfigInjectionBean.java

Author: johndament
Date: Fri Aug  4 23:33:09 2017
New Revision: 1804164

URL: http://svn.apache.org/viewvc?rev=1804164&view=rev
Log:
GERONIMO-6574 Fixing tests against Weld3.

Modified:
    geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
    geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java

Modified: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java?rev=1804164&r1=1804163&r2=1804164&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java (original)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java Fri Aug  4 23:33:09 2017
@@ -46,7 +46,7 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
-import java.util.function.Function;
+import java.util.function.BiFunction;
 import java.util.stream.Stream;
 
 import static java.util.function.Function.identity;
@@ -139,12 +139,12 @@ public class ConfigExtension implements
     public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) {
         injections.stream()
                 .flatMap(injection -> {
-                    final Function<CreationalContext<?>, String> keyProvider;
+                    final BiFunction<CreationalContext<?>, ConfigInjectionBean<?>, String> keyProvider;
                     if (injection.keys.size() == 1) {
                         final String key = injection.keys.iterator().next();
-                        keyProvider = ctx -> key;
+                        keyProvider = (ctx, bean) -> key;
                     } else {
-                        keyProvider = ctx -> getName(findInjectionPoint(bm, ctx));
+                        keyProvider = (ctx, bean) -> getName(findInjectionPoint(bm, ctx, bean));
                     }
 
                     if (ParameterizedType.class.isInstance(injection.type)) {
@@ -161,7 +161,7 @@ public class ConfigExtension implements
                             return Stream.of(new ConfigInjectionBean<Provider<?>>(injection.type, true) {
                                 @Override
                                 public Provider<?> create(final CreationalContext<Provider<?>> context) {
-                                    return () -> config.getValue(keyProvider.apply(context), providerType);
+                                    return () -> config.getValue(keyProvider.apply(context, this), providerType);
                                 }
                             });
                         } else if (Optional.class == rawType && paramType.getActualTypeArguments().length == 1) {
@@ -173,7 +173,7 @@ public class ConfigExtension implements
                             return Stream.of(new ConfigInjectionBean<Optional<?>>(injection.type) {
                                 @Override
                                 public Optional<?> create(final CreationalContext<Optional<?>> context) {
-                                    return config.getOptionalValue(keyProvider.apply(context), optionalType);
+                                    return config.getOptionalValue(keyProvider.apply(context, this), optionalType);
                                 }
                             });
                         } else {
@@ -187,7 +187,7 @@ public class ConfigExtension implements
                             bean = new ConfigInjectionBean<Object>(injection.type) {
                                 @Override
                                 public Object create(final CreationalContext<Object> context) {
-                                    return config.getOptionalValue(keyProvider.apply(context), clazz);
+                                    return config.getOptionalValue(keyProvider.apply(context, this), clazz);
                                 }
                             };
                         } else if (injection.defaultValues.size() == 1) { // common enough to be optimized
@@ -196,7 +196,7 @@ public class ConfigExtension implements
                             bean = new ConfigInjectionBean<Object>(injection.type) {
                                 @Override
                                 public Object create(final CreationalContext<Object> context) {
-                                    final Optional optionalValue = config.getOptionalValue(keyProvider.apply(context), clazz);
+                                    final Optional optionalValue = config.getOptionalValue(keyProvider.apply(context, this), clazz);
                                     return optionalValue.orElse(alternativeVal);
                                 }
                             };
@@ -206,7 +206,7 @@ public class ConfigExtension implements
                             bean = new ConfigInjectionBean<Object>(injection.type) {
                                 @Override
                                 public Object create(final CreationalContext<Object> context) {
-                                    final InjectionPoint ip = findInjectionPoint(bm, context);
+                                    final InjectionPoint ip = findInjectionPoint(bm, context, this);
                                     if (ip == null) {
                                         throw new IllegalStateException("Could not retrieve InjectionPoint");
                                     }
@@ -267,7 +267,7 @@ public class ConfigExtension implements
         return ConfigImpl.class.cast(config);
     }
 
-    private String getName(final InjectionPoint ip) {
+    private static String getName(final InjectionPoint ip) {
         final ConfigProperty annotation = ip.getAnnotated().getAnnotation(ConfigProperty.class);
         final String name = annotation.name();
         return isDefaultUnset(name) ? getConfigKey(ip, annotation) : name;
@@ -307,9 +307,9 @@ public class ConfigExtension implements
         return defaultValue == null || defaultValue.length() == 0 || defaultValue.equals(ConfigProperty.UNCONFIGURED_VALUE);
     }
 
-    private static InjectionPoint findInjectionPoint(final BeanManager bm, final CreationalContext<?> ctx) {
-        return InjectionPoint.class.cast(
-                bm.getReference(bm.resolve(bm.getBeans(InjectionPoint.class)), InjectionPoint.class, ctx));
+    private static InjectionPoint findInjectionPoint(final BeanManager bm, final CreationalContext<?> ctx,
+                                                     ConfigInjectionBean bean) {
+        return InjectionPoint.class.cast(bm.getInjectableReference(bean.getSimpleInjectionPoint(), ctx));
     }
 
     private static final class Injection {

Modified: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java?rev=1804164&r1=1804163&r2=1804164&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java (original)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java Fri Aug  4 23:33:09 2017
@@ -20,11 +20,14 @@ import org.eclipse.microprofile.config.i
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.PassivationCapable;
 import javax.enterprise.util.AnnotationLiteral;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.Collections;
@@ -126,6 +129,10 @@ public abstract class ConfigInjectionBea
         return id;
     }
 
+    InjectionPoint getSimpleInjectionPoint() {
+        return simpleInjectionPoint;
+    }
+
     private static class ConfigPropertyLiteral extends AnnotationLiteral<ConfigProperty> implements ConfigProperty {
         @Override
         public String name() {
@@ -137,4 +144,42 @@ public abstract class ConfigInjectionBea
             return "";
         }
     }
+
+    private final InjectionPoint simpleInjectionPoint = new InjectionPoint() {
+
+        @Override
+        public boolean isTransient() {
+            return false;
+        }
+
+        @Override
+        public boolean isDelegate() {
+            return false;
+        }
+
+        @Override
+        public Type getType() {
+            return InjectionPoint.class;
+        }
+
+        @Override
+        public Set<Annotation> getQualifiers() {
+            return Collections.singleton(new AnnotationLiteral<Default>() {});
+        }
+
+        @Override
+        public Member getMember() {
+            return null;
+        }
+
+        @Override
+        public Bean<?> getBean() {
+            return ConfigInjectionBean.this;
+        }
+
+        @Override
+        public Annotated getAnnotated() {
+            return null;
+        }
+    };
 }



Re: svn commit: r1804164 - in /geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi: ConfigExtension.java ConfigInjectionBean.java

Posted by "John D. Ament" <jo...@apache.org>.
Just as an FYI, I chatted with Martin from Weld to understand what's going
on, it wasn't obvious to me.  Weld only generates beans for InjectionPoint
for each injection point of type InjectionPoint.  So what was there
wouldn't work.  getInjectableReference does, and it seems to work fine for
OWB and Weld.  Any concerns with that swap out?

With that said - Config now passes on Weld!

John

On Fri, Aug 4, 2017 at 7:33 PM <jo...@apache.org> wrote:

> Author: johndament
> Date: Fri Aug  4 23:33:09 2017
> New Revision: 1804164
>
> URL: http://svn.apache.org/viewvc?rev=1804164&view=rev
> Log:
> GERONIMO-6574 Fixing tests against Weld3.
>
> Modified:
>
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
>
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
>
> Modified:
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
> URL:
> http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java?rev=1804164&r1=1804163&r2=1804164&view=diff
>
> ==============================================================================
> ---
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
> (original)
> +++
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
> Fri Aug  4 23:33:09 2017
> @@ -46,7 +46,7 @@ import java.util.Map;
>  import java.util.Objects;
>  import java.util.Optional;
>  import java.util.Set;
> -import java.util.function.Function;
> +import java.util.function.BiFunction;
>  import java.util.stream.Stream;
>
>  import static java.util.function.Function.identity;
> @@ -139,12 +139,12 @@ public class ConfigExtension implements
>      public void registerConfigProducer(@Observes AfterBeanDiscovery abd,
> BeanManager bm) {
>          injections.stream()
>                  .flatMap(injection -> {
> -                    final Function<CreationalContext<?>, String>
> keyProvider;
> +                    final BiFunction<CreationalContext<?>,
> ConfigInjectionBean<?>, String> keyProvider;
>                      if (injection.keys.size() == 1) {
>                          final String key =
> injection.keys.iterator().next();
> -                        keyProvider = ctx -> key;
> +                        keyProvider = (ctx, bean) -> key;
>                      } else {
> -                        keyProvider = ctx ->
> getName(findInjectionPoint(bm, ctx));
> +                        keyProvider = (ctx, bean) ->
> getName(findInjectionPoint(bm, ctx, bean));
>                      }
>
>                      if
> (ParameterizedType.class.isInstance(injection.type)) {
> @@ -161,7 +161,7 @@ public class ConfigExtension implements
>                              return Stream.of(new
> ConfigInjectionBean<Provider<?>>(injection.type, true) {
>                                  @Override
>                                  public Provider<?> create(final
> CreationalContext<Provider<?>> context) {
> -                                    return () ->
> config.getValue(keyProvider.apply(context), providerType);
> +                                    return () ->
> config.getValue(keyProvider.apply(context, this), providerType);
>                                  }
>                              });
>                          } else if (Optional.class == rawType &&
> paramType.getActualTypeArguments().length == 1) {
> @@ -173,7 +173,7 @@ public class ConfigExtension implements
>                              return Stream.of(new
> ConfigInjectionBean<Optional<?>>(injection.type) {
>                                  @Override
>                                  public Optional<?> create(final
> CreationalContext<Optional<?>> context) {
> -                                    return
> config.getOptionalValue(keyProvider.apply(context), optionalType);
> +                                    return
> config.getOptionalValue(keyProvider.apply(context, this), optionalType);
>                                  }
>                              });
>                          } else {
> @@ -187,7 +187,7 @@ public class ConfigExtension implements
>                              bean = new
> ConfigInjectionBean<Object>(injection.type) {
>                                  @Override
>                                  public Object create(final
> CreationalContext<Object> context) {
> -                                    return
> config.getOptionalValue(keyProvider.apply(context), clazz);
> +                                    return
> config.getOptionalValue(keyProvider.apply(context, this), clazz);
>                                  }
>                              };
>                          } else if (injection.defaultValues.size() == 1) {
> // common enough to be optimized
> @@ -196,7 +196,7 @@ public class ConfigExtension implements
>                              bean = new
> ConfigInjectionBean<Object>(injection.type) {
>                                  @Override
>                                  public Object create(final
> CreationalContext<Object> context) {
> -                                    final Optional optionalValue =
> config.getOptionalValue(keyProvider.apply(context), clazz);
> +                                    final Optional optionalValue =
> config.getOptionalValue(keyProvider.apply(context, this), clazz);
>                                      return
> optionalValue.orElse(alternativeVal);
>                                  }
>                              };
> @@ -206,7 +206,7 @@ public class ConfigExtension implements
>                              bean = new
> ConfigInjectionBean<Object>(injection.type) {
>                                  @Override
>                                  public Object create(final
> CreationalContext<Object> context) {
> -                                    final InjectionPoint ip =
> findInjectionPoint(bm, context);
> +                                    final InjectionPoint ip =
> findInjectionPoint(bm, context, this);
>                                      if (ip == null) {
>                                          throw new
> IllegalStateException("Could not retrieve InjectionPoint");
>                                      }
> @@ -267,7 +267,7 @@ public class ConfigExtension implements
>          return ConfigImpl.class.cast(config);
>      }
>
> -    private String getName(final InjectionPoint ip) {
> +    private static String getName(final InjectionPoint ip) {
>          final ConfigProperty annotation =
> ip.getAnnotated().getAnnotation(ConfigProperty.class);
>          final String name = annotation.name();
>          return isDefaultUnset(name) ? getConfigKey(ip, annotation) : name;
> @@ -307,9 +307,9 @@ public class ConfigExtension implements
>          return defaultValue == null || defaultValue.length() == 0 ||
> defaultValue.equals(ConfigProperty.UNCONFIGURED_VALUE);
>      }
>
> -    private static InjectionPoint findInjectionPoint(final BeanManager
> bm, final CreationalContext<?> ctx) {
> -        return InjectionPoint.class.cast(
> -
> bm.getReference(bm.resolve(bm.getBeans(InjectionPoint.class)),
> InjectionPoint.class, ctx));
> +    private static InjectionPoint findInjectionPoint(final BeanManager
> bm, final CreationalContext<?> ctx,
> +                                                     ConfigInjectionBean
> bean) {
> +        return
> InjectionPoint.class.cast(bm.getInjectableReference(bean.getSimpleInjectionPoint(),
> ctx));
>      }
>
>      private static final class Injection {
>
> Modified:
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
> URL:
> http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java?rev=1804164&r1=1804163&r2=1804164&view=diff
>
> ==============================================================================
> ---
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
> (original)
> +++
> geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
> Fri Aug  4 23:33:09 2017
> @@ -20,11 +20,14 @@ import org.eclipse.microprofile.config.i
>
>  import javax.enterprise.context.Dependent;
>  import javax.enterprise.context.spi.CreationalContext;
> +import javax.enterprise.inject.Default;
> +import javax.enterprise.inject.spi.Annotated;
>  import javax.enterprise.inject.spi.Bean;
>  import javax.enterprise.inject.spi.InjectionPoint;
>  import javax.enterprise.inject.spi.PassivationCapable;
>  import javax.enterprise.util.AnnotationLiteral;
>  import java.lang.annotation.Annotation;
> +import java.lang.reflect.Member;
>  import java.lang.reflect.ParameterizedType;
>  import java.lang.reflect.Type;
>  import java.util.Collections;
> @@ -126,6 +129,10 @@ public abstract class ConfigInjectionBea
>          return id;
>      }
>
> +    InjectionPoint getSimpleInjectionPoint() {
> +        return simpleInjectionPoint;
> +    }
> +
>      private static class ConfigPropertyLiteral extends
> AnnotationLiteral<ConfigProperty> implements ConfigProperty {
>          @Override
>          public String name() {
> @@ -137,4 +144,42 @@ public abstract class ConfigInjectionBea
>              return "";
>          }
>      }
> +
> +    private final InjectionPoint simpleInjectionPoint = new
> InjectionPoint() {
> +
> +        @Override
> +        public boolean isTransient() {
> +            return false;
> +        }
> +
> +        @Override
> +        public boolean isDelegate() {
> +            return false;
> +        }
> +
> +        @Override
> +        public Type getType() {
> +            return InjectionPoint.class;
> +        }
> +
> +        @Override
> +        public Set<Annotation> getQualifiers() {
> +            return Collections.singleton(new AnnotationLiteral<Default>()
> {});
> +        }
> +
> +        @Override
> +        public Member getMember() {
> +            return null;
> +        }
> +
> +        @Override
> +        public Bean<?> getBean() {
> +            return ConfigInjectionBean.this;
> +        }
> +
> +        @Override
> +        public Annotated getAnnotated() {
> +            return null;
> +        }
> +    };
>  }
>
>
>