Skip to content

Commit

Permalink
Fix config mapping and config properties synthetic beans
Browse files Browse the repository at this point in the history
- register synthetic injection point for InjectionPoint metadata
  • Loading branch information
mkouba committed May 18, 2023
1 parent aad9ce5 commit c411487
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.ClassType;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
Expand Down Expand Up @@ -320,6 +321,7 @@ void registerConfigMappingsBean(
.configure(configClass.getConfigClass())
.types(configClass.getTypes().toArray(new Type[] {}))
.creator(ConfigMappingCreator.class)
.addInjectionPoint(ClassType.create(DotNames.INJECTION_POINT))
.param("type", configClass.getConfigClass())
.param("prefix", configClass.getPrefix());

Expand Down Expand Up @@ -367,6 +369,7 @@ void registerConfigPropertiesBean(
createStringValue("prefix", configClass.getPrefix())
}))
.creator(ConfigMappingCreator.class)
.addInjectionPoint(ClassType.create(DotNames.INJECTION_POINT))
.param("type", configClass.getConfigClass())
.param("prefix", configClass.getPrefix())));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
package io.quarkus.arc.runtime;

import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Optional;

import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.Annotated;
import jakarta.enterprise.inject.spi.InjectionPoint;

import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.inject.ConfigProperties;

import io.quarkus.arc.BeanCreator;
import io.quarkus.arc.impl.InjectionPointProvider;
import io.quarkus.arc.SyntheticCreationalContext;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.SmallRyeConfig;

public class ConfigMappingCreator implements BeanCreator<Object> {

@Override
public Object create(CreationalContext<Object> creationalContext, Map<String, Object> params) {
InjectionPoint injectionPoint = InjectionPointProvider.get();
public Object create(SyntheticCreationalContext<Object> context) {
InjectionPoint injectionPoint = context.getInjectedReference(InjectionPoint.class);
if (injectionPoint == null) {
throw new IllegalStateException("No current injection point found");
}

Class<?> interfaceType = (Class<?>) params.get("type");
String prefix = (String) params.get("prefix");
Class<?> interfaceType = (Class<?>) context.getParams().get("type");
String prefix = (String) context.getParams().get("prefix");

SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig();
return config.getConfigMapping(interfaceType, getPrefixFromInjectionPoint(injectionPoint).orElse(prefix));
Expand Down

0 comments on commit c411487

Please sign in to comment.