Skip to content

Commit

Permalink
Try to reproduce missing mapping in ConfigRecorder - DO NOT MERGE
Browse files Browse the repository at this point in the history
radcortez committed Nov 20, 2024
1 parent 528dc23 commit 70f25ec
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -9,15 +9,19 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.ConfigValue;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.jboss.logging.Logger;

import io.quarkus.runtime.ConfigConfig;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

@Recorder
public class ConfigRecorder {
@@ -64,6 +68,22 @@ public void handleConfigChange(Map<String, ConfigValue> buildTimeRuntimeValues)
BuildTimeMismatchAtRuntime buildTimeMismatchAtRuntime = config
.getOptionalValue("quarkus.config.build-time-mismatch-at-runtime", BuildTimeMismatchAtRuntime.class)
.orElse(warn);

// Maybe it is a different instance?
SmallRyeConfig quarkusConfig = new QuarkusConfigFactory().getConfigFor(null, null);
if (!config.equals(quarkusConfig)) {
throw new IllegalStateException("SmallRyeConfig Classloaders mismatch!");
}

// Is it missing from the customizer?
SmallRyeConfigBuilder mappingBuilder = new SmallRyeConfigBuilder();
AbstractConfigBuilder.withCustomizer(mappingBuilder, "io.quarkus.runtime.generated.RunTimeConfig");
mappingBuilder.withCustomizers(new MissingMappingConfigBuilderCustomizer());
mappingBuilder.build();

// Does this fail even if present in the builder?
config.getConfigMapping(ConfigConfig.class);

if (fail.equals(buildTimeMismatchAtRuntime)) {
throw new IllegalStateException(msg);
} else if (warn.equals(buildTimeMismatchAtRuntime)) {
@@ -72,6 +92,23 @@ public void handleConfigChange(Map<String, ConfigValue> buildTimeRuntimeValues)
}
}

static class MissingMappingConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer {
@Override
public void configBuilder(final SmallRyeConfigBuilder builder) {
Map<Class<?>, Set<String>> mappings = builder.getMappingsBuilder().getMappings();
for (Map.Entry<Class<?>, Set<String>> entry : mappings.entrySet()) {
for (String prefix : entry.getValue()) {
log.info("Found mapping " + entry.getKey() + " with prefix " + prefix);
}
}
}

@Override
public int priority() {
return Integer.MAX_VALUE;
}
}

public void handleNativeProfileChange(List<String> buildProfiles) {
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
List<String> runtimeProfiles = config.getProfiles();

0 comments on commit 70f25ec

Please sign in to comment.