Skip to content

Commit

Permalink
Merge pull request quarkusio#43513 from mcruzdev/issue-43394
Browse files Browse the repository at this point in the history
Show nicer error when a @ConfigMapping class exists in the deployment module and set to the runtime phase
  • Loading branch information
geoand authored Dec 13, 2024
2 parents d8069b0 + c43e0dc commit e2db51c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import io.quarkus.annotation.processor.documentation.config.discovery.EnumDefinition;
import io.quarkus.annotation.processor.documentation.config.discovery.EnumDefinition.EnumConstant;
import io.quarkus.annotation.processor.documentation.config.discovery.ResolvedType;
import io.quarkus.annotation.processor.documentation.config.model.ConfigPhase;
import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule;
import io.quarkus.annotation.processor.documentation.config.util.Types;
import io.quarkus.annotation.processor.util.Config;
import io.quarkus.annotation.processor.util.Utils;
Expand Down Expand Up @@ -66,6 +68,18 @@ public void onResolvedEnum(TypeElement enumTypeElement) {
configCollector.addResolvedEnum(enumDefinition);
}

protected void validateRuntimeConfigOnDeploymentModules(ConfigPhase configPhase, TypeElement configRoot) {
if (configPhase.equals(ConfigPhase.RUN_TIME) || configPhase.equals(ConfigPhase.BUILD_AND_RUN_TIME_FIXED)) {
ExtensionModule.ExtensionModuleType type = config.getExtensionModule().type();
if (type.equals(ExtensionModule.ExtensionModuleType.DEPLOYMENT)) {
throw new IllegalStateException(String.format(
"Error on %s: Configuration classes with ConfigPhase.RUN_TIME or " +
"ConfigPhase.BUILD_AND_RUNTIME_FIXED phases, must reside in the respective module.",
configRoot.getSimpleName().toString()));
}
}
}

protected void handleCommonPropertyAnnotations(DiscoveryConfigProperty.Builder builder,
Map<String, AnnotationMirror> propertyAnnotations, ResolvedType resolvedType, String sourceElementName) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {
}
}

validateRuntimeConfigOnDeploymentModules(configPhase, configRoot);

for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : configMappingAnnotion.getElementValues()
.entrySet()) {
if ("prefix()".equals(entry.getKey().toString())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {
}
}

validateRuntimeConfigOnDeploymentModules(configPhase, configRoot);

String overriddenDocPrefix = null;
if (configDocPrefixAnnotation != null) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : configDocPrefixAnnotation
Expand Down

0 comments on commit e2db51c

Please sign in to comment.