GERONIMO-6574 Fixing tests against Weld3.
git-svn-id: https://svn.apache.org/repos/asf/geronimo/components/config/trunk@1804164 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java b/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
index 03e331e..09c6cd6 100644
--- a/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
+++ b/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigExtension.java
@@ -46,7 +46,7 @@
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 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 {
diff --git a/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java b/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
index 4a5b60f..efa6110 100644
--- a/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
+++ b/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
@@ -20,11 +20,14 @@
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 @@
return id;
}
+ InjectionPoint getSimpleInjectionPoint() {
+ return simpleInjectionPoint;
+ }
+
private static class ConfigPropertyLiteral extends AnnotationLiteral<ConfigProperty> implements ConfigProperty {
@Override
public String name() {
@@ -137,4 +144,42 @@
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;
+ }
+ };
}