Skip to content

Commit

Permalink
Show a better error when runtime config is on deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mcruzdev committed Sep 28, 2024
1 parent 1ff7c69 commit bf90dd3
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static io.quarkus.deployment.util.ReflectUtil.toError;
import static io.quarkus.deployment.util.ReflectUtil.typeOfParameter;
import static io.quarkus.deployment.util.ReflectUtil.unwrapInvocationTargetException;
import static io.quarkus.runtime.configuration.PropertiesUtil.isPropertyInRoots;
import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix;
import static io.smallrye.config.Expressions.withoutExpansion;
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
Expand Down Expand Up @@ -39,6 +38,7 @@
import org.jboss.logging.Logger;
import org.wildfly.common.Assert;

import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.configuration.definition.ClassDefinition;
import io.quarkus.deployment.configuration.definition.ClassDefinition.ClassMember;
import io.quarkus.deployment.configuration.definition.ClassDefinition.GroupMember;
Expand Down Expand Up @@ -164,6 +164,7 @@ private BuildTimeConfigurationReader(ClassLoader classLoader, final List<Class<?
runTimeMappings = new ArrayList<>();

Map<Class<?>, GroupDefinition> groups = new HashMap<>();
log.info(">>> I am running here!");
for (Class<?> configRoot : configRoots) {
boolean isMapping = configRoot.isAnnotationPresent(ConfigMapping.class);
if (isMapping) {
Expand All @@ -184,6 +185,9 @@ private BuildTimeConfigurationReader(ClassLoader classLoader, final List<Class<?
}

ConfigClassWithPrefix mapping = configClassWithPrefix(configRoot);

checkIfIsOnDeploymentModule(configRoot, phase);

if (phase.equals(ConfigPhase.BUILD_TIME)) {
buildTimeMappings.add(mapping);
} else if (phase.equals(ConfigPhase.BUILD_AND_RUN_TIME_FIXED)) {
Expand All @@ -204,6 +208,9 @@ private BuildTimeConfigurationReader(ClassLoader classLoader, final List<Class<?
name = annotation.name();
phase = annotation.phase();
}

checkIfIsOnDeploymentModule(configRoot, phase);

RootDefinition.Builder defBuilder = new RootDefinition.Builder();
defBuilder.setPrefix(prefix);
defBuilder.setConfigPhase(phase);
Expand Down Expand Up @@ -244,6 +251,17 @@ private BuildTimeConfigurationReader(ClassLoader classLoader, final List<Class<?
buildConfigTracker = new ConfigTrackingInterceptor();
}

private static void checkIfIsOnDeploymentModule(Class<?> configRoot, ConfigPhase phase) {
if (phase.equals(ConfigPhase.RUN_TIME) || phase.equals(ConfigPhase.BUILD_AND_RUN_TIME_FIXED)) {
boolean isPresentAtDeployment = !QuarkusClassLoader.isClassPresentAtRuntime(configRoot.getName());
if (isPresentAtDeployment) {
throw reportError(configRoot,
"Configuration classes with ConfigPhase.RUN_TIME or ConfigPhase.BUILD_AND_RUNTIME_FIXED " +
"phases, must be on runtime module.");
}
}
}

private static void processClass(ClassDefinition.Builder builder, Class<?> clazz,
final Map<Class<?>, GroupDefinition> groups) {
builder.setConfigurationClass(clazz);
Expand Down

0 comments on commit bf90dd3

Please sign in to comment.