From ce6b94470401bf7a640016fd852a5355defe18a1 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 21 Jan 2025 15:46:09 +0100 Subject: [PATCH 1/5] Use @ConfigMapping in SmallRye GraphQL server --- .../smallrye-graphql/deployment/pom.xml | 3 - .../deployment/SmallRyeGraphQLProcessor.java | 50 ++++---- .../devui/SmallRyeGraphQLDevUIProcessor.java | 4 +- extensions/smallrye-graphql/runtime/pom.xml | 3 - .../runtime/SmallRyeGraphQLConfig.java | 117 ++++++++---------- .../runtime/SmallRyeGraphQLRecorder.java | 6 +- .../runtime/SmallRyeGraphQLRuntimeConfig.java | 27 ++-- .../runtime/SmallRyeGraphQLUIConfig.java | 12 +- 8 files changed, 104 insertions(+), 118 deletions(-) diff --git a/extensions/smallrye-graphql/deployment/pom.xml b/extensions/smallrye-graphql/deployment/pom.xml index 4e210b0e3950a..25b1dd953a3c8 100644 --- a/extensions/smallrye-graphql/deployment/pom.xml +++ b/extensions/smallrye-graphql/deployment/pom.xml @@ -105,9 +105,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java index 1c8d9373e90e9..772cb3b2bed67 100644 --- a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java @@ -359,9 +359,9 @@ void buildExecutionService( Optional graphQLDevUILogBuildItem) { activateFederation(graphQLConfig, systemPropertyProducer, graphQLFinalIndexBuildItem); - graphQLConfig.extraScalars.ifPresent(this::registerExtraScalarsInSchema); + graphQLConfig.extraScalars().ifPresent(this::registerExtraScalarsInSchema); Schema schema = SchemaBuilder.build(graphQLFinalIndexBuildItem.getFinalIndex(), - Converters.getImplicitConverter(TypeAutoNameStrategy.class).convert(graphQLConfig.autoNameStrategy)); + Converters.getImplicitConverter(TypeAutoNameStrategy.class).convert(graphQLConfig.autoNameStrategy())); Optional publisher = Optional.empty(); if (graphQLDevUILogBuildItem.isPresent()) { @@ -402,10 +402,10 @@ void buildSchemaEndpoint( SmallRyeGraphQLConfig graphQLConfig) { Handler schemaHandler = recorder.schemaHandler(graphQLInitializedBuildItem.getInitialized(), - graphQLConfig.schemaAvailable); + graphQLConfig.schemaAvailable()); routeProducer.produce(httpRootPathBuildItem.routeBuilder() - .nestedRoute(graphQLConfig.rootPath, SCHEMA_PATH) + .nestedRoute(graphQLConfig.rootPath(), SCHEMA_PATH) .handler(schemaHandler) .displayOnNotFoundPage("MicroProfile GraphQL Schema") .build()); @@ -449,12 +449,12 @@ void buildExecutionEndpoint( runBlocking); HttpRootPathBuildItem.Builder subscriptionsBuilder = httpRootPathBuildItem.routeBuilder() - .orderedRoute(graphQLConfig.rootPath, GRAPHQL_WEBSOCKET_HANDLER_ORDER) + .orderedRoute(graphQLConfig.rootPath(), GRAPHQL_WEBSOCKET_HANDLER_ORDER) .handler(graphqlOverWebsocketHandler); routeProducer.produce(subscriptionsBuilder.build()); // WebSocket subprotocols - graphQLConfig.websocketSubprotocols.ifPresentOrElse(subprotocols -> { + graphQLConfig.websocketSubprotocols().ifPresentOrElse(subprotocols -> { for (String subprotocol : subprotocols) { if (!SUPPORTED_WEBSOCKET_SUBPROTOCOLS.contains(subprotocol)) { throw new IllegalArgumentException("Unknown websocket subprotocol: " + subprotocol); @@ -479,7 +479,7 @@ void buildExecutionEndpoint( allowGet, allowQueryParametersOnPost, runBlocking, allowCompression); HttpRootPathBuildItem.Builder requestBuilder = httpRootPathBuildItem.routeBuilder() - .routeFunction(graphQLConfig.rootPath, recorder.routeFunction(bodyHandlerBuildItem.getHandler())) + .routeFunction(graphQLConfig.rootPath(), recorder.routeFunction(bodyHandlerBuildItem.getHandler())) .handler(executionHandler) .routeConfigKey("quarkus.smallrye-graphql.root-path") .displayOnNotFoundPage("MicroProfile GraphQL Endpoint"); @@ -516,8 +516,8 @@ private Set getAdapterClasses(IndexView index, DotName adapterClass) { } private boolean shouldRunBlockingRoute(SmallRyeGraphQLConfig graphQLConfig) { - if (graphQLConfig.nonBlockingEnabled.isPresent()) { - return !graphQLConfig.nonBlockingEnabled.get(); + if (graphQLConfig.nonBlockingEnabled().isPresent()) { + return !graphQLConfig.nonBlockingEnabled().get(); } return false; } @@ -647,13 +647,13 @@ void printDataFetcherExceptionInDevMode(SmallRyeGraphQLConfig graphQLConfig, BuildProducer systemProperties) { // User did not set this explicitly - if (!graphQLConfig.printDataFetcherException.isPresent()) { + if (!graphQLConfig.printDataFetcherException().isPresent()) { if (launchMode.getLaunchMode().isDevOrTest()) { systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.PRINT_DATAFETCHER_EXCEPTION, TRUE)); } } else { systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.PRINT_DATAFETCHER_EXCEPTION, - String.valueOf(graphQLConfig.printDataFetcherException.get()))); + String.valueOf(graphQLConfig.printDataFetcherException().get()))); } } // Services Integrations @@ -664,7 +664,7 @@ void activateMetrics(Capabilities capabilities, SmallRyeGraphQLConfig graphQLConfig, BuildProducer systemProperties, BuildProducer serviceProvider) { - if (graphQLConfig.metricsEnabled.orElse(false) + if (graphQLConfig.metricsEnabled().orElse(false) || Config.get().getConfigValue(ConfigKey.ENABLE_METRICS, boolean.class, false)) { metricsCapability.ifPresentOrElse(capability -> { if (capability.metricsSupported(MetricsFactory.MICROMETER)) { @@ -689,7 +689,7 @@ void activateTracing(Capabilities capabilities, BuildProducer systemProperties, BuildProducer unremovableBeans) { - boolean activate = shouldActivateService(graphQLConfig.tracingEnabled, + boolean activate = shouldActivateService(graphQLConfig.tracingEnabled(), capabilities.isPresent(Capability.OPENTELEMETRY_TRACER), "quarkus-opentelemetry", Capability.OPENTELEMETRY_TRACER, @@ -704,7 +704,7 @@ void activateTracing(Capabilities capabilities, @BuildStep void activateEventing(SmallRyeGraphQLConfig graphQLConfig, BuildProducer systemProperties) { - if (graphQLConfig.eventsEnabled) { + if (graphQLConfig.eventsEnabled()) { systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_EVENTS, TRUE)); } else { systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_EVENTS, FALSE)); @@ -714,8 +714,8 @@ void activateEventing(SmallRyeGraphQLConfig graphQLConfig, BuildProducer systemProperties) { - if (graphQLConfig.federationBatchResolvingEnabled.isPresent()) { - String value = graphQLConfig.federationBatchResolvingEnabled.get().toString(); + if (graphQLConfig.federationBatchResolvingEnabled().isPresent()) { + String value = graphQLConfig.federationBatchResolvingEnabled().get().toString(); systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_FEDERATION_BATCH_RESOLVING, value)); System.setProperty(ConfigKey.ENABLE_FEDERATION_BATCH_RESOLVING, value); } @@ -737,8 +737,8 @@ void activateFederationBatchResolving(SmallRyeGraphQLConfig graphQLConfig, void activateFederation(SmallRyeGraphQLConfig config, BuildProducer systemProperties, SmallRyeGraphQLFinalIndexBuildItem index) { - if (config.federationEnabled.isPresent()) { - String value = config.federationEnabled.get().toString(); + if (config.federationEnabled().isPresent()) { + String value = config.federationEnabled().get().toString(); systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_FEDERATION, value)); System.setProperty(ConfigKey.ENABLE_FEDERATION, value); } else { @@ -791,14 +791,14 @@ void getGraphqlUiFinalDestination( if (shouldInclude(launchMode, graphQLConfig)) { - if ("/".equals(graphQLConfig.ui.rootPath)) { + if ("/".equals(graphQLConfig.ui().rootPath())) { throw new ConfigurationException( "quarkus.smallrye-graphql.root-path-ui was set to \"/\", this is not allowed as it blocks the application from serving anything else.", Collections.singleton("quarkus.smallrye-graphql.root-path-ui")); } - String graphQLPath = httpRootPath.resolvePath(graphQLConfig.rootPath); - String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui.rootPath); + String graphQLPath = httpRootPath.resolvePath(graphQLConfig.rootPath()); + String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui().rootPath()); String devUiPath = nonApplicationRootPathBuildItem.resolvePath("dev"); webJarBuildProducer.produce( @@ -847,21 +847,21 @@ void registerGraphQLUiHandler( } if (shouldInclude(launchMode, graphQLConfig)) { - String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui.rootPath); + String graphQLUiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui().rootPath()); smallRyeGraphQLBuildProducer .produce(new SmallRyeGraphQLBuildItem(result.getFinalDestination(), graphQLUiPath)); Handler handler = recorder.uiHandler(result.getFinalDestination(), graphQLUiPath, result.getWebRootConfigurations(), runtimeConfig, shutdownContext); routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() - .route(graphQLConfig.ui.rootPath) + .route(graphQLConfig.ui().rootPath()) .displayOnNotFoundPage("GraphQL UI") .routeConfigKey("quarkus.smallrye-graphql.ui.root-path") .handler(handler) .build()); routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() - .route(graphQLConfig.ui.rootPath + "*") + .route(graphQLConfig.ui().rootPath() + "*") .handler(handler) .build()); @@ -889,7 +889,7 @@ private String getLogoUrl(LaunchModeBuildItem launchMode, String devUIValue, Str } private static boolean shouldInclude(LaunchModeBuildItem launchMode, SmallRyeGraphQLConfig graphQLConfig) { - return launchMode.getLaunchMode().isDevOrTest() || graphQLConfig.ui.alwaysInclude; + return launchMode.getLaunchMode().isDevOrTest() || graphQLConfig.ui().alwaysInclude(); } private String updateUrl(String original, String path, String lineStartsWith, String format) { diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/devui/SmallRyeGraphQLDevUIProcessor.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/devui/SmallRyeGraphQLDevUIProcessor.java index 7b5c516eb9335..3245dfc6f186a 100644 --- a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/devui/SmallRyeGraphQLDevUIProcessor.java +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/devui/SmallRyeGraphQLDevUIProcessor.java @@ -18,13 +18,13 @@ CardPageBuildItem createCard(NonApplicationRootPathBuildItem nonApplicationRootP CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); // Generated GraphQL Schema - String schemaPath = "/" + graphQLConfig.rootPath + "/schema.graphql"; + String schemaPath = "/" + graphQLConfig.rootPath() + "/schema.graphql"; PageBuilder schemaPage = Page.externalPageBuilder("GraphQL Schema") .icon("font-awesome-solid:diagram-project") .url(schemaPath, schemaPath); // GraphiQL UI - String uiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui.rootPath); + String uiPath = nonApplicationRootPathBuildItem.resolvePath(graphQLConfig.ui().rootPath()); PageBuilder uiPage = Page.externalPageBuilder("GraphQL UI") .icon("font-awesome-solid:table-columns") .url(uiPath + "/index.html?embed=true", uiPath); diff --git a/extensions/smallrye-graphql/runtime/pom.xml b/extensions/smallrye-graphql/runtime/pom.xml index 4bca2a4e46d8e..8f8099ba84704 100644 --- a/extensions/smallrye-graphql/runtime/pom.xml +++ b/extensions/smallrye-graphql/runtime/pom.xml @@ -85,9 +85,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java index 74d4b382698a9..ef2e93775940f 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java @@ -2,203 +2,194 @@ import java.util.List; import java.util.Optional; +import java.util.OptionalInt; import io.quarkus.runtime.annotations.ConfigDocSection; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; import io.smallrye.graphql.spi.config.LogPayloadOption; -@ConfigRoot(name = "smallrye-graphql", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) -public class SmallRyeGraphQLConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +@ConfigMapping(prefix = "quarkus.smallrye-graphql") +public interface SmallRyeGraphQLConfig { /** * The rootPath under which queries will be served. Default to graphql * By default, this value will be resolved as a path relative to `${quarkus.http.root-path}`. */ - @ConfigItem(defaultValue = "graphql") - public String rootPath; + @WithDefault("graphql") + String rootPath(); /** * Enable Apollo Federation. If this value is unspecified, then federation will be enabled * automatically if any GraphQL Federation annotations are detected in the application. */ - @ConfigItem(name = "federation.enabled") - public Optional federationEnabled; + @WithName("federation.enabled") + Optional federationEnabled(); /** * Enable batch resolving for federation. Disabled by default. */ - @ConfigItem(name = "federation.batch-resolving-enabled") - public Optional federationBatchResolvingEnabled; + @WithName("federation.batch-resolving-enabled") + Optional federationBatchResolvingEnabled(); /** * Enable metrics. By default, this is false. If set to true, a metrics extension is required. */ - @ConfigItem(name = "metrics.enabled") - public Optional metricsEnabled; + @WithName("metrics.enabled") + Optional metricsEnabled(); /** * Enable tracing. By default, this will be enabled if the tracing extension is added. */ - @ConfigItem(name = "tracing.enabled") - public Optional tracingEnabled; + @WithName("tracing.enabled") + Optional tracingEnabled(); /** * Enable eventing. Allow you to receive events on bootstrap and execution. */ - @ConfigItem(name = "events.enabled", defaultValue = "false") - public boolean eventsEnabled; + @WithName("events.enabled") + @WithDefault("false") + boolean eventsEnabled(); /** * Enable non-blocking support. Default is true. */ - @ConfigItem(name = "nonblocking.enabled") - public Optional nonBlockingEnabled; + @WithName("nonblocking.enabled") + Optional nonBlockingEnabled(); /** * Enable GET Requests. Allow queries via HTTP GET. */ - @ConfigItem(name = "http.get.enabled") - public Optional httpGetEnabled; + @WithName("http.get.enabled") + Optional httpGetEnabled(); /** * Enable Query parameter on POST Requests. Allow POST request to override or supply values in a query parameter. */ - @ConfigItem(name = "http.post.queryparameters.enabled") - public Optional httpPostQueryParametersEnabled; + @WithName("http.post.queryparameters.enabled") + Optional httpPostQueryParametersEnabled(); /** * Change the type naming strategy. * All possible strategies are: default, merge-inner-class, full */ - @ConfigItem(defaultValue = "Default") - public String autoNameStrategy; + @WithDefault("Default") + String autoNameStrategy(); /** * List of extension fields that should be included in the error response. * By default, none will be included. Examples of valid values include * [exception,classification,code,description,validationErrorType,queryPath] */ - @ConfigItem - public Optional> errorExtensionFields; + Optional> errorExtensionFields(); /** * The default error message that will be used for hidden exception messages. * Defaults to "Server Error" */ - @ConfigItem - public Optional defaultErrorMessage; + Optional defaultErrorMessage(); /** * Print the data fetcher exception to the log file. Default `true` in dev and test mode, default `false` in prod. */ - @ConfigItem - public Optional printDataFetcherException; + Optional printDataFetcherException(); /** * Make the schema available over HTTP. */ - @ConfigItem(defaultValue = "true") - public boolean schemaAvailable; + @WithDefault("true") + boolean schemaAvailable(); /** * Include the Scalar definitions in the schema. */ - @ConfigItem(defaultValue = "false") - public boolean schemaIncludeScalars; + @WithDefault("false") + boolean schemaIncludeScalars(); /** * Include the schema internal definition in the schema. */ - @ConfigItem(defaultValue = "false") - public boolean schemaIncludeSchemaDefinition; + @WithDefault("false") + boolean schemaIncludeSchemaDefinition(); /** * Include Directives in the schema. */ - @ConfigItem(defaultValue = "false") - public boolean schemaIncludeDirectives; + @WithDefault("false") + boolean schemaIncludeDirectives(); /** * Include Introspection Types in the schema. */ - @ConfigItem(defaultValue = "false") - public boolean schemaIncludeIntrospectionTypes; + @WithDefault("false") + boolean schemaIncludeIntrospectionTypes(); /** * Log the payload (and optionally variables) to System out. */ - @ConfigItem(defaultValue = "off") - public LogPayloadOption logPayload; + @WithDefault("off") + LogPayloadOption logPayload(); /** * Exceptions that should be unwrapped (class names). */ - @ConfigItem - public Optional> unwrapExceptions; + Optional> unwrapExceptions(); /** * Subprotocols that should be supported by the server for graphql-over-websocket use cases. * Allowed subprotocols are "graphql-ws" and "graphql-transport-ws". By default, both are enabled. */ - @ConfigItem - public Optional> websocketSubprotocols; + Optional> websocketSubprotocols(); /** * Set to true if ignored chars should be captured as AST nodes. Default to false */ - @ConfigItem - public Optional parserCaptureIgnoredChars; + Optional parserCaptureIgnoredChars(); /** * Set to true if `graphql.language.Comment`s should be captured as AST nodes */ - @ConfigItem - public Optional parserCaptureLineComments; + Optional parserCaptureLineComments(); /** * Set to true true if `graphql.language.SourceLocation`s should be captured as AST nodes. Default to true */ - @ConfigItem - public Optional parserCaptureSourceLocation; + Optional parserCaptureSourceLocation(); /** * The maximum number of raw tokens the parser will accept, after which an exception will be thrown. Default to 15000 */ - @ConfigItem - public Optional parserMaxTokens; + OptionalInt parserMaxTokens(); /** * The maximum number of raw whitespace tokens the parser will accept, after which an exception will be thrown. Default to * 200000 */ - @ConfigItem - public Optional parserMaxWhitespaceTokens; + OptionalInt parserMaxWhitespaceTokens(); /** * Abort a query if the total number of data fields queried exceeds the defined limit. Default to no limit */ - @ConfigItem - public Optional instrumentationQueryComplexity; + OptionalInt instrumentationQueryComplexity(); /** * Abort a query if the total depth of the query exceeds the defined limit. Default to no limit */ - @ConfigItem - public Optional instrumentationQueryDepth; + OptionalInt instrumentationQueryDepth(); /** * SmallRye GraphQL UI configuration */ - @ConfigItem @ConfigDocSection - public SmallRyeGraphQLUIConfig ui; + SmallRyeGraphQLUIConfig ui(); /** * Additional scalars to register in the schema. * These are taken from the `graphql-java-extended-scalars` library. */ - @ConfigItem - public Optional> extraScalars; + Optional> extraScalars(); } diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java index 1378ba001b72c..b0d0487989932 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java @@ -37,8 +37,8 @@ public RuntimeValue createExecutionService(BeanContainer beanContainer, SmallRyeGraphQLConfig graphQLConfig, Optional>> publisher) { GraphQLProducer graphQLProducer = beanContainer.beanInstance(GraphQLProducer.class); - if (graphQLConfig.extraScalars.isPresent()) { - registerExtraScalars(graphQLConfig.extraScalars.get()); + if (graphQLConfig.extraScalars().isPresent()) { + registerExtraScalars(graphQLConfig.extraScalars().get()); } if (publisher.isPresent()) { graphQLProducer.setTraficPublisher(publisher.get().getValue()); @@ -91,7 +91,7 @@ public Handler uiHandler(String graphqlUiFinalDestination, String graphqlUiPath, List webRootConfigurations, SmallRyeGraphQLRuntimeConfig runtimeConfig, ShutdownContext shutdownContext) { - if (runtimeConfig.enable) { + if (runtimeConfig.enable()) { WebJarStaticHandler handler = new WebJarStaticHandler(graphqlUiFinalDestination, graphqlUiPath, webRootConfigurations); shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(handler)); diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRuntimeConfig.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRuntimeConfig.java index e74025abcb765..32b824dae80f2 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRuntimeConfig.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRuntimeConfig.java @@ -3,18 +3,22 @@ import java.util.List; import java.util.Optional; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "smallrye-graphql", phase = ConfigPhase.RUN_TIME) -public class SmallRyeGraphQLRuntimeConfig { +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +@ConfigMapping(prefix = "quarkus.smallrye-graphql") +public interface SmallRyeGraphQLRuntimeConfig { /** * If GraphQL UI should be enabled. By default, GraphQL UI is enabled if it is included (see {@code always-include}). */ - @ConfigItem(name = "ui.enable", defaultValue = "true") - boolean enable; + @WithName("ui.enable") + @WithDefault("true") + boolean enable(); /** * Specifies the field visibility for the GraphQL schema. @@ -24,28 +28,25 @@ public class SmallRyeGraphQLRuntimeConfig { * For more info see graphql-java * documentation */ - @ConfigItem(defaultValue = "default") - public String fieldVisibility; + @WithDefault("default") + String fieldVisibility(); /** * Excludes all the 'null' fields in the GraphQL response's data field, * except for the non-successfully resolved fields (errors). * Disabled by default. */ - @ConfigItem - public Optional excludeNullFieldsInResponses; + Optional excludeNullFieldsInResponses(); /** * List of Runtime Exceptions class names that should show the error message. * By default, Runtime Exception messages will be hidden and a generic `Server Error` message will be returned. */ - @ConfigItem - public Optional> showRuntimeExceptionMessage; + Optional> showRuntimeExceptionMessage(); /** * List of Checked Exceptions class names that should hide the error message. * By default, Checked Exception messages will show the exception message. */ - @ConfigItem - public Optional> hideCheckedExceptionMessage; + Optional> hideCheckedExceptionMessage(); } diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLUIConfig.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLUIConfig.java index f71b0069116f2..0271fb28ff127 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLUIConfig.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLUIConfig.java @@ -1,23 +1,23 @@ package io.quarkus.smallrye.graphql.runtime; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class SmallRyeGraphQLUIConfig { +public interface SmallRyeGraphQLUIConfig { /** * The path where GraphQL UI is available. * The value `/` is not allowed as it blocks the application from serving anything else. * By default, this URL will be resolved as a path relative to `${quarkus.http.non-application-root-path}`. */ - @ConfigItem(defaultValue = "graphql-ui") - public String rootPath; + @WithDefault("graphql-ui") + String rootPath(); /** * Always include the UI. By default, this will only be included in dev and test. * Setting this to true will also include the UI in Prod */ - @ConfigItem(defaultValue = "false") - public boolean alwaysInclude; + @WithDefault("false") + boolean alwaysInclude(); } From f90a67d68759eb64bff0ee714c28c64b511f8c44 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 21 Jan 2025 16:02:53 +0100 Subject: [PATCH 2/5] Use @ConfigMapping in SmallRye Health Also drop the deprecated configuration (it's present in at least one LTS as it has been deprecated in 3.14) and rationalize the config classes (we had two config classes with the exact same scope). --- extensions/smallrye-health/deployment/pom.xml | 3 - .../DeprecatedHealthBuildTimeConfig.java | 34 ------- .../deployment/SmallRyeHealthActive.java | 2 +- .../SmallRyeHealthBuildTimeConfig.java | 99 +++++++++++++++++-- .../deployment/SmallRyeHealthConfig.java | 88 ----------------- .../SmallRyeHealthDevUiProcessor.java | 10 +- .../deployment/SmallRyeHealthProcessor.java | 79 +++++++-------- .../deployment/SmallRyeHealthUIConfig.java | 12 +-- .../test/DeprecatedHealthOpenAPITest.java | 48 --------- extensions/smallrye-health/runtime/pom.xml | 3 - .../SmallRyeHealthBuildFixedConfig.java | 12 ++- .../runtime/SmallRyeHealthRecorder.java | 10 +- .../runtime/SmallRyeHealthRuntimeConfig.java | 26 ++--- .../src/main/resources/application.properties | 2 +- 14 files changed, 167 insertions(+), 261 deletions(-) delete mode 100644 extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/DeprecatedHealthBuildTimeConfig.java delete mode 100644 extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java delete mode 100644 extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeprecatedHealthOpenAPITest.java diff --git a/extensions/smallrye-health/deployment/pom.xml b/extensions/smallrye-health/deployment/pom.xml index 50ba3ea09d60b..c303c6266e3f5 100644 --- a/extensions/smallrye-health/deployment/pom.xml +++ b/extensions/smallrye-health/deployment/pom.xml @@ -93,9 +93,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/DeprecatedHealthBuildTimeConfig.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/DeprecatedHealthBuildTimeConfig.java deleted file mode 100644 index 8b3473ec9a5f0..0000000000000 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/DeprecatedHealthBuildTimeConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.quarkus.smallrye.health.deployment; - -import io.quarkus.runtime.annotations.ConfigItem; -import io.quarkus.runtime.annotations.ConfigRoot; - -/** - * This class is deprecated, don't add any more properties here. - * - * When dropping this class please make the properties in {@link SmallRyeHealthBuildTimeConfig} non optional. - * - * @deprecated Use {@link SmallRyeHealthBuildTimeConfig} instead. - */ -@ConfigRoot(name = "health") -@Deprecated(since = "3.14", forRemoval = true) -public class DeprecatedHealthBuildTimeConfig { - - /** - * Whether extensions published health check should be enabled. - * - * @deprecated Use {@code quarkus.smallrye-health.extensions.enabled} instead. - */ - @ConfigItem(name = "extensions.enabled", defaultValue = "true") - @Deprecated(since = "3.14", forRemoval = true) - public boolean extensionsEnabled; - - /** - * Whether to include the Liveness and Readiness Health endpoints in the generated OpenAPI document - * - * @deprecated Use {@code quarkus.smallrye-health.openapi.included} instead. - */ - @ConfigItem(name = "openapi.included", defaultValue = "false") - @Deprecated(since = "3.14", forRemoval = true) - public boolean openapiIncluded; -} diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthActive.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthActive.java index c5fe90ce7e69a..a2ef015093b61 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthActive.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthActive.java @@ -12,7 +12,7 @@ public class SmallRyeHealthActive implements BooleanSupplier { @Override public boolean getAsBoolean() { - return config.enabled; + return config.enabled(); } } diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthBuildTimeConfig.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthBuildTimeConfig.java index 29ceda99da53e..c7cf6d853fff6 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthBuildTimeConfig.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthBuildTimeConfig.java @@ -1,27 +1,108 @@ package io.quarkus.smallrye.health.deployment; import java.util.Optional; +import java.util.OptionalInt; -import io.quarkus.runtime.annotations.ConfigItem; +import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "smallrye-health") -public class SmallRyeHealthBuildTimeConfig { +@ConfigRoot +@ConfigMapping(prefix = "quarkus.smallrye-health") +public interface SmallRyeHealthBuildTimeConfig { /** * Activate or disable this extension. Disabling this extension means that no health related information is exposed. */ - @ConfigItem(defaultValue = "true") - public boolean enabled; + @WithDefault("true") + boolean enabled(); /** * Whether extensions published health check should be enabled. */ - @ConfigItem(name = "extensions.enabled", defaultValueDocumentation = "true") - public Optional extensionsEnabled; + @WithName("extensions.enabled") + @WithDefault("true") + boolean extensionsEnabled(); /** * Whether to include the Liveness and Readiness Health endpoints in the generated OpenAPI document */ - @ConfigItem(name = "openapi.included", defaultValueDocumentation = "false") - public Optional openapiIncluded; + @WithName("openapi.included") + @WithDefault("false") + boolean openapiIncluded(); + + /** + * Root path for health-checking endpoints. + * By default, this value will be resolved as a path relative to `${quarkus.http.non-application-root-path}`. + * If the management interface is enabled, the value will be resolved as a path relative to + * `${quarkus.management.root-path}`. + */ + @WithDefault("health") + String rootPath(); + + /** + * The relative path of the liveness health-checking endpoint. + * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. + */ + @WithDefault("live") + String livenessPath(); + + /** + * The relative path of the readiness health-checking endpoint. + * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. + */ + @WithDefault("ready") + String readinessPath(); + + /** + * The relative path of the health group endpoint. + * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. + */ + @WithDefault("group") + String groupPath(); + + /** + * The relative path of the wellness health-checking endpoint. + * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. + */ + @WithDefault("well") + String wellnessPath(); + + /** + * The relative path of the startup health-checking endpoint. + * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. + */ + @WithDefault("started") + String startupPath(); + + /** + * Whether the context should be propagated to each health check invocation. + */ + @WithDefault("false") + boolean contextPropagation(); + + /** + * The number of the maximum health groups that can be created. + */ + OptionalInt maxGroupRegistriesCount(); + + /** + * The name of the default health group used when no other health group is defined on the health check. + */ + Optional defaultHealthGroup(); + + /** + * If management interface is turned on the health endpoints and ui will be published under the management interface. This + * allows you to exclude Health from management by setting the value to false + */ + @WithName("management.enabled") + @WithDefault("true") + boolean managementEnabled(); + + /** + * SmallRye Health UI configuration + */ + @ConfigDocSection + SmallRyeHealthUIConfig ui(); } diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java deleted file mode 100644 index 79a941fa3e3ce..0000000000000 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthConfig.java +++ /dev/null @@ -1,88 +0,0 @@ -package io.quarkus.smallrye.health.deployment; - -import java.util.Optional; -import java.util.OptionalInt; - -import io.quarkus.runtime.annotations.ConfigDocSection; -import io.quarkus.runtime.annotations.ConfigItem; -import io.quarkus.runtime.annotations.ConfigRoot; - -@ConfigRoot(name = "smallrye-health") -public class SmallRyeHealthConfig { - - /** - * Root path for health-checking endpoints. - * By default, this value will be resolved as a path relative to `${quarkus.http.non-application-root-path}`. - * If the management interface is enabled, the value will be resolved as a path relative to - * `${quarkus.management.root-path}`. - */ - @ConfigItem(defaultValue = "health") - String rootPath; - - /** - * The relative path of the liveness health-checking endpoint. - * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. - */ - @ConfigItem(defaultValue = "live") - String livenessPath; - - /** - * The relative path of the readiness health-checking endpoint. - * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. - */ - @ConfigItem(defaultValue = "ready") - String readinessPath; - - /** - * The relative path of the health group endpoint. - * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. - */ - @ConfigItem(defaultValue = "group") - String groupPath; - - /** - * The relative path of the wellness health-checking endpoint. - * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. - */ - @ConfigItem(defaultValue = "well") - String wellnessPath; - - /** - * The relative path of the startup health-checking endpoint. - * By default, this value will be resolved as a path relative to `${quarkus.smallrye-health.rootPath}`. - */ - @ConfigItem(defaultValue = "started") - String startupPath; - - /** - * Whether the context should be propagated to each health check invocation. - */ - @ConfigItem(defaultValue = "false") - boolean contextPropagation; - - /** - * The number of the maximum health groups that can be created. - */ - @ConfigItem - OptionalInt maxGroupRegistriesCount; - - /** - * The name of the default health group used when no other health group is defined on the health check. - */ - @ConfigItem - Optional defaultHealthGroup; - - /** - * If management interface is turned on the health endpoints and ui will be published under the management interface. This - * allows you to exclude Health from management by setting the value to false - */ - @ConfigItem(name = "management.enabled", defaultValue = "true") - public boolean managementEnabled; - - /** - * SmallRye Health UI configuration - */ - @ConfigItem - @ConfigDocSection - SmallRyeHealthUIConfig ui; -} diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthDevUiProcessor.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthDevUiProcessor.java index 4a9f5b2f79d92..7cd95a5dee02b 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthDevUiProcessor.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthDevUiProcessor.java @@ -19,22 +19,22 @@ public class SmallRyeHealthDevUiProcessor { @BuildStep(onlyIf = IsDevelopment.class) @Record(ExecutionTime.STATIC_INIT) CardPageBuildItem create(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, - SmallRyeHealthConfig config, + SmallRyeHealthBuildTimeConfig config, ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig, LaunchModeBuildItem launchModeBuildItem, SmallRyeHealthRecorder unused) { CardPageBuildItem pageBuildItem = new CardPageBuildItem(); - String path = nonApplicationRootPathBuildItem.resolveManagementPath(config.rootPath, - managementInterfaceBuildTimeConfig, launchModeBuildItem, config.managementEnabled); + String path = nonApplicationRootPathBuildItem.resolveManagementPath(config.rootPath(), + managementInterfaceBuildTimeConfig, launchModeBuildItem, config.managementEnabled()); pageBuildItem.addPage(Page.externalPageBuilder("Health") .icon("font-awesome-solid:heart-circle-bolt") .url(path, path) .isJsonContent()); - String uipath = nonApplicationRootPathBuildItem.resolveManagementPath(config.ui.rootPath, - managementInterfaceBuildTimeConfig, launchModeBuildItem, config.managementEnabled); + String uipath = nonApplicationRootPathBuildItem.resolveManagementPath(config.ui().rootPath(), + managementInterfaceBuildTimeConfig, launchModeBuildItem, config.managementEnabled()); pageBuildItem.addPage(Page.externalPageBuilder("Health UI") .icon("font-awesome-solid:stethoscope") .url(uipath, uipath) diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java index 56e8c21c34b90..b9464551fbd3e 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java @@ -120,10 +120,9 @@ class SmallRyeHealthProcessor { static class OpenAPIIncluded implements BooleanSupplier { SmallRyeHealthBuildTimeConfig smallryeHealthBuildTimeConfig; - DeprecatedHealthBuildTimeConfig deprecatedHealthBuildTimeConfig; public boolean getAsBoolean() { - return smallryeHealthBuildTimeConfig.openapiIncluded.orElse(deprecatedHealthBuildTimeConfig.openapiIncluded); + return smallryeHealthBuildTimeConfig.openapiIncluded(); } } @@ -141,10 +140,8 @@ List brandingFiles() { @BuildStep void healthCheck(BuildProducer buildItemBuildProducer, List healthBuildItems, - SmallRyeHealthBuildTimeConfig smallryeHealthBuildTimeConfig, - DeprecatedHealthBuildTimeConfig deprecatedHealthBuildTimeConfig) { - boolean extensionsEnabled = smallryeHealthBuildTimeConfig.extensionsEnabled - .orElse(deprecatedHealthBuildTimeConfig.extensionsEnabled) && + SmallRyeHealthBuildTimeConfig smallryeHealthBuildTimeConfig) { + boolean extensionsEnabled = smallryeHealthBuildTimeConfig.extensionsEnabled() && !ConfigProvider.getConfig().getOptionalValue("mp.health.disable-default-procedures", boolean.class) .orElse(false); if (extensionsEnabled) { @@ -203,7 +200,7 @@ void build(SmallRyeHealthRecorder recorder, public void defineHealthRoutes(BuildProducer routes, BeanArchiveIndexBuildItem beanArchiveIndex, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, - SmallRyeHealthConfig healthConfig) { + SmallRyeHealthBuildTimeConfig healthConfig) { IndexView index = beanArchiveIndex.getIndex(); // log a warning if users try to use MP Health annotations with JAX-RS @Path @@ -215,7 +212,7 @@ public void defineHealthRoutes(BuildProducer routes, // Register the health handler routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .route(healthConfig.rootPath) + .route(healthConfig.rootPath()) .routeConfigKey("quarkus.smallrye-health.root-path") .handler(new SmallRyeHealthHandler()) .displayOnNotFoundPage() @@ -224,7 +221,7 @@ public void defineHealthRoutes(BuildProducer routes, // Register the liveness handler routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .nestedRoute(healthConfig.rootPath, healthConfig.livenessPath) + .nestedRoute(healthConfig.rootPath(), healthConfig.livenessPath()) .handler(new SmallRyeLivenessHandler()) .displayOnNotFoundPage() .build()); @@ -232,7 +229,7 @@ public void defineHealthRoutes(BuildProducer routes, // Register the readiness handler routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .nestedRoute(healthConfig.rootPath, healthConfig.readinessPath) + .nestedRoute(healthConfig.rootPath(), healthConfig.readinessPath()) .handler(new SmallRyeReadinessHandler()) .displayOnNotFoundPage() .build()); @@ -240,7 +237,7 @@ public void defineHealthRoutes(BuildProducer routes, // Register the health group handlers routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .nestedRoute(healthConfig.rootPath, healthConfig.groupPath) + .nestedRoute(healthConfig.rootPath(), healthConfig.groupPath()) .handler(new SmallRyeHealthGroupHandler()) .displayOnNotFoundPage() .build()); @@ -248,7 +245,7 @@ public void defineHealthRoutes(BuildProducer routes, SmallRyeIndividualHealthGroupHandler handler = new SmallRyeIndividualHealthGroupHandler(); routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .nestedRoute(healthConfig.rootPath, healthConfig.groupPath + "/*") + .nestedRoute(healthConfig.rootPath(), healthConfig.groupPath() + "/*") .handler(handler) .displayOnNotFoundPage() .build()); @@ -256,7 +253,7 @@ public void defineHealthRoutes(BuildProducer routes, // Register the wellness handler routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .nestedRoute(healthConfig.rootPath, healthConfig.wellnessPath) + .nestedRoute(healthConfig.rootPath(), healthConfig.wellnessPath()) .handler(new SmallRyeWellnessHandler()) .displayOnNotFoundPage() .build()); @@ -264,7 +261,7 @@ public void defineHealthRoutes(BuildProducer routes, // Register the startup handler routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .nestedRoute(healthConfig.rootPath, healthConfig.startupPath) + .nestedRoute(healthConfig.rootPath(), healthConfig.startupPath()) .handler(new SmallRyeStartupHandler()) .displayOnNotFoundPage() .build()); @@ -272,19 +269,19 @@ public void defineHealthRoutes(BuildProducer routes, } @BuildStep - public void processSmallRyeHealthConfigValues(SmallRyeHealthConfig healthConfig, + public void processSmallRyeHealthConfigValues(SmallRyeHealthBuildTimeConfig healthConfig, BuildProducer config) { - if (healthConfig.contextPropagation) { + if (healthConfig.contextPropagation()) { config.produce(new RunTimeConfigurationDefaultBuildItem("io.smallrye.health.context.propagation", "true")); } - if (healthConfig.maxGroupRegistriesCount.isPresent()) { + if (healthConfig.maxGroupRegistriesCount().isPresent()) { config.produce(new RunTimeConfigurationDefaultBuildItem("io.smallrye.health.maxGroupRegistriesCount", - String.valueOf(healthConfig.maxGroupRegistriesCount.getAsInt()))); + String.valueOf(healthConfig.maxGroupRegistriesCount().getAsInt()))); } config.produce(new RunTimeConfigurationDefaultBuildItem("io.smallrye.health.delayChecksInitializations", "true")); - if (healthConfig.defaultHealthGroup.isPresent()) { + if (healthConfig.defaultHealthGroup().isPresent()) { config.produce(new RunTimeConfigurationDefaultBuildItem("io.smallrye.health.defaultHealthGroup", - healthConfig.defaultHealthGroup.get())); + healthConfig.defaultHealthGroup().get())); } } @@ -293,15 +290,15 @@ public void includeInOpenAPIEndpoint(BuildProducer livenessPathItemProducer, BuildProducer readinessPathItemProducer, @@ -345,16 +342,16 @@ public void kubernetes(NonApplicationRootPathBuildItem nonApplicationRootPathBui livenessPathItemProducer.produce( new KubernetesHealthLivenessPathBuildItem( - nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath, - healthConfig.livenessPath))); + nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath(), + healthConfig.livenessPath()))); readinessPathItemProducer.produce( new KubernetesHealthReadinessPathBuildItem( - nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath, - healthConfig.readinessPath))); + nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath(), + healthConfig.readinessPath()))); startupPathItemProducer.produce( new KubernetesHealthStartupPathBuildItem( - nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath, - healthConfig.startupPath))); + nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath(), + healthConfig.startupPath()))); } @BuildStep @@ -378,19 +375,19 @@ ShutdownListenerBuildItem shutdownListener() { void registerUiExtension( NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig, - SmallRyeHealthConfig healthConfig, + SmallRyeHealthBuildTimeConfig healthConfig, LaunchModeBuildItem launchModeBuildItem, BuildProducer webJarBuildProducer) { if (shouldInclude(launchModeBuildItem, healthConfig)) { - if ("/".equals(healthConfig.ui.rootPath)) { + if ("/".equals(healthConfig.ui().rootPath())) { throw new ConfigurationException( "quarkus.smallrye-health.root-path-ui was set to \"/\", this is not allowed as it blocks the application from serving anything else.", Set.of("quarkus.smallrye-health.root-path-ui")); } - String healthPath = nonApplicationRootPathBuildItem.resolveManagementPath(healthConfig.rootPath, + String healthPath = nonApplicationRootPathBuildItem.resolveManagementPath(healthConfig.rootPath(), managementInterfaceBuildTimeConfig, launchModeBuildItem, false); webJarBuildProducer.produce( @@ -424,7 +421,7 @@ void registerHealthUiHandler( WebJarResultsBuildItem webJarResultsBuildItem, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, LaunchModeBuildItem launchMode, - SmallRyeHealthConfig healthConfig, + SmallRyeHealthBuildTimeConfig healthConfig, BuildProducer smallryeHealthBuildProducer, ShutdownContextBuildItem shutdownContext) { WebJarResultsBuildItem.WebJarResult result = webJarResultsBuildItem.byArtifactKey(HEALTH_UI_WEBJAR_ARTIFACT_KEY); if (result == null) { @@ -432,7 +429,7 @@ void registerHealthUiHandler( } if (shouldInclude(launchMode, healthConfig)) { - String healthUiPath = nonApplicationRootPathBuildItem.resolvePath(healthConfig.ui.rootPath); + String healthUiPath = nonApplicationRootPathBuildItem.resolvePath(healthConfig.ui().rootPath()); smallryeHealthBuildProducer .produce(new SmallRyeHealthBuildItem(result.getFinalDestination(), healthUiPath)); @@ -441,7 +438,7 @@ void registerHealthUiHandler( routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .route(healthConfig.ui.rootPath) + .route(healthConfig.ui().rootPath()) .displayOnNotFoundPage("Health UI") .routeConfigKey("quarkus.smallrye-health.ui.root-path") .handler(handler) @@ -449,7 +446,7 @@ void registerHealthUiHandler( routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() .management(CONFIG_KEY_HEALTH_MANAGEMENT_ENABLED) - .route(healthConfig.ui.rootPath + "*") + .route(healthConfig.ui().rootPath() + "*") .handler(handler) .build()); } @@ -472,8 +469,8 @@ public String updateApiUrl(String original, String healthPath) { .replace("placeholder=\"/health\"", "placeholder=\"" + healthPath + "\""); } - private static boolean shouldInclude(LaunchModeBuildItem launchMode, SmallRyeHealthConfig healthConfig) { - return launchMode.getLaunchMode().isDevOrTest() || healthConfig.ui.alwaysInclude; + private static boolean shouldInclude(LaunchModeBuildItem launchMode, SmallRyeHealthBuildTimeConfig healthConfig) { + return launchMode.getLaunchMode().isDevOrTest() || healthConfig.ui().alwaysInclude(); } /** diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthUIConfig.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthUIConfig.java index 87390a7221c46..01eeefc101863 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthUIConfig.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthUIConfig.java @@ -1,23 +1,23 @@ package io.quarkus.smallrye.health.deployment; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class SmallRyeHealthUIConfig { +public interface SmallRyeHealthUIConfig { /** * The path where Health UI is available. * The value `/` is not allowed as it blocks the application from serving anything else. * By default, this value will be resolved as a path relative to `${quarkus.http.non-application-root-path}`. */ - @ConfigItem(defaultValue = "health-ui") - String rootPath; + @WithDefault("health-ui") + String rootPath(); /** * Always include the UI. By default, this will only be included in dev and test. * Setting this to true will also include the UI in Prod */ - @ConfigItem(defaultValue = "false") - boolean alwaysInclude; + @WithDefault("false") + boolean alwaysInclude(); } diff --git a/extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeprecatedHealthOpenAPITest.java b/extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeprecatedHealthOpenAPITest.java deleted file mode 100644 index 6c96b912c21d0..0000000000000 --- a/extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeprecatedHealthOpenAPITest.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.quarkus.smallrye.health.test; - -import org.hamcrest.Matchers; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.test.QuarkusUnitTest; -import io.restassured.RestAssured; - -@Deprecated(since = "3.14", forRemoval = true) -class DeprecatedHealthOpenAPITest { - - private static final String OPEN_API_PATH = "/q/openapi"; - - @RegisterExtension - static final QuarkusUnitTest config = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addClasses(BasicHealthCheck.class, OpenApiRoute.class) - .addAsResource(new StringAsset("quarkus.health.openapi.included=true\n" - + "quarkus.smallrye-openapi.store-schema-directory=target"), "application.properties") - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); - - @Test - void testOpenApiPathAccessResource() { - - RestAssured.given().header("Accept", "application/json") - .when().get(OPEN_API_PATH) - .then() - .header("Content-Type", "application/json;charset=UTF-8") - - .body("paths", Matchers.hasKey("/q/health/ready")) - .body("paths", Matchers.hasKey("/q/health/live")) - .body("paths", Matchers.hasKey("/q/health/started")) - .body("paths", Matchers.hasKey("/q/health")) - - .body("components.schemas.HealthResponse.type", Matchers.equalTo("object")) - .body("components.schemas.HealthResponse.properties.status.type", Matchers.equalTo("string")) - .body("components.schemas.HealthResponse.properties.checks.type", Matchers.equalTo("array")) - - .body("components.schemas.HealthCheck.type", Matchers.equalTo("object")) - .body("components.schemas.HealthCheck.properties.status.type", Matchers.equalTo("string")) - .body("components.schemas.HealthCheck.properties.name.type", Matchers.equalTo("string")) - .body("components.schemas.HealthCheck.properties.data.type", Matchers.contains("object", "null")); - } - -} diff --git a/extensions/smallrye-health/runtime/pom.xml b/extensions/smallrye-health/runtime/pom.xml index b556b0e110e10..368fc8ad2a49a 100644 --- a/extensions/smallrye-health/runtime/pom.xml +++ b/extensions/smallrye-health/runtime/pom.xml @@ -66,9 +66,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthBuildFixedConfig.java b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthBuildFixedConfig.java index 32cd94d1b65c8..32939c0ff5fe1 100644 --- a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthBuildFixedConfig.java +++ b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthBuildFixedConfig.java @@ -1,17 +1,19 @@ package io.quarkus.smallrye.health.runtime; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; -@ConfigRoot(name = "smallrye-health", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) -public class SmallRyeHealthBuildFixedConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +@ConfigMapping(prefix = "quarkus.smallrye-health") +public interface SmallRyeHealthBuildFixedConfig { /** * Specify the reported DOWN responses should be aligned with RFC 9457 - Problem Details for HTTP APIs. * * @see RFC 7807 */ - @ConfigItem(defaultValue = "false") - boolean includeProblemDetails; + @WithDefault("false") + boolean includeProblemDetails(); } diff --git a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRecorder.java b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRecorder.java index 65dde1b4c3f7d..83db1c83f531d 100644 --- a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRecorder.java +++ b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRecorder.java @@ -33,7 +33,7 @@ public Handler uiHandler(String healthUiFinalDestination, String List webRootConfigurations, SmallRyeHealthRuntimeConfig runtimeConfig, ShutdownContext shutdownContext) { - if (runtimeConfig.enable) { + if (runtimeConfig.enable()) { WebJarStaticHandler handler = new WebJarStaticHandler(healthUiFinalDestination, healthUiPath, webRootConfigurations); shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(handler)); @@ -46,12 +46,12 @@ public Handler uiHandler(String healthUiFinalDestination, String public void processSmallRyeHealthRuntimeConfiguration(SmallRyeHealthRuntimeConfig runtimeConfig, SmallRyeHealthBuildFixedConfig buildFixedConfig) { SmallRyeHealthReporter reporter = Arc.container().select(SmallRyeHealthReporter.class).get(); - reporter.setAdditionalProperties(runtimeConfig.additionalProperties); + reporter.setAdditionalProperties(runtimeConfig.additionalProperties()); - reporter.setHealthChecksConfigs(runtimeConfig.check.entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().enabled))); + reporter.setHealthChecksConfigs(runtimeConfig.check().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().enabled()))); - SmallRyeHealthHandlerBase.problemDetails = buildFixedConfig.includeProblemDetails; + SmallRyeHealthHandlerBase.problemDetails = buildFixedConfig.includeProblemDetails(); } } diff --git a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRuntimeConfig.java b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRuntimeConfig.java index 43c8adeb0bcc0..4a3a8a35788c2 100644 --- a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRuntimeConfig.java +++ b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRuntimeConfig.java @@ -4,40 +4,42 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "smallrye-health", phase = ConfigPhase.RUN_TIME) -public class SmallRyeHealthRuntimeConfig { +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +@ConfigMapping(prefix = "quarkus.smallrye-health") +public interface SmallRyeHealthRuntimeConfig { /** * If Health UI should be enabled. By default, Health UI is enabled if it is included (see {@code always-include}). */ - @ConfigItem(name = "ui.enable", defaultValue = "true") - boolean enable; + @WithName("ui.enable") + @WithDefault("true") + boolean enable(); /** * Additional top-level properties to be included in the resulting JSON object. */ - @ConfigItem(name = "additional.property") + @WithName("additional.property") @ConfigDocMapKey("property-name") - Map additionalProperties; + Map additionalProperties(); /** * Specifications of checks that can be disabled. */ - @ConfigItem @ConfigDocMapKey("check-name") - Map check; + Map check(); @ConfigGroup - public static final class Enabled { + public interface Enabled { /** * Whether the HealthCheck should be enabled. */ - @ConfigItem - boolean enabled; + boolean enabled(); } } diff --git a/integration-tests/main/src/main/resources/application.properties b/integration-tests/main/src/main/resources/application.properties index 2960f5a13447a..56fcd9f5f38e3 100644 --- a/integration-tests/main/src/main/resources/application.properties +++ b/integration-tests/main/src/main/resources/application.properties @@ -47,7 +47,7 @@ configproperties.instant=2010-10-10T10:10:10Z quarkus.swagger-ui.always-include=true -quarkus.health.openapi.included=true +quarkus.smallrye-health.openapi.included=true quarkus.native.resources.includes = test-resources/**.txt quarkus.native.resources.excludes = **/unwanted.* From 952c33ec07db300f3b2d8eb59395718e011b9018 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 21 Jan 2025 16:10:32 +0100 Subject: [PATCH 3/5] Use @ConfigMapping in SmallRye Metrics Also extract the config to a proper file. --- .../smallrye-metrics/deployment/pom.xml | 3 - .../deployment/JaxRsMetricsProcessor.java | 4 +- .../deployment/SmallRyeMetricsConfig.java | 48 +++++++++++++++ .../SmallRyeMetricsDevUiProcessor.java | 4 +- .../deployment/SmallRyeMetricsProcessor.java | 60 ++++--------------- extensions/smallrye-metrics/runtime/pom.xml | 3 - 6 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsConfig.java diff --git a/extensions/smallrye-metrics/deployment/pom.xml b/extensions/smallrye-metrics/deployment/pom.xml index 71c92edc2d4a5..0d2b2e8cae815 100644 --- a/extensions/smallrye-metrics/deployment/pom.xml +++ b/extensions/smallrye-metrics/deployment/pom.xml @@ -93,9 +93,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/JaxRsMetricsProcessor.java b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/JaxRsMetricsProcessor.java index 7608c1813a7a1..ba0dbd4a0e540 100644 --- a/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/JaxRsMetricsProcessor.java +++ b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/JaxRsMetricsProcessor.java @@ -31,12 +31,12 @@ public class JaxRsMetricsProcessor { static final String RESTEASY_CONFIG_PROPERTY = "quarkus.resteasy.metrics.enabled"; // TODO: we probably want to remove this now... static class RestMetricsEnabled implements BooleanSupplier { - SmallRyeMetricsProcessor.SmallRyeMetricsConfig smConfig; + SmallRyeMetricsConfig smConfig; public boolean getAsBoolean() { boolean resteasyConfigEnabled = ConfigProvider.getConfig().getOptionalValue(RESTEASY_CONFIG_PROPERTY, Boolean.class) .orElse(false); - return smConfig.extensionsEnabled && (smConfig.jaxrsEnabled || resteasyConfigEnabled); + return smConfig.extensionsEnabled() && (smConfig.jaxrsEnabled() || resteasyConfigEnabled); } } diff --git a/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsConfig.java b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsConfig.java new file mode 100644 index 0000000000000..2044df70bda44 --- /dev/null +++ b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsConfig.java @@ -0,0 +1,48 @@ +package io.quarkus.smallrye.metrics.deployment; + +import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; + +@ConfigRoot +@ConfigMapping(prefix = "quarkus.smallrye-metrics") +public interface SmallRyeMetricsConfig { + + /** + * The path to the metrics handler. + * By default, this value will be resolved as a path relative to `${quarkus.http.non-application-root-path}`. + * If the management interface is enabled, the value will be resolved as a path relative to + * `${quarkus.management.root-path}`. + */ + @WithDefault("metrics") + String path(); + + /** + * Whether metrics published by Quarkus extensions should be enabled. + */ + @WithName("extensions.enabled") + @WithDefault("true") + boolean extensionsEnabled(); + + /** + * Apply Micrometer compatibility mode, where instead of regular 'base' and 'vendor' metrics, + * Quarkus exposes the same 'jvm' metrics that Micrometer does. Application metrics are unaffected by this mode. + * The use case is to facilitate migration from Micrometer-based metrics, because original dashboards for JVM metrics + * will continue working without having to rewrite them. + */ + @WithName("micrometer.compatibility") + @WithDefault("false") + boolean micrometerCompatibility(); + + /** + * Whether detailed JAX-RS metrics should be enabled. + *

+ * See MicroProfile + * Metrics: Optional REST metrics. + */ + @WithName("jaxrs.enabled") + @WithDefault("false") + boolean jaxrsEnabled(); +} \ No newline at end of file diff --git a/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsDevUiProcessor.java b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsDevUiProcessor.java index 0eb695a2116a0..b1a625dd485b6 100644 --- a/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsDevUiProcessor.java +++ b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsDevUiProcessor.java @@ -20,12 +20,12 @@ public class SmallRyeMetricsDevUiProcessor { @Record(ExecutionTime.STATIC_INIT) CardPageBuildItem create(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig, - SmallRyeMetricsProcessor.SmallRyeMetricsConfig config, + SmallRyeMetricsConfig config, LaunchModeBuildItem launchModeBuildItem, SmallRyeMetricsRecorder unused) { CardPageBuildItem pageBuildItem = new CardPageBuildItem(); - var path = nonApplicationRootPathBuildItem.resolveManagementPath(config.path, + var path = nonApplicationRootPathBuildItem.resolveManagementPath(config.path(), managementInterfaceBuildTimeConfig, launchModeBuildItem); pageBuildItem.addPage(Page.externalPageBuilder("All Metrics") .icon("font-awesome-solid:chart-line") diff --git a/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsProcessor.java b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsProcessor.java index 5849fdb533ab8..2c245fe642335 100644 --- a/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsProcessor.java +++ b/extensions/smallrye-metrics/deployment/src/main/java/io/quarkus/smallrye/metrics/deployment/SmallRyeMetricsProcessor.java @@ -65,8 +65,6 @@ import io.quarkus.deployment.logging.LogCleanupFilterBuildItem; import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem; import io.quarkus.deployment.metrics.MetricsFactoryConsumerBuildItem; -import io.quarkus.runtime.annotations.ConfigItem; -import io.quarkus.runtime.annotations.ConfigRoot; import io.quarkus.runtime.metrics.MetricsFactory; import io.quarkus.smallrye.metrics.deployment.jandex.JandexBeanInfoAdapter; import io.quarkus.smallrye.metrics.deployment.jandex.JandexMemberInfoAdapter; @@ -91,56 +89,18 @@ public class SmallRyeMetricsProcessor { static final Logger LOGGER = Logger.getLogger("io.quarkus.smallrye.metrics.deployment.SmallRyeMetricsProcessor"); - @ConfigRoot(name = "smallrye-metrics") - static final class SmallRyeMetricsConfig { - - /** - * The path to the metrics handler. - * By default, this value will be resolved as a path relative to `${quarkus.http.non-application-root-path}`. - * If the management interface is enabled, the value will be resolved as a path relative to - * `${quarkus.management.root-path}`. - */ - @ConfigItem(defaultValue = "metrics") - String path; - - /** - * Whether metrics published by Quarkus extensions should be enabled. - */ - @ConfigItem(name = "extensions.enabled", defaultValue = "true") - public boolean extensionsEnabled; - - /** - * Apply Micrometer compatibility mode, where instead of regular 'base' and 'vendor' metrics, - * Quarkus exposes the same 'jvm' metrics that Micrometer does. Application metrics are unaffected by this mode. - * The use case is to facilitate migration from Micrometer-based metrics, because original dashboards for JVM metrics - * will continue working without having to rewrite them. - */ - @ConfigItem(name = "micrometer.compatibility") - public boolean micrometerCompatibility; - - /** - * Whether detailed JAX-RS metrics should be enabled. - *

- * See MicroProfile - * Metrics: Optional REST metrics. - */ - @ConfigItem(name = "jaxrs.enabled", defaultValue = "false") - public boolean jaxrsEnabled; - } - SmallRyeMetricsConfig metrics; @BuildStep MetricsConfigurationBuildItem metricsConfigurationBuildItem() { - return new MetricsConfigurationBuildItem(metrics.path); + return new MetricsConfigurationBuildItem(metrics.path()); } @BuildStep MetricsCapabilityBuildItem metricsCapabilityBuildItem(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) { - if (metrics.extensionsEnabled) { + if (metrics.extensionsEnabled()) { return new MetricsCapabilityBuildItem(MetricsFactory.MP_METRICS::equals, - nonApplicationRootPathBuildItem.resolvePath(metrics.path)); + nonApplicationRootPathBuildItem.resolvePath(metrics.path())); } return null; } @@ -156,19 +116,19 @@ void createRoute(BuildProducer routes, // add metrics endpoint for not found display in dev or test mode if (launchModeBuildItem.getLaunchMode().isDevOrTest()) { - displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(metrics.path)); + displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(metrics.path())); } routes.produce(frameworkRoot.routeBuilder() .management() - .route(metrics.path + (metrics.path.endsWith("/") ? "*" : "/*")) - .handler(recorder.handler(frameworkRoot.resolvePath(metrics.path))) + .route(metrics.path() + (metrics.path().endsWith("/") ? "*" : "/*")) + .handler(recorder.handler(frameworkRoot.resolvePath(metrics.path()))) .blockingRoute() .build()); routes.produce(frameworkRoot.routeBuilder() .management() - .route(metrics.path) + .route(metrics.path()) .routeConfigKey("quarkus.smallrye-metrics.path") - .handler(recorder.handler(frameworkRoot.resolvePath(metrics.path))) + .handler(recorder.handler(frameworkRoot.resolvePath(metrics.path()))) .displayOnNotFoundPage("Metrics") .blockingRoute() .build()); @@ -324,7 +284,7 @@ public void build(BeanContainerBuildItem beanContainerBuildItem, void registerBaseAndVendorMetrics(SmallRyeMetricsRecorder metrics, ShutdownContextBuildItem shutdown, SmallRyeMetricsConfig config) { - if (config.micrometerCompatibility) { + if (config.micrometerCompatibility()) { metrics.registerMicrometerJvmMetrics(shutdown); } else { metrics.registerBaseMetrics(); @@ -551,7 +511,7 @@ public void warnAboutMetricsFromProducers(ValidationPhaseBuildItem validationPha @Record(STATIC_INIT) void extensionMetrics(SmallRyeMetricsRecorder recorder, List metricsFactoryConsumerBuildItems) { - if (metrics.extensionsEnabled) { + if (metrics.extensionsEnabled()) { for (MetricsFactoryConsumerBuildItem item : metricsFactoryConsumerBuildItems) { if (item.executionTime() == STATIC_INIT) { recorder.registerMetrics(item.getConsumer()); diff --git a/extensions/smallrye-metrics/runtime/pom.xml b/extensions/smallrye-metrics/runtime/pom.xml index 6874d663fe883..49d239dbb1916 100644 --- a/extensions/smallrye-metrics/runtime/pom.xml +++ b/extensions/smallrye-metrics/runtime/pom.xml @@ -75,9 +75,6 @@ ${project.version} - - -AlegacyConfigRoot=true - From 1e454df082904b6d099b0846bc8c33c79292c6f5 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 21 Jan 2025 16:44:04 +0100 Subject: [PATCH 4/5] Use @ConfigMapping in SmallRye OpenAPI --- .../deployment/pom.xml | 3 - .../deployment/SmallRyeOpenApiConfig.java | 148 +++++------ .../smallrye-openapi/deployment/pom.xml | 3 - .../deployment/SmallRyeOpenApiProcessor.java | 87 ++++--- .../devui/OpenApiDevUIProcessor.java | 6 +- .../filter/SecurityConfigFilter.java | 32 +-- .../filter/SecurityConfigFilterTest.java | 246 ++++++++++++++++-- extensions/smallrye-openapi/runtime/pom.xml | 3 - .../openapi/runtime/OpenApiRecorder.java | 5 +- .../openapi/runtime/OpenApiRuntimeConfig.java | 15 +- .../deployment/SwaggerUiProcessor.java | 6 +- 11 files changed, 363 insertions(+), 191 deletions(-) diff --git a/extensions/smallrye-openapi-common/deployment/pom.xml b/extensions/smallrye-openapi-common/deployment/pom.xml index 45bdfef55f030..504bf76ac07fa 100644 --- a/extensions/smallrye-openapi-common/deployment/pom.xml +++ b/extensions/smallrye-openapi-common/deployment/pom.xml @@ -34,9 +34,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java b/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java index fec24aeb5a55b..a41556b76fb34 100644 --- a/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java +++ b/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java @@ -1,250 +1,234 @@ package io.quarkus.smallrye.openapi.common.deployment; import java.nio.file.Path; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import io.quarkus.runtime.annotations.ConfigDocMapKey; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "smallrye-openapi") -public final class SmallRyeOpenApiConfig { +@ConfigRoot +@ConfigMapping(prefix = "quarkus.smallrye-openapi") +public interface SmallRyeOpenApiConfig { /** * The path at which to register the OpenAPI Servlet. */ - @ConfigItem(defaultValue = "openapi") - public String path; + @WithDefault("openapi") + String path(); /** * If set, the generated OpenAPI schema documents will be stored here on build. * Both openapi.json and openapi.yaml will be stored here if this is set. */ - @ConfigItem - public Optional storeSchemaDirectory; + Optional storeSchemaDirectory(); /** * The name of the file in case it is being stored. */ - @ConfigItem(defaultValue = "openapi") - public String storeSchemaFileName; + @WithDefault("openapi") + String storeSchemaFileName(); /** * Do not run the filter only at startup, but every time the document is requested (dynamic). */ - @ConfigItem(defaultValue = "false") - public boolean alwaysRunFilter; + @WithDefault("false") + boolean alwaysRunFilter(); /** * Do not include the provided static openapi document (eg. META-INF/openapi.yaml) */ - @ConfigItem(defaultValue = "false") - public boolean ignoreStaticDocument; + @WithDefault("false") + boolean ignoreStaticDocument(); /** * If management interface is turned on the openapi schema document will be published under the management interface. This * allows you to exclude OpenAPI from management by setting the value to false */ - @ConfigItem(name = "management.enabled", defaultValue = "true") - public boolean managementEnabled; + @WithName("management.enabled") + @WithDefault("true") + boolean managementEnabled(); /** * A list of local directories that should be scanned for yaml and/or json files to be included in the static model. * Example: `META-INF/openapi/` */ - @ConfigItem - public Optional> additionalDocsDirectory; + Optional> additionalDocsDirectory(); /** * Add a certain SecurityScheme with config */ - @ConfigItem - public Optional securityScheme; + Optional securityScheme(); /** * Add a Security Scheme name to the generated OpenAPI document */ - @ConfigItem(defaultValue = "SecurityScheme") - public String securitySchemeName; + @WithDefault("SecurityScheme") + String securitySchemeName(); /** * Add a description to the Security Scheme */ - @ConfigItem(defaultValue = "Authentication") - public String securitySchemeDescription; + @WithDefault("Authentication") + String securitySchemeDescription(); /** * Add one or more extensions to the security scheme */ - @ConfigItem @ConfigDocMapKey("extension-name") - public Map securitySchemeExtensions = Collections.emptyMap(); + Map securitySchemeExtensions(); /** * This will automatically add the security requirement to all methods/classes that has a `RolesAllowed` annotation. */ - @ConfigItem(defaultValue = "true") - public boolean autoAddSecurityRequirement; + @WithDefault("true") + boolean autoAddSecurityRequirement(); /** * This will automatically add tags to operations based on the Java class name. */ - @ConfigItem(defaultValue = "true") - public boolean autoAddTags; + @WithDefault("true") + boolean autoAddTags(); /** * This will automatically add a summary to operations based on the Java method name. */ - @ConfigItem(defaultValue = "true") - public boolean autoAddOperationSummary; + @WithDefault("true") + boolean autoAddOperationSummary(); /** * Setting it to `true` will automatically add a default server to the schema if none is provided, * using the current running server host and port. */ - @ConfigItem - public Optional autoAddServer; + + Optional autoAddServer(); /** * This will automatically add security based on the security extension included (if any). */ - @ConfigItem(defaultValue = "true") - public boolean autoAddSecurity; + @WithDefault("true") + boolean autoAddSecurity(); /** * Required when using `apiKey` security. The location of the API key. Valid values are "query", "header" or "cookie". */ - @ConfigItem - public Optional apiKeyParameterIn; + + Optional apiKeyParameterIn(); /** * Required when using `apiKey` security. The name of the header, query or cookie parameter to be used. */ - @ConfigItem - public Optional apiKeyParameterName; + + Optional apiKeyParameterName(); /** * Add a scheme value to the Basic HTTP Security Scheme */ - @ConfigItem(defaultValue = "basic") - public String basicSecuritySchemeValue; + @WithDefault("basic") + String basicSecuritySchemeValue(); /** * Add a scheme value to the JWT Security Scheme */ - @ConfigItem(defaultValue = "bearer") - public String jwtSecuritySchemeValue; + @WithDefault("bearer") + String jwtSecuritySchemeValue(); /** * Add a bearer format the JWT Security Scheme */ - @ConfigItem(defaultValue = "JWT") - public String jwtBearerFormat; + @WithDefault("JWT") + String jwtBearerFormat(); /** * Add a scheme value to the OAuth2 opaque token Security Scheme */ - @ConfigItem(defaultValue = "bearer") - public String oauth2SecuritySchemeValue; + @WithDefault("bearer") + String oauth2SecuritySchemeValue(); /** * Add a scheme value to OAuth2 opaque token Security Scheme */ - @ConfigItem(defaultValue = "Opaque") - public String oauth2BearerFormat; + @WithDefault("Opaque") + String oauth2BearerFormat(); /** * Add a openIdConnectUrl value to the OIDC Security Scheme */ - @ConfigItem - public Optional oidcOpenIdConnectUrl; + Optional oidcOpenIdConnectUrl(); /** * Add a implicit flow refreshUrl value to the OAuth2 Security Scheme */ - @ConfigItem - public Optional oauth2ImplicitRefreshUrl; + Optional oauth2ImplicitRefreshUrl(); /** * Add an implicit flow authorizationUrl value to the OAuth2 Security Scheme */ - @ConfigItem - public Optional oauth2ImplicitAuthorizationUrl; + Optional oauth2ImplicitAuthorizationUrl(); /** * Add an implicit flow tokenUrl value to the OAuth2 Security Scheme */ - @ConfigItem - public Optional oauth2ImplicitTokenUrl; + Optional oauth2ImplicitTokenUrl(); /** * Override the openapi version in the Schema document */ - @ConfigItem - public Optional openApiVersion; + Optional openApiVersion(); /** * Set the title in Info tag in the Schema document */ - @ConfigItem - public Optional infoTitle; + Optional infoTitle(); /** * Set the version in Info tag in the Schema document */ - @ConfigItem - public Optional infoVersion; + Optional infoVersion(); /** * Set the description in Info tag in the Schema document */ - @ConfigItem - public Optional infoDescription; + Optional infoDescription(); /** * Set the terms of the service in Info tag in the Schema document */ - @ConfigItem - public Optional infoTermsOfService; + Optional infoTermsOfService(); /** * Set the contact email in Info tag in the Schema document */ - @ConfigItem - public Optional infoContactEmail; + Optional infoContactEmail(); /** * Set the contact name in Info tag in the Schema document */ - @ConfigItem - public Optional infoContactName; + Optional infoContactName(); /** * Set the contact url in Info tag in the Schema document */ - @ConfigItem - public Optional infoContactUrl; + Optional infoContactUrl(); /** * Set the license name in Info tag in the Schema document */ - @ConfigItem - public Optional infoLicenseName; + Optional infoLicenseName(); /** * Set the license url in Info tag in the Schema document */ - @ConfigItem - public Optional infoLicenseUrl; + Optional infoLicenseUrl(); /** * Set the strategy to automatically create an operation Id */ - @ConfigItem - public Optional operationIdStrategy; + Optional operationIdStrategy(); public enum SecurityScheme { apiKey, @@ -261,8 +245,8 @@ public enum OperationIdStrategy { PACKAGE_CLASS_METHOD } - public Map getValidSecuritySchemeExtentions() { - return securitySchemeExtensions + default Map getValidSecuritySchemeExtensions() { + return securitySchemeExtensions() .entrySet() .stream() .filter(x -> x.getKey().startsWith("x-")) diff --git a/extensions/smallrye-openapi/deployment/pom.xml b/extensions/smallrye-openapi/deployment/pom.xml index d7dba9bd236c3..f1e4a3dbcb244 100644 --- a/extensions/smallrye-openapi/deployment/pom.xml +++ b/extensions/smallrye-openapi/deployment/pom.xml @@ -124,9 +124,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java index 8f46b46da752a..34d0e2e79f82a 100644 --- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java +++ b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java @@ -183,8 +183,8 @@ void configFiles(BuildProducer watchedFiles, LaunchModeBuildItem launchMode, OutputTargetBuildItem outputTargetBuildItem) { // Add any additional directories if configured - if (launchMode.getLaunchMode().isDevOrTest() && openApiConfig.additionalDocsDirectory.isPresent()) { - List additionalStaticDocuments = openApiConfig.additionalDocsDirectory.get(); + if (launchMode.getLaunchMode().isDevOrTest() && openApiConfig.additionalDocsDirectory().isPresent()) { + List additionalStaticDocuments = openApiConfig.additionalDocsDirectory().get(); for (Path path : additionalStaticDocuments) { // Scan all yaml and json files List filesInDir = getResourceFiles(path, outputTargetBuildItem.getOutputDirectory()); @@ -209,7 +209,7 @@ void registerAutoSecurityFilter(BuildProducer syntheticB OpenApiRecorder recorder) { AutoSecurityFilter autoSecurityFilter = null; - if (openApiConfig.autoAddSecurity) { + if (openApiConfig.autoAddSecurity()) { autoSecurityFilter = getAutoSecurityFilter(securityInformationBuildItems, openApiConfig) .filter(securityFilter -> autoSecurityRuntimeEnabled(securityFilter, () -> hasAutoEndpointSecurity(apiFilteredIndexViewBuildItem, openApiConfig))) @@ -287,7 +287,7 @@ void handler(LaunchModeBuildItem launch, } } - routes.produce(RouteBuildItem.newManagementRoute(openApiConfig.path, MANAGEMENT_ENABLED) + routes.produce(RouteBuildItem.newManagementRoute(openApiConfig.path(), MANAGEMENT_ENABLED) .withRouteCustomizer(corsFilter) .withRoutePathConfigKey("quarkus.smallrye-openapi.path") .withRequestHandler(handler) @@ -296,19 +296,19 @@ void handler(LaunchModeBuildItem launch, .build()); routes.produce( - RouteBuildItem.newManagementRoute(openApiConfig.path + ".json", MANAGEMENT_ENABLED) + RouteBuildItem.newManagementRoute(openApiConfig.path() + ".json", MANAGEMENT_ENABLED) .withRouteCustomizer(corsFilter) .withRequestHandler(handler) .build()); routes.produce( - RouteBuildItem.newManagementRoute(openApiConfig.path + ".yaml", MANAGEMENT_ENABLED) + RouteBuildItem.newManagementRoute(openApiConfig.path() + ".yaml", MANAGEMENT_ENABLED) .withRouteCustomizer(corsFilter) .withRequestHandler(handler) .build()); routes.produce( - RouteBuildItem.newManagementRoute(openApiConfig.path + ".yml", MANAGEMENT_ENABLED) + RouteBuildItem.newManagementRoute(openApiConfig.path() + ".yml", MANAGEMENT_ENABLED) .withRouteCustomizer(corsFilter) .withRequestHandler(handler) .build()); @@ -344,7 +344,7 @@ private String getManagementRoot(LaunchModeBuildItem launch, SmallRyeOpenApiConfig openApiConfig, ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig) { String managementRoot = nonApplicationRootPathBuildItem.resolveManagementPath("/", - managementInterfaceBuildTimeConfig, launch, openApiConfig.managementEnabled); + managementInterfaceBuildTimeConfig, launch, openApiConfig.managementEnabled()); return managementRoot.split(managementInterfaceBuildTimeConfig.rootPath)[0]; @@ -395,11 +395,11 @@ void addAutoFilters(BuildProducer addToOpenAPID ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig) { // Add a security scheme from config - if (config.securityScheme.isPresent()) { + if (config.securityScheme().isPresent()) { addToOpenAPIDefinitionProducer .produce(new AddToOpenAPIDefinitionBuildItem( new SecurityConfigFilter(config))); - } else if (config.autoAddSecurity) { + } else if (config.autoAddSecurity()) { getAutoSecurityFilter(securityInformationBuildItems, config) .map(AddToOpenAPIDefinitionBuildItem::new) .ifPresent(addToOpenAPIDefinitionProducer::produce); @@ -454,14 +454,14 @@ private List getUserDefinedFilters(IndexView index, OpenApiFilter.RunSta private boolean isManagement(ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig, SmallRyeOpenApiConfig smallRyeOpenApiConfig, LaunchModeBuildItem launchModeBuildItem) { - return managementInterfaceBuildTimeConfig.enabled && smallRyeOpenApiConfig.managementEnabled + return managementInterfaceBuildTimeConfig.enabled && smallRyeOpenApiConfig.managementEnabled() && launchModeBuildItem.getLaunchMode().equals(LaunchMode.DEVELOPMENT); } private Optional getAutoSecurityFilter(List securityInformationBuildItems, SmallRyeOpenApiConfig config) { - if (config.securityScheme.isPresent()) { + if (config.securityScheme().isPresent()) { return Optional.empty(); } @@ -473,37 +473,37 @@ private Optional getAutoSecurityFilter(List { AutoUrl openIdConnectUrl = new AutoUrl( - config.oidcOpenIdConnectUrl.orElse(null), + config.oidcOpenIdConnectUrl().orElse(null), info.getUrlConfigKey(), "/.well-known/openid-configuration"); return new OpenIDConnectSecurityFilter( - config.securitySchemeName, - config.securitySchemeDescription, - config.getValidSecuritySchemeExtentions(), + config.securitySchemeName(), + config.securitySchemeDescription(), + config.getValidSecuritySchemeExtensions(), openIdConnectUrl); }) .orElse(null); @@ -519,7 +519,7 @@ private boolean hasAutoEndpointSecurity( OpenApiFilteredIndexViewBuildItem indexViewBuildItem, SmallRyeOpenApiConfig config) { - if (config.autoAddSecurityRequirement) { + if (config.autoAddSecurityRequirement()) { Map> rolesAllowedMethods = Collections.emptyMap(); List authenticatedMethods = Collections.emptyList(); @@ -544,11 +544,11 @@ private OASFilter getOperationFilter(OpenApiFilteredIndexViewBuildItem indexView Map> rolesAllowedMethods = Collections.emptyMap(); List authenticatedMethods = Collections.emptyList(); - if (config.autoAddTags || config.autoAddOperationSummary) { + if (config.autoAddTags() || config.autoAddOperationSummary()) { classNamesMethods = getClassNamesMethodReferences(indexViewBuildItem); } - if (config.autoAddSecurityRequirement) { + if (config.autoAddSecurityRequirement()) { rolesAllowedMethods = getRolesAllowedMethodReferences(indexViewBuildItem); for (String methodRef : getPermissionsAllowedMethodReferences(indexViewBuildItem)) { @@ -559,15 +559,16 @@ private OASFilter getOperationFilter(OpenApiFilteredIndexViewBuildItem indexView } if (!classNamesMethods.isEmpty() || !rolesAllowedMethods.isEmpty() || !authenticatedMethods.isEmpty()) { - return new OperationFilter(classNamesMethods, rolesAllowedMethods, authenticatedMethods, config.securitySchemeName, - config.autoAddTags, config.autoAddOperationSummary, isOpenApi_3_1_0_OrGreater(config)); + return new OperationFilter(classNamesMethods, rolesAllowedMethods, authenticatedMethods, + config.securitySchemeName(), + config.autoAddTags(), config.autoAddOperationSummary(), isOpenApi_3_1_0_OrGreater(config)); } return null; } private OASFilter getAutoServerFilter(SmallRyeOpenApiConfig config, boolean defaultFlag, String description) { - if (config.autoAddServer.orElse(defaultFlag)) { + if (config.autoAddServer().orElse(defaultFlag)) { Config c = ConfigProvider.getConfig(); String scheme = "http"; @@ -887,7 +888,7 @@ public void build(BuildProducer feature, .withApplicationClassLoader(loader) .withScannerClassLoader(loader) .enableModelReader(true) - .enableStandardStaticFiles(Boolean.FALSE.equals(smallRyeOpenApiConfig.ignoreStaticDocument)) + .enableStandardStaticFiles(Boolean.FALSE.equals(smallRyeOpenApiConfig.ignoreStaticDocument())) .withResourceLocator(path -> { URL locator = loader.getResource(path); if (locator == null || shouldIgnore(urlIgnorePatterns, locator.toString())) { @@ -950,11 +951,11 @@ Map.> entry("YAML", openAPI::toYAML)) finalOpenAPI = storedOpenAPI; - smallRyeOpenApiConfig.storeSchemaDirectory.ifPresent(storageDir -> { + smallRyeOpenApiConfig.storeSchemaDirectory().ifPresent(storageDir -> { try { - storeGeneratedSchema(storageDir, smallRyeOpenApiConfig.storeSchemaFileName, outputTargetBuildItem, + storeGeneratedSchema(storageDir, smallRyeOpenApiConfig.storeSchemaFileName(), outputTargetBuildItem, finalOpenAPI.toJSON(), "json"); - storeGeneratedSchema(storageDir, smallRyeOpenApiConfig.storeSchemaFileName, outputTargetBuildItem, + storeGeneratedSchema(storageDir, smallRyeOpenApiConfig.storeSchemaFileName(), outputTargetBuildItem, finalOpenAPI.toYAML(), "yaml"); } catch (IOException e) { throw new UncheckedIOException(e); @@ -1051,7 +1052,7 @@ private boolean isUsingVertxRoute(IndexView index) { private InputStream loadAdditionalDocsModel(SmallRyeOpenApiConfig openApiConfig, List ignorePatterns, Path target) { - if (openApiConfig.ignoreStaticDocument) { + if (openApiConfig.ignoreStaticDocument()) { return null; } @@ -1062,7 +1063,7 @@ private InputStream loadAdditionalDocsModel(SmallRyeOpenApiConfig openApiConfig, .enableAnnotationScan(false) .enableStandardFilter(false); - return openApiConfig.additionalDocsDirectory + return openApiConfig.additionalDocsDirectory() .map(Collection::stream) .orElseGet(Stream::empty) .map(path -> getResourceFiles(path, target)) @@ -1197,7 +1198,7 @@ private List getResourceFiles(Path resourcePath, Path target) { } private static boolean isOpenApi_3_1_0_OrGreater(SmallRyeOpenApiConfig config) { - final String openApiVersion = config.openApiVersion.orElse(null); + final String openApiVersion = config.openApiVersion().orElse(null); return openApiVersion == null || (!openApiVersion.startsWith("2") && !openApiVersion.startsWith("3.0")); } } diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/devui/OpenApiDevUIProcessor.java b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/devui/OpenApiDevUIProcessor.java index 5e690fc1b1e9c..20b5c8154cbbe 100644 --- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/devui/OpenApiDevUIProcessor.java +++ b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/devui/OpenApiDevUIProcessor.java @@ -20,10 +20,10 @@ public CardPageBuildItem pages(NonApplicationRootPathBuildItem nonApplicationRoo SmallRyeOpenApiConfig openApiConfig) { String uiPath = nonApplicationRootPathBuildItem.resolveManagementPath(swaggerUiConfig.path, - managementInterfaceBuildTimeConfig, launchModeBuildItem, openApiConfig.managementEnabled); + managementInterfaceBuildTimeConfig, launchModeBuildItem, openApiConfig.managementEnabled()); - String schemaPath = nonApplicationRootPathBuildItem.resolveManagementPath(openApiConfig.path, - managementInterfaceBuildTimeConfig, launchModeBuildItem, openApiConfig.managementEnabled); + String schemaPath = nonApplicationRootPathBuildItem.resolveManagementPath(openApiConfig.path(), + managementInterfaceBuildTimeConfig, launchModeBuildItem, openApiConfig.managementEnabled()); CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilter.java b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilter.java index 2dec832d218b7..ac235b4a0abcd 100644 --- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilter.java +++ b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilter.java @@ -33,7 +33,7 @@ public SecurityConfigFilter(SmallRyeOpenApiConfig config) { * Add a security scheme from config */ public void filterOpenAPI(OpenAPI openAPI) { - if (config.securityScheme.isEmpty()) { + if (config.securityScheme().isEmpty()) { return; } @@ -48,10 +48,10 @@ public void filterOpenAPI(OpenAPI openAPI) { Optional.ofNullable(openAPI.getComponents().getSecuritySchemes()) .ifPresent(securitySchemes::putAll); - SmallRyeOpenApiConfig.SecurityScheme securitySchemeOption = config.securityScheme.get(); + SmallRyeOpenApiConfig.SecurityScheme securitySchemeOption = config.securityScheme().get(); SecurityScheme securityScheme = OASFactory.createSecurityScheme(); - securityScheme.setDescription(config.securitySchemeDescription); - config.getValidSecuritySchemeExtentions().forEach(securityScheme::addExtension); + securityScheme.setDescription(config.securitySchemeDescription()); + config.getValidSecuritySchemeExtensions().forEach(securityScheme::addExtension); switch (securitySchemeOption) { case apiKey: @@ -59,36 +59,36 @@ public void filterOpenAPI(OpenAPI openAPI) { break; case basic: securityScheme.setType(SecurityScheme.Type.HTTP); - securityScheme.setScheme(config.basicSecuritySchemeValue); + securityScheme.setScheme(config.basicSecuritySchemeValue()); break; case jwt: securityScheme.setType(SecurityScheme.Type.HTTP); - securityScheme.setScheme(config.jwtSecuritySchemeValue); - securityScheme.setBearerFormat(config.jwtBearerFormat); + securityScheme.setScheme(config.jwtSecuritySchemeValue()); + securityScheme.setBearerFormat(config.jwtBearerFormat()); break; case oauth2: securityScheme.setType(SecurityScheme.Type.HTTP); - securityScheme.setScheme(config.oauth2SecuritySchemeValue); - securityScheme.setBearerFormat(config.oauth2BearerFormat); + securityScheme.setScheme(config.oauth2SecuritySchemeValue()); + securityScheme.setBearerFormat(config.oauth2BearerFormat()); break; case oidc: securityScheme.setType(SecurityScheme.Type.OPENIDCONNECT); - securityScheme.setOpenIdConnectUrl(config.oidcOpenIdConnectUrl.orElse(null)); + securityScheme.setOpenIdConnectUrl(config.oidcOpenIdConnectUrl().orElse(null)); break; case oauth2Implicit: securityScheme.setType(SecurityScheme.Type.OAUTH2); OAuthFlows oAuthFlows = OASFactory.createOAuthFlows(); OAuthFlow oAuthFlow = OASFactory.createOAuthFlow(); - config.oauth2ImplicitAuthorizationUrl.ifPresent(oAuthFlow::authorizationUrl); - config.oauth2ImplicitRefreshUrl.ifPresent(oAuthFlow::refreshUrl); - config.oauth2ImplicitTokenUrl.ifPresent(oAuthFlow::tokenUrl); + config.oauth2ImplicitAuthorizationUrl().ifPresent(oAuthFlow::authorizationUrl); + config.oauth2ImplicitRefreshUrl().ifPresent(oAuthFlow::refreshUrl); + config.oauth2ImplicitTokenUrl().ifPresent(oAuthFlow::tokenUrl); oAuthFlows.setImplicit(oAuthFlow); securityScheme.setType(SecurityScheme.Type.OAUTH2); securityScheme.setFlows(oAuthFlows); break; } - securitySchemes.put(config.securitySchemeName, securityScheme); + securitySchemes.put(config.securitySchemeName(), securityScheme); openAPI.getComponents().setSecuritySchemes(securitySchemes); if (securitySchemes.size() > 1) { @@ -100,11 +100,11 @@ public void filterOpenAPI(OpenAPI openAPI) { void configureApiKeySecurityScheme(SecurityScheme securityScheme) { securityScheme.setType(SecurityScheme.Type.APIKEY); - securityScheme.setName(config.apiKeyParameterName + securityScheme.setName(config.apiKeyParameterName() .orElseThrow( () -> new ConfigurationException("Parameter `name` is required for `apiKey` OpenAPI security scheme"))); - securityScheme.setIn(config.apiKeyParameterIn + securityScheme.setIn(config.apiKeyParameterIn() .map(in -> Stream.of(SecurityScheme.In.values()) .filter(v -> v.toString().equals(in)) .findFirst() diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilterTest.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilterTest.java index 32f90e47d07b9..807399e5982e0 100644 --- a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilterTest.java +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilterTest.java @@ -3,11 +3,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; import java.util.Optional; import org.eclipse.microprofile.openapi.OASFactory; import org.eclipse.microprofile.openapi.models.security.SecurityScheme; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import io.quarkus.runtime.configuration.ConfigurationException; @@ -15,50 +17,244 @@ class SecurityConfigFilterTest { - SmallRyeOpenApiConfig config; - SecurityConfigFilter target; - - @BeforeEach - void setup() { - config = new SmallRyeOpenApiConfig(); - target = new SecurityConfigFilter(config); - } - @Test void testConfigureApiKeySecuritySchemeMissingName() { SecurityScheme securityScheme = OASFactory.createSecurityScheme(); - config.securityScheme = Optional.of(SmallRyeOpenApiConfig.SecurityScheme.apiKey); - config.apiKeyParameterName = Optional.empty(); - assertThrows(ConfigurationException.class, () -> target.configureApiKeySecurityScheme(securityScheme)); + SmallRyeOpenApiConfig config = new DummySmallRyeOpenApiConfig(SmallRyeOpenApiConfig.SecurityScheme.apiKey, null, null); + assertThrows(ConfigurationException.class, + () -> new SecurityConfigFilter(config).configureApiKeySecurityScheme(securityScheme)); } @Test void testConfigureApiKeySecuritySchemeMissingParamIn() { SecurityScheme securityScheme = OASFactory.createSecurityScheme(); - config.securityScheme = Optional.of(SmallRyeOpenApiConfig.SecurityScheme.apiKey); - config.apiKeyParameterName = Optional.of("KeyParamName"); - config.apiKeyParameterIn = Optional.empty(); - assertThrows(ConfigurationException.class, () -> target.configureApiKeySecurityScheme(securityScheme)); + SmallRyeOpenApiConfig config = new DummySmallRyeOpenApiConfig(SmallRyeOpenApiConfig.SecurityScheme.apiKey, + "KeyParamName", null); + assertThrows(ConfigurationException.class, + () -> new SecurityConfigFilter(config).configureApiKeySecurityScheme(securityScheme)); } @Test void testConfigureApiKeySecuritySchemeInvalidParamIn() { SecurityScheme securityScheme = OASFactory.createSecurityScheme(); - config.securityScheme = Optional.of(SmallRyeOpenApiConfig.SecurityScheme.apiKey); - config.apiKeyParameterName = Optional.of("KeyParamName"); - config.apiKeyParameterIn = Optional.of("path"); - assertThrows(ConfigurationException.class, () -> target.configureApiKeySecurityScheme(securityScheme)); + SmallRyeOpenApiConfig config = new DummySmallRyeOpenApiConfig(SmallRyeOpenApiConfig.SecurityScheme.apiKey, + "KeyParamName", "path"); + assertThrows(ConfigurationException.class, + () -> new SecurityConfigFilter(config).configureApiKeySecurityScheme(securityScheme)); } @Test void testConfigureApiKeySecuritySchemeSuccess() { SecurityScheme securityScheme = OASFactory.createSecurityScheme(); - config.securityScheme = Optional.of(SmallRyeOpenApiConfig.SecurityScheme.apiKey); - config.apiKeyParameterName = Optional.of("KeyParamName"); - config.apiKeyParameterIn = Optional.of("header"); - target.configureApiKeySecurityScheme(securityScheme); + SmallRyeOpenApiConfig config = new DummySmallRyeOpenApiConfig(SmallRyeOpenApiConfig.SecurityScheme.apiKey, + "KeyParamName", "header"); + new SecurityConfigFilter(config).configureApiKeySecurityScheme(securityScheme); assertEquals("KeyParamName", securityScheme.getName()); assertEquals(SecurityScheme.In.HEADER, securityScheme.getIn()); } + private class DummySmallRyeOpenApiConfig implements SmallRyeOpenApiConfig { + + private SecurityScheme securityScheme; + private String apiKeyParameterName; + private String apiKeyParameterIn; + + DummySmallRyeOpenApiConfig(SecurityScheme securityScheme, + String apiKeyParameterName, + String apiKeyParameterIn) { + this.securityScheme = securityScheme; + this.apiKeyParameterName = apiKeyParameterName; + this.apiKeyParameterIn = apiKeyParameterIn; + } + + @Override + public String path() { + return null; + } + + @Override + public Optional storeSchemaDirectory() { + return Optional.empty(); + } + + @Override + public String storeSchemaFileName() { + return null; + } + + @Override + public boolean alwaysRunFilter() { + return false; + } + + @Override + public boolean ignoreStaticDocument() { + return false; + } + + @Override + public boolean managementEnabled() { + return false; + } + + @Override + public Optional> additionalDocsDirectory() { + return Optional.empty(); + } + + @Override + public Optional securityScheme() { + return Optional.ofNullable(securityScheme); + } + + @Override + public String securitySchemeName() { + return null; + } + + @Override + public String securitySchemeDescription() { + return null; + } + + @Override + public boolean autoAddSecurityRequirement() { + return false; + } + + @Override + public boolean autoAddTags() { + return false; + } + + @Override + public boolean autoAddOperationSummary() { + return false; + } + + @Override + public Optional autoAddServer() { + return Optional.empty(); + } + + @Override + public boolean autoAddSecurity() { + return false; + } + + @Override + public Optional apiKeyParameterIn() { + return Optional.ofNullable(apiKeyParameterIn); + } + + @Override + public Optional apiKeyParameterName() { + return Optional.ofNullable(apiKeyParameterName); + } + + @Override + public String basicSecuritySchemeValue() { + return null; + } + + @Override + public String jwtSecuritySchemeValue() { + return null; + } + + @Override + public String jwtBearerFormat() { + return null; + } + + @Override + public String oauth2SecuritySchemeValue() { + return null; + } + + @Override + public String oauth2BearerFormat() { + return null; + } + + @Override + public Optional oidcOpenIdConnectUrl() { + return Optional.empty(); + } + + @Override + public Optional oauth2ImplicitRefreshUrl() { + return Optional.empty(); + } + + @Override + public Optional oauth2ImplicitAuthorizationUrl() { + return Optional.empty(); + } + + @Override + public Optional oauth2ImplicitTokenUrl() { + return Optional.empty(); + } + + @Override + public Optional openApiVersion() { + return Optional.empty(); + } + + @Override + public Optional infoTitle() { + return Optional.empty(); + } + + @Override + public Optional infoVersion() { + return Optional.empty(); + } + + @Override + public Optional infoDescription() { + return Optional.empty(); + } + + @Override + public Optional infoTermsOfService() { + return Optional.empty(); + } + + @Override + public Optional infoContactEmail() { + return Optional.empty(); + } + + @Override + public Optional infoContactName() { + return Optional.empty(); + } + + @Override + public Optional infoContactUrl() { + return Optional.empty(); + } + + @Override + public Optional infoLicenseName() { + return Optional.empty(); + } + + @Override + public Optional infoLicenseUrl() { + return Optional.empty(); + } + + @Override + public Optional operationIdStrategy() { + return Optional.empty(); + } + + @Override + public Map securitySchemeExtensions() { + return Map.of(); + } + } } diff --git a/extensions/smallrye-openapi/runtime/pom.xml b/extensions/smallrye-openapi/runtime/pom.xml index 1e8ec20b31c26..73016d8481066 100644 --- a/extensions/smallrye-openapi/runtime/pom.xml +++ b/extensions/smallrye-openapi/runtime/pom.xml @@ -60,9 +60,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRecorder.java b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRecorder.java index 49b3563ff4e7f..c5ed3d2bb035b 100644 --- a/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRecorder.java +++ b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRecorder.java @@ -5,7 +5,6 @@ import java.util.function.Supplier; import org.eclipse.microprofile.openapi.OASFilter; -import org.jboss.logging.Logger; import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.ShutdownContext; @@ -18,7 +17,7 @@ @Recorder public class OpenApiRecorder { - private static final Logger log = Logger.getLogger(OpenApiRecorder.class); + final RuntimeValue configuration; public OpenApiRecorder(RuntimeValue configuration) { @@ -38,7 +37,7 @@ public void accept(Route route) { } public Handler handler(OpenApiRuntimeConfig runtimeConfig) { - if (runtimeConfig.enable) { + if (runtimeConfig.enable()) { return new OpenApiHandler(); } else { return new OpenApiNotFoundHandler(); diff --git a/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRuntimeConfig.java b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRuntimeConfig.java index c41080b2541a9..119f0bd707214 100644 --- a/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRuntimeConfig.java +++ b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiRuntimeConfig.java @@ -3,22 +3,23 @@ import java.util.Optional; import java.util.Set; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; -@ConfigRoot(name = "smallrye-openapi", phase = ConfigPhase.RUN_TIME) -public class OpenApiRuntimeConfig { +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +@ConfigMapping(prefix = "quarkus.smallrye-openapi") +public interface OpenApiRuntimeConfig { /** * Enable the openapi endpoint. By default it's enabled. */ - @ConfigItem(defaultValue = "true") - public boolean enable; + @WithDefault("true") + boolean enable(); /** * Specify the list of global servers that provide connectivity information */ - @ConfigItem - public Optional> servers; + Optional> servers(); } diff --git a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java index bc01164f7127e..e78a3a3c8bb38 100644 --- a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java +++ b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java @@ -100,10 +100,10 @@ public void getSwaggerUiFinalDestination( Set.of("quarkus.swagger-ui.path")); } - if (openapi.path.equalsIgnoreCase(swaggerUiConfig.path)) { + if (openapi.path().equalsIgnoreCase(swaggerUiConfig.path)) { throw new ConfigurationException( "quarkus.smallrye-openapi.path and quarkus.swagger-ui.path was set to the same value, this is not allowed as the paths needs to be unique [" - + openapi.path + "].", + + openapi.path() + "].", Set.of("quarkus.smallrye-openapi.path", "quarkus.swagger-ui.path")); } @@ -120,7 +120,7 @@ public void getSwaggerUiFinalDestination( } } - String openApiPath = nonApplicationRootPathBuildItem.resolvePath(openapi.path); + String openApiPath = nonApplicationRootPathBuildItem.resolvePath(openapi.path()); String swaggerUiPath = nonApplicationRootPathBuildItem.resolvePath(swaggerUiConfig.path); ThemeHref theme = swaggerUiConfig.theme.orElse(ThemeHref.feeling_blue); From b329543309b5c46f175d29dafa7423bb43dd5625 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 21 Jan 2025 17:04:28 +0100 Subject: [PATCH 5/5] Use @ConfigMapping in SmallRye Reactive Messaging extensions --- .../deployment/pom.xml | 3 - .../amqp/deployment/AmqpBuildTimeConfig.java | 10 +- .../AmqpDevServicesBuildTimeConfig.java | 29 +++-- .../deployment/AmqpDevServicesProcessor.java | 16 +-- .../runtime/pom.xml | 3 - .../deployment/pom.xml | 3 - ...ReactiveMessagingKafkaBuildTimeConfig.java | 28 +++-- ...allRyeReactiveMessagingKafkaProcessor.java | 8 +- .../runtime/pom.xml | 3 - .../kafka/ReactiveMessagingKafkaConfig.java | 18 ---- .../deployment/pom.xml | 3 - .../mqtt/deployment/MqttBuildTimeConfig.java | 10 +- .../MqttDevServicesBuildTimeConfig.java | 25 ++--- .../deployment/MqttDevServicesProcessor.java | 14 +-- .../runtime/pom.xml | 3 - .../deployment/pom.xml | 3 - .../deployment/PulsarBuildTimeConfig.java | 10 +- .../PulsarDevServicesBuildTimeConfig.java | 25 ++--- .../PulsarDevServicesProcessor.java | 14 +-- .../PulsarSchemaDiscoveryProcessor.java | 5 +- ...eactiveMessagingPulsarBuildTimeConfig.java | 19 ++-- .../runtime/pom.xml | 3 - .../deployment/pom.xml | 3 - .../deployment/RabbitMQBuildTimeConfig.java | 16 ++- .../RabbitMQDevServicesBuildTimeConfig.java | 101 ++++++++---------- .../RabbitMQDevServicesProcessor.java | 66 ++++++------ ...RyeReactiveMessagingRabbitMQProcessor.java | 6 +- .../runtime/pom.xml | 3 - .../deployment/pom.xml | 3 - .../ReactiveMessagingBuildTimeConfig.java | 19 ++-- .../SmallRyeReactiveMessagingProcessor.java | 14 +-- .../deployment/WiringProcessor.java | 4 +- .../runtime/pom.xml | 3 - .../ReactiveMessagingConfiguration.java | 23 ++-- 34 files changed, 233 insertions(+), 283 deletions(-) delete mode 100644 extensions/smallrye-reactive-messaging-kafka/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/ReactiveMessagingKafkaConfig.java diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml b/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml index efdf9bc89b055..752c6b84c4cf4 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml @@ -112,9 +112,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpBuildTimeConfig.java index 8db1e0ef04b32..2f74cf0e6b481 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpBuildTimeConfig.java @@ -1,19 +1,19 @@ package io.quarkus.smallrye.reactivemessaging.amqp.deployment; import io.quarkus.runtime.annotations.ConfigDocSection; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; -@ConfigRoot(name = "amqp", phase = ConfigPhase.BUILD_TIME) -public class AmqpBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +@ConfigMapping(prefix = "quarkus.amqp") +public interface AmqpBuildTimeConfig { /** * Dev Services. *

* Dev Services allows Quarkus to automatically start an AMQP broker in dev and test mode. */ - @ConfigItem @ConfigDocSection(generated = true) - public AmqpDevServicesBuildTimeConfig devservices; + AmqpDevServicesBuildTimeConfig devservices(); } diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesBuildTimeConfig.java index 26997157ad810..0b89620630f8f 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesBuildTimeConfig.java @@ -5,10 +5,10 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class AmqpDevServicesBuildTimeConfig { +public interface AmqpDevServicesBuildTimeConfig { /** * If Dev Services for AMQP has been explicitly enabled or disabled. Dev Services are generally enabled @@ -16,16 +16,14 @@ public class AmqpDevServicesBuildTimeConfig { * {@code amqp-host} or {@code amqp-port} are set or if all the Reactive Messaging AMQP channel are configured with * {@code host} or {@code port}. */ - @ConfigItem - public Optional enabled = Optional.empty(); + Optional enabled(); /** * Optional fixed port the dev service will listen to. *

* If not defined, the port will be chosen randomly. */ - @ConfigItem - public Optional port; + Optional port(); /** * The image to use. @@ -36,16 +34,16 @@ public class AmqpDevServicesBuildTimeConfig { * page * to find the available versions. */ - @ConfigItem(defaultValue = "quay.io/artemiscloud/activemq-artemis-broker:1.0.25") - public String imageName; + @WithDefault("quay.io/artemiscloud/activemq-artemis-broker:1.0.25") + String imageName(); /** * The value of the {@code AMQ_EXTRA_ARGS} environment variable to pass to the container. * For ActiveMQ Artemis Broker <= 1.0.21, set this property to * {@code --no-autotune --mapped --no-fsync --relax-jolokia --http-host 0.0.0.0} */ - @ConfigItem(defaultValue = "--no-autotune --mapped --no-fsync --relax-jolokia") - public String extraArgs; + @WithDefault("--no-autotune --mapped --no-fsync --relax-jolokia") + String extraArgs(); /** * Indicates if the AMQP broker managed by Quarkus Dev Services is shared. @@ -58,8 +56,8 @@ public class AmqpDevServicesBuildTimeConfig { *

* Container sharing is only used in dev mode. */ - @ConfigItem(defaultValue = "true") - public boolean shared; + @WithDefault("true") + boolean shared(); /** * The value of the {@code quarkus-dev-service-aqmp} label attached to the started container. @@ -71,14 +69,13 @@ public class AmqpDevServicesBuildTimeConfig { *

* This property is used when you need multiple shared AMQP brokers. */ - @ConfigItem(defaultValue = "amqp") - public String serviceName; + @WithDefault("amqp") + String serviceName(); /** * Environment variables that are passed to the container. */ - @ConfigItem @ConfigDocMapKey("environment-variable-name") - public Map containerEnv; + Map containerEnv(); } diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java index c5580024afb8a..4069406358a03 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java @@ -236,7 +236,7 @@ private boolean hasAmqpChannelWithoutHostAndPort() { } private AmqpDevServiceCfg getConfiguration(AmqpBuildTimeConfig cfg) { - AmqpDevServicesBuildTimeConfig devServicesConfig = cfg.devservices; + AmqpDevServicesBuildTimeConfig devServicesConfig = cfg.devservices(); return new AmqpDevServiceCfg(devServicesConfig); } @@ -250,13 +250,13 @@ private static final class AmqpDevServiceCfg { private final Map containerEnv; public AmqpDevServiceCfg(AmqpDevServicesBuildTimeConfig devServicesConfig) { - this.devServicesEnabled = devServicesConfig.enabled.orElse(true); - this.imageName = devServicesConfig.imageName; - this.fixedExposedPort = devServicesConfig.port.orElse(0); - this.extra = devServicesConfig.extraArgs; - this.shared = devServicesConfig.shared; - this.serviceName = devServicesConfig.serviceName; - this.containerEnv = devServicesConfig.containerEnv; + this.devServicesEnabled = devServicesConfig.enabled().orElse(true); + this.imageName = devServicesConfig.imageName(); + this.fixedExposedPort = devServicesConfig.port().orElse(0); + this.extra = devServicesConfig.extraArgs(); + this.shared = devServicesConfig.shared(); + this.serviceName = devServicesConfig.serviceName(); + this.containerEnv = devServicesConfig.containerEnv(); } @Override diff --git a/extensions/smallrye-reactive-messaging-amqp/runtime/pom.xml b/extensions/smallrye-reactive-messaging-amqp/runtime/pom.xml index d49053f4cf25d..2474d91098e1a 100644 --- a/extensions/smallrye-reactive-messaging-amqp/runtime/pom.xml +++ b/extensions/smallrye-reactive-messaging-amqp/runtime/pom.xml @@ -77,9 +77,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-kafka/deployment/pom.xml b/extensions/smallrye-reactive-messaging-kafka/deployment/pom.xml index 8ee27f89e36e3..0cdeb34d17a97 100644 --- a/extensions/smallrye-reactive-messaging-kafka/deployment/pom.xml +++ b/extensions/smallrye-reactive-messaging-kafka/deployment/pom.xml @@ -119,9 +119,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/ReactiveMessagingKafkaBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/ReactiveMessagingKafkaBuildTimeConfig.java index 512684e84111b..b3e8761a98795 100644 --- a/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/ReactiveMessagingKafkaBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/ReactiveMessagingKafkaBuildTimeConfig.java @@ -1,21 +1,35 @@ package io.quarkus.smallrye.reactivemessaging.kafka.deployment; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "messaging.kafka", phase = ConfigPhase.BUILD_TIME) -public class ReactiveMessagingKafkaBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +@ConfigMapping(prefix = "quarkus.messaging.kafka") +public interface ReactiveMessagingKafkaBuildTimeConfig { /** * Whether or not Kafka serializer/deserializer auto-detection is enabled. */ - @ConfigItem(name = "serializer-autodetection.enabled", defaultValue = "true") - public boolean serializerAutodetectionEnabled; + @WithName("serializer-autodetection.enabled") + @WithDefault("true") + boolean serializerAutodetectionEnabled(); /** * Whether Kafka serializer/deserializer generation is enabled. * When no serializer/deserializer are found and not set, Quarkus generates a Jackson-based serde. */ - @ConfigItem(name = "serializer-generation.enabled", defaultValue = "true") - public boolean serializerGenerationEnabled; + @WithName("serializer-generation.enabled") + @WithDefault("true") + boolean serializerGenerationEnabled(); + + /** + * Enables the graceful shutdown in dev and test modes. + * The graceful shutdown waits until the inflight records have been processed and the offset committed to Kafka. + * While this setting is highly recommended in production, in dev and test modes, it's disabled by default. + * This setting allows to re-enable it. + */ + @WithDefault("false") + boolean enableGracefulShutdownInDevAndTestMode(); } diff --git a/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/SmallRyeReactiveMessagingKafkaProcessor.java b/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/SmallRyeReactiveMessagingKafkaProcessor.java index 03c4133fe4edb..592ecea7d81c8 100644 --- a/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/SmallRyeReactiveMessagingKafkaProcessor.java +++ b/extensions/smallrye-reactive-messaging-kafka/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/deployment/SmallRyeReactiveMessagingKafkaProcessor.java @@ -46,7 +46,6 @@ import io.quarkus.smallrye.reactivemessaging.kafka.HibernateOrmStateStore; import io.quarkus.smallrye.reactivemessaging.kafka.HibernateReactiveStateStore; import io.quarkus.smallrye.reactivemessaging.kafka.KafkaConfigCustomizer; -import io.quarkus.smallrye.reactivemessaging.kafka.ReactiveMessagingKafkaConfig; import io.quarkus.smallrye.reactivemessaging.kafka.RedisStateStore; import io.smallrye.mutiny.tuples.Functions.TriConsumer; import io.smallrye.reactive.messaging.kafka.KafkaConnector; @@ -181,7 +180,6 @@ public void additionalJpaModel(BuildProducer additi public void defaultChannelConfiguration( LaunchModeBuildItem launchMode, ReactiveMessagingKafkaBuildTimeConfig buildTimeConfig, - ReactiveMessagingKafkaConfig runtimeConfig, CombinedIndexBuildItem combinedIndex, List channelsManagedByConnectors, BuildProducer defaultConfigProducer, @@ -189,13 +187,13 @@ public void defaultChannelConfiguration( BuildProducer reflection) { DefaultSerdeDiscoveryState discoveryState = new DefaultSerdeDiscoveryState(combinedIndex.getIndex()); - if (buildTimeConfig.serializerAutodetectionEnabled) { + if (buildTimeConfig.serializerAutodetectionEnabled()) { discoverDefaultSerdeConfig(discoveryState, channelsManagedByConnectors, defaultConfigProducer, - buildTimeConfig.serializerGenerationEnabled ? generatedClass : null, reflection); + buildTimeConfig.serializerGenerationEnabled() ? generatedClass : null, reflection); } if (launchMode.getLaunchMode().isDevOrTest()) { - if (!runtimeConfig.enableGracefulShutdownInDevAndTestMode) { + if (!buildTimeConfig.enableGracefulShutdownInDevAndTestMode()) { List incomings = discoveryState.findRepeatableAnnotationsOnMethods(DotNames.INCOMING); List outgoings = discoveryState.findRepeatableAnnotationsOnMethods(DotNames.OUTGOING); List channels = discoveryState.findAnnotationsOnInjectionPoints(DotNames.CHANNEL); diff --git a/extensions/smallrye-reactive-messaging-kafka/runtime/pom.xml b/extensions/smallrye-reactive-messaging-kafka/runtime/pom.xml index a1204f7969395..410b03fe8b8a3 100644 --- a/extensions/smallrye-reactive-messaging-kafka/runtime/pom.xml +++ b/extensions/smallrye-reactive-messaging-kafka/runtime/pom.xml @@ -90,9 +90,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-kafka/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/ReactiveMessagingKafkaConfig.java b/extensions/smallrye-reactive-messaging-kafka/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/ReactiveMessagingKafkaConfig.java deleted file mode 100644 index 6865cb3c79e0d..0000000000000 --- a/extensions/smallrye-reactive-messaging-kafka/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/kafka/ReactiveMessagingKafkaConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.quarkus.smallrye.reactivemessaging.kafka; - -import io.quarkus.runtime.annotations.ConfigItem; -import io.quarkus.runtime.annotations.ConfigRoot; - -@ConfigRoot(name = "messaging.kafka") -public class ReactiveMessagingKafkaConfig { - - /** - * Enables the graceful shutdown in dev and test modes. - * The graceful shutdown waits until the inflight records have been processed and the offset committed to Kafka. - * While this setting is highly recommended in production, in dev and test modes, it's disabled by default. - * This setting allows to re-enable it. - */ - @ConfigItem(defaultValue = "false") - public boolean enableGracefulShutdownInDevAndTestMode; - -} diff --git a/extensions/smallrye-reactive-messaging-mqtt/deployment/pom.xml b/extensions/smallrye-reactive-messaging-mqtt/deployment/pom.xml index 00d8ab5e9cf43..af47df29cf77c 100644 --- a/extensions/smallrye-reactive-messaging-mqtt/deployment/pom.xml +++ b/extensions/smallrye-reactive-messaging-mqtt/deployment/pom.xml @@ -73,9 +73,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttBuildTimeConfig.java index 08ad023d7d6ad..51dce9020fa07 100644 --- a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttBuildTimeConfig.java @@ -1,15 +1,15 @@ package io.quarkus.smallrye.reactivemessaging.mqtt.deployment; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; -@ConfigRoot(name = "mqtt", phase = ConfigPhase.BUILD_TIME) -public class MqttBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +@ConfigMapping(prefix = "quarkus.mqtt") +public interface MqttBuildTimeConfig { /** * Configuration for DevServices. DevServices allows Quarkus to automatically start a MQTT broker in dev and test mode. */ - @ConfigItem - public MqttDevServicesBuildTimeConfig devservices; + MqttDevServicesBuildTimeConfig devservices(); } diff --git a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesBuildTimeConfig.java index b7e9be259235f..c08aaa606334b 100644 --- a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesBuildTimeConfig.java @@ -6,10 +6,10 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class MqttDevServicesBuildTimeConfig { +public interface MqttDevServicesBuildTimeConfig { /** * If Dev Services for MQTT has been explicitly enabled or disabled. Dev Services are generally enabled @@ -19,22 +19,20 @@ public class MqttDevServicesBuildTimeConfig { * with * {@code host} or {@code port}. */ - @ConfigItem - public Optional enabled = Optional.empty(); + Optional enabled(); /** * Optional fixed port the dev service will listen to. *

* If not defined, the port will be chosen randomly. */ - @ConfigItem - public OptionalInt port; + OptionalInt port(); /** * The image to use. */ - @ConfigItem(defaultValue = "eclipse-mosquitto:2.0.15") - public String imageName; + @WithDefault("eclipse-mosquitto:2.0.15") + String imageName(); /** * Indicates if the MQTT broker managed by Quarkus Dev Services is shared. @@ -47,8 +45,8 @@ public class MqttDevServicesBuildTimeConfig { *

* Container sharing is only used in dev mode. */ - @ConfigItem(defaultValue = "true") - public boolean shared; + @WithDefault("true") + boolean shared(); /** * The value of the {@code quarkus-dev-service-mqtt} label attached to the started container. @@ -60,13 +58,12 @@ public class MqttDevServicesBuildTimeConfig { *

* This property is used when you need multiple shared MQTT brokers. */ - @ConfigItem(defaultValue = "mqtt") - public String serviceName; + @WithDefault("mqtt") + String serviceName(); /** * Environment variables that are passed to the container. */ - @ConfigItem @ConfigDocMapKey("environment-variable-name") - public Map containerEnv; + Map containerEnv(); } diff --git a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java index 7d9367a876364..67386b09bfeb0 100644 --- a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java @@ -218,7 +218,7 @@ private boolean hasMqttChannelWithoutHostAndPort() { } private MqttDevServiceCfg getConfiguration(MqttBuildTimeConfig cfg) { - MqttDevServicesBuildTimeConfig devServicesConfig = cfg.devservices; + MqttDevServicesBuildTimeConfig devServicesConfig = cfg.devservices(); return new MqttDevServiceCfg(devServicesConfig); } @@ -232,12 +232,12 @@ private static final class MqttDevServiceCfg { private final Map containerEnv; public MqttDevServiceCfg(MqttDevServicesBuildTimeConfig devServicesConfig) { - this.devServicesEnabled = devServicesConfig.enabled.orElse(true); - this.imageName = devServicesConfig.imageName; - this.fixedExposedPort = devServicesConfig.port.orElse(0); - this.shared = devServicesConfig.shared; - this.serviceName = devServicesConfig.serviceName; - this.containerEnv = devServicesConfig.containerEnv; + this.devServicesEnabled = devServicesConfig.enabled().orElse(true); + this.imageName = devServicesConfig.imageName(); + this.fixedExposedPort = devServicesConfig.port().orElse(0); + this.shared = devServicesConfig.shared(); + this.serviceName = devServicesConfig.serviceName(); + this.containerEnv = devServicesConfig.containerEnv(); } @Override diff --git a/extensions/smallrye-reactive-messaging-mqtt/runtime/pom.xml b/extensions/smallrye-reactive-messaging-mqtt/runtime/pom.xml index 1ca33e4d0a01c..1df55e70b0f87 100644 --- a/extensions/smallrye-reactive-messaging-mqtt/runtime/pom.xml +++ b/extensions/smallrye-reactive-messaging-mqtt/runtime/pom.xml @@ -73,9 +73,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-pulsar/deployment/pom.xml b/extensions/smallrye-reactive-messaging-pulsar/deployment/pom.xml index ddb77fea405fb..76404947dcf57 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/deployment/pom.xml +++ b/extensions/smallrye-reactive-messaging-pulsar/deployment/pom.xml @@ -111,9 +111,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarBuildTimeConfig.java index d7c82b3814c08..8acb29f4a53eb 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarBuildTimeConfig.java @@ -1,19 +1,19 @@ package io.quarkus.smallrye.reactivemessaging.pulsar.deployment; import io.quarkus.runtime.annotations.ConfigDocSection; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; -@ConfigRoot(name = "pulsar", phase = ConfigPhase.BUILD_TIME) -public class PulsarBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +@ConfigMapping(prefix = "quarkus.pulsar") +public interface PulsarBuildTimeConfig { /** * Dev Services. *

* Dev Services allows Quarkus to automatically start a Pulsar Container in dev and test mode. */ - @ConfigItem @ConfigDocSection(generated = true) - public PulsarDevServicesBuildTimeConfig devservices; + PulsarDevServicesBuildTimeConfig devservices(); } diff --git a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesBuildTimeConfig.java index ddee633aeeeca..15ed31511e0b5 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesBuildTimeConfig.java @@ -5,10 +5,10 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class PulsarDevServicesBuildTimeConfig { +public interface PulsarDevServicesBuildTimeConfig { /** * If Dev Services for Pulsar has been explicitly enabled or disabled. Dev Services are generally enabled @@ -16,16 +16,14 @@ public class PulsarDevServicesBuildTimeConfig { * {@code pulsar.client.serviceUrl} is set or if all the Reactive Messaging Pulsar channel are configured with * {@code serviceUrl}. */ - @ConfigItem - public Optional enabled = Optional.empty(); + Optional enabled(); /** * Optional fixed port the dev service will listen to. *

* If not defined, the port will be chosen randomly. */ - @ConfigItem - public Optional port; + Optional port(); /** * The image to use. @@ -35,8 +33,8 @@ public class PulsarDevServicesBuildTimeConfig { * Check https://hub.docker.com/r/apachepulsar/pulsar to find the available versions. */ // Alpine-based images starting from 3.3.0 fail to start on aarch64: https://github.com/apache/pulsar/issues/23306 - @ConfigItem(defaultValue = "apachepulsar/pulsar:3.2.4") - public String imageName; + @WithDefault("apachepulsar/pulsar:3.2.4") + String imageName(); /** * Indicates if the Pulsar broker managed by Quarkus Dev Services is shared. @@ -49,8 +47,8 @@ public class PulsarDevServicesBuildTimeConfig { *

* Container sharing is only used in dev mode. */ - @ConfigItem(defaultValue = "true") - public boolean shared; + @WithDefault("true") + boolean shared(); /** * The value of the {@code quarkus-dev-service-pulsar} label attached to the started container. @@ -62,14 +60,13 @@ public class PulsarDevServicesBuildTimeConfig { *

* This property is used when you need multiple shared Pulsar brokers. */ - @ConfigItem(defaultValue = "pulsar") - public String serviceName; + @WithDefault("pulsar") + String serviceName(); /** * Broker config to set on the Pulsar instance */ - @ConfigItem @ConfigDocMapKey("environment-variable-name") - public Map brokerConfig; + Map brokerConfig(); } diff --git a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java index c339b99151e70..03bf4106d2f95 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java @@ -238,7 +238,7 @@ private boolean hasPulsarChannelWithoutHostAndPort() { } private PulsarDevServiceCfg getConfiguration(PulsarBuildTimeConfig cfg) { - PulsarDevServicesBuildTimeConfig devServicesConfig = cfg.devservices; + PulsarDevServicesBuildTimeConfig devServicesConfig = cfg.devservices(); return new PulsarDevServiceCfg(devServicesConfig); } @@ -251,12 +251,12 @@ private static final class PulsarDevServiceCfg { private final Map brokerConfig; public PulsarDevServiceCfg(PulsarDevServicesBuildTimeConfig devServicesConfig) { - this.devServicesEnabled = devServicesConfig.enabled.orElse(true); - this.imageName = devServicesConfig.imageName; - this.fixedExposedPort = devServicesConfig.port.orElse(0); - this.shared = devServicesConfig.shared; - this.serviceName = devServicesConfig.serviceName; - this.brokerConfig = devServicesConfig.brokerConfig; + this.devServicesEnabled = devServicesConfig.enabled().orElse(true); + this.imageName = devServicesConfig.imageName(); + this.fixedExposedPort = devServicesConfig.port().orElse(0); + this.shared = devServicesConfig.shared(); + this.serviceName = devServicesConfig.serviceName(); + this.brokerConfig = devServicesConfig.brokerConfig(); } @Override diff --git a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarSchemaDiscoveryProcessor.java b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarSchemaDiscoveryProcessor.java index f5539127a0149..9f5d75d342d77 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarSchemaDiscoveryProcessor.java +++ b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarSchemaDiscoveryProcessor.java @@ -43,10 +43,11 @@ public void defaultChannelConfiguration( BuildProducer syntheticBean, RecorderContext recorderContext, SchemaProviderRecorder recorder) { - if (buildTimeConfig.schemaAutodetectionEnabled) { + if (buildTimeConfig.schemaAutodetectionEnabled()) { DefaultSchemaDiscoveryState discoveryState = new DefaultSchemaDiscoveryState(combinedIndex.getIndex()); discoverDefaultSerdeConfig(discoveryState, channelsManagedByConnectors, defaultConfigProducer, - buildTimeConfig.schemaGenerationEnabled ? new SyntheticBeanBuilder(syntheticBean, recorder, recorderContext) + buildTimeConfig.schemaGenerationEnabled() + ? new SyntheticBeanBuilder(syntheticBean, recorder, recorderContext) : null); } } diff --git a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/ReactiveMessagingPulsarBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/ReactiveMessagingPulsarBuildTimeConfig.java index ac819771b046a..472b1667fa849 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/ReactiveMessagingPulsarBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/ReactiveMessagingPulsarBuildTimeConfig.java @@ -1,21 +1,26 @@ package io.quarkus.smallrye.reactivemessaging.pulsar.deployment; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "messaging.pulsar", phase = ConfigPhase.BUILD_TIME) -public class ReactiveMessagingPulsarBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +@ConfigMapping(prefix = "quarkus.messaging.pulsar") +public interface ReactiveMessagingPulsarBuildTimeConfig { /** * Whether or not Pulsar Schema auto-detection is enabled. */ - @ConfigItem(name = "schema-autodetection.enabled", defaultValue = "true") - public boolean schemaAutodetectionEnabled; + @WithName("schema-autodetection.enabled") + @WithDefault("true") + boolean schemaAutodetectionEnabled(); /** * Whether Pulsar Schema generation is enabled. * When no Schema are found and not set, Quarkus generates a JSON Schema. */ - @ConfigItem(name = "schema-generation.enabled", defaultValue = "true") - public boolean schemaGenerationEnabled; + @WithName("schema-generation.enabled") + @WithDefault("true") + boolean schemaGenerationEnabled(); } diff --git a/extensions/smallrye-reactive-messaging-pulsar/runtime/pom.xml b/extensions/smallrye-reactive-messaging-pulsar/runtime/pom.xml index 36b057b5b2151..d34381809feb6 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/runtime/pom.xml +++ b/extensions/smallrye-reactive-messaging-pulsar/runtime/pom.xml @@ -157,9 +157,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/pom.xml b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/pom.xml index 7e24315a51b04..a28fc62c8e931 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/pom.xml +++ b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/pom.xml @@ -91,9 +91,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQBuildTimeConfig.java index ea478a7074ef2..bf259bf80d49d 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQBuildTimeConfig.java @@ -3,27 +3,26 @@ import java.util.Optional; import io.quarkus.runtime.annotations.ConfigDocSection; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; -@ConfigRoot(name = "rabbitmq", phase = ConfigPhase.BUILD_TIME) -public class RabbitMQBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +@ConfigMapping(prefix = "quarkus.rabbitmq") +public interface RabbitMQBuildTimeConfig { /** * Dev Services. *

* DevServices allows Quarkus to start a RabbitMQ broker in dev and test mode automatically. */ - @ConfigItem @ConfigDocSection(generated = true) - public RabbitMQDevServicesBuildTimeConfig devservices; + RabbitMQDevServicesBuildTimeConfig devservices(); /** * The credentials provider name. */ - @ConfigItem - public Optional credentialsProvider = Optional.empty(); + Optional credentialsProvider(); /** * The credentials provider bean name. @@ -34,6 +33,5 @@ public class RabbitMQBuildTimeConfig { *

* For Vault, the credentials provider bean name is {@code vault-credentials-provider}. */ - @ConfigItem - public Optional credentialsProviderName = Optional.empty(); + Optional credentialsProviderName(); } diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesBuildTimeConfig.java b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesBuildTimeConfig.java index a0a1ca41e2727..015569e7fa21f 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesBuildTimeConfig.java @@ -7,114 +7,109 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class RabbitMQDevServicesBuildTimeConfig { +public interface RabbitMQDevServicesBuildTimeConfig { @ConfigGroup - public static class Exchange { + public interface Exchange { /** * Type of exchange: direct, topic, headers, fanout, etc. */ - @ConfigItem(defaultValue = "direct") - public String type; + @WithDefault("direct") + String type(); /** * Should the exchange be deleted when all queues are finished using it? */ - @ConfigItem(defaultValue = "false") - public Boolean autoDelete; + @WithDefault("false") + Boolean autoDelete(); /** * Should the exchange remain after restarts? */ - @ConfigItem(defaultValue = "false") - public Boolean durable; + @WithDefault("false") + Boolean durable(); /** * What virtual host should the exchange be associated with? */ - @ConfigItem(defaultValue = "/") - public String vhost; + @WithDefault("/") + String vhost(); /** * Extra arguments for the exchange definition. */ - @ConfigItem @ConfigDocMapKey("argument-name") - public Map arguments; + Map arguments(); } @ConfigGroup - public static class Queue { + public interface Queue { /** * Should the queue be deleted when all consumers are finished using it? */ - @ConfigItem(defaultValue = "false") - public Boolean autoDelete; + @WithDefault("false") + Boolean autoDelete(); /** * Should the queue remain after restarts? */ - @ConfigItem(defaultValue = "false") - public Boolean durable; + @WithDefault("false") + Boolean durable(); /** * What virtual host should the queue be associated with? */ - @ConfigItem(defaultValue = "/") - public String vhost; + @WithDefault("/") + String vhost(); /** * Extra arguments for the queue definition. */ - @ConfigItem @ConfigDocMapKey("argument-name") - public Map arguments; + Map arguments(); } @ConfigGroup - public static class Binding { + public interface Binding { /** * Source exchange to bind to. Defaults to name of binding instance. */ - @ConfigItem - public Optional source; + Optional source(); /** * Routing key specification for the source exchange. */ - @ConfigItem(defaultValue = "#") - public String routingKey; + @WithDefault("#") + String routingKey(); /** * Destination exchange or queue to bind to. Defaults to name of binding instance. */ - @ConfigItem - public Optional destination; + Optional destination(); /** * Destination type for binding: queue, exchange, etc. */ - @ConfigItem(defaultValue = "queue") - public String destinationType; + @WithDefault("queue") + String destinationType(); /** * What virtual host should the binding be associated with? */ - @ConfigItem(defaultValue = "/") - public String vhost; + @WithDefault("/") + String vhost(); /** * Extra arguments for the binding definition. */ - @ConfigItem @ConfigDocMapKey("argument-name") - public Map arguments; + Map arguments(); } /** @@ -124,32 +119,29 @@ public static class Binding { * with * {@code host} or {@code port}. */ - @ConfigItem - public Optional enabled = Optional.empty(); + Optional enabled(); /** * Optional fixed port the dev service will listen to. *

* If not defined, the port will be chosen randomly. */ - @ConfigItem - public OptionalInt port; + OptionalInt port(); /** * Optional fixed port for the RabbitMQ management plugin. *

* If not defined, the port will be chosen randomly. */ - @ConfigItem - public OptionalInt httpPort; + OptionalInt httpPort(); /** * The image to use. * Note that only official RabbitMQ images are supported. * Specifically, the image repository must end with {@code rabbitmq}. */ - @ConfigItem(defaultValue = "rabbitmq:3.12-management") - public String imageName; + @WithDefault("rabbitmq:3.12-management") + String imageName(); /** * Indicates if the RabbitMQ broker managed by Quarkus Dev Services is shared. @@ -162,8 +154,8 @@ public static class Binding { *

* Container sharing is only used in dev mode. */ - @ConfigItem(defaultValue = "true") - public boolean shared; + @WithDefault("true") + boolean shared(); /** * The value of the {@code quarkus-dev-service-rabbitmq} label attached to the started container. @@ -175,40 +167,35 @@ public static class Binding { *

* This property is used when you need multiple shared RabbitMQ brokers. */ - @ConfigItem(defaultValue = "rabbitmq") - public String serviceName; + @WithDefault("rabbitmq") + String serviceName(); /** * Exchanges that should be predefined after starting the RabbitMQ broker. */ - @ConfigItem @ConfigDocMapKey("exchange-name") - public Map exchanges; + Map exchanges(); /** * Queues that should be predefined after starting the RabbitMQ broker. */ - @ConfigItem @ConfigDocMapKey("queue-name") - public Map queues; + Map queues(); /** * Bindings that should be predefined after starting the RabbitMQ broker. */ - @ConfigItem @ConfigDocMapKey("binding-name") - public Map bindings; + Map bindings(); /** * Virtual hosts that should be predefined after starting the RabbitMQ broker. */ - @ConfigItem - public Optional> vhosts; + Optional> vhosts(); /** * Environment variables that are passed to the container. */ - @ConfigItem @ConfigDocMapKey("environment-variable-name") - public Map containerEnv; + Map containerEnv(); } diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java index 1318fd5e1f02c..e9ecb89ca7c14 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java @@ -245,7 +245,7 @@ private boolean hasRabbitMQChannelWithoutHostAndPort() { } private RabbitMQDevServiceCfg getConfiguration(RabbitMQBuildTimeConfig cfg) { - RabbitMQDevServicesBuildTimeConfig devServicesConfig = cfg.devservices; + RabbitMQDevServicesBuildTimeConfig devServicesConfig = cfg.devservices(); return new RabbitMQDevServiceCfg(devServicesConfig); } @@ -265,12 +265,12 @@ static class Exchange { Exchange(String name, RabbitMQDevServicesBuildTimeConfig.Exchange source) { this.name = name; - this.type = source.type; - this.autoDelete = source.autoDelete; - this.durable = source.durable; - this.vhost = source.vhost; - this.arguments = source.arguments != null - ? source.arguments.entrySet().stream().collect(Collectors.toMap(Entry::getKey, Entry::getValue)) + this.type = source.type(); + this.autoDelete = source.autoDelete(); + this.durable = source.durable(); + this.vhost = source.vhost(); + this.arguments = source.arguments() != null + ? source.arguments().entrySet().stream().collect(Collectors.toMap(Entry::getKey, Entry::getValue)) : Map.of(); } } @@ -288,11 +288,11 @@ static class Queue { Queue(String name, RabbitMQDevServicesBuildTimeConfig.Queue source) { this.name = name; - this.autoDelete = source.autoDelete; - this.durable = source.durable; - this.vhost = source.vhost; - this.arguments = source.arguments != null - ? source.arguments.entrySet().stream().collect(Collectors.toMap(Entry::getKey, Entry::getValue)) + this.autoDelete = source.autoDelete(); + this.durable = source.durable(); + this.vhost = source.vhost(); + this.arguments = source.arguments() != null + ? source.arguments().entrySet().stream().collect(Collectors.toMap(Entry::getKey, Entry::getValue)) : Map.of(); } } @@ -310,13 +310,13 @@ static class Binding { } Binding(String name, RabbitMQDevServicesBuildTimeConfig.Binding source) { - this.source = source.source.orElse(name); - this.routingKey = source.routingKey; - this.destination = source.destination.orElse(name); - this.destinationType = source.destinationType; - this.vhost = source.vhost; - this.arguments = source.arguments != null - ? source.arguments.entrySet().stream().collect(Collectors.toMap(Entry::getKey, Entry::getValue)) + this.source = source.source().orElse(name); + this.routingKey = source.routingKey(); + this.destination = source.destination().orElse(name); + this.destinationType = source.destinationType(); + this.vhost = source.vhost(); + this.arguments = source.arguments() != null + ? source.arguments().entrySet().stream().collect(Collectors.toMap(Entry::getKey, Entry::getValue)) : Map.of(); } } @@ -334,23 +334,23 @@ static class Binding { private final Map containerEnv; public RabbitMQDevServiceCfg(RabbitMQDevServicesBuildTimeConfig devServicesConfig) { - this.devServicesEnabled = devServicesConfig.enabled.orElse(true); - this.imageName = devServicesConfig.imageName; - this.fixedExposedPort = devServicesConfig.port.orElse(0); - this.fixedExposedHttpPort = devServicesConfig.httpPort.orElse(0); - this.shared = devServicesConfig.shared; - this.serviceName = devServicesConfig.serviceName; - this.exchanges = devServicesConfig.exchanges != null - ? devServicesConfig.exchanges.entrySet().stream().map(Exchange::new).collect(Collectors.toList()) + this.devServicesEnabled = devServicesConfig.enabled().orElse(true); + this.imageName = devServicesConfig.imageName(); + this.fixedExposedPort = devServicesConfig.port().orElse(0); + this.fixedExposedHttpPort = devServicesConfig.httpPort().orElse(0); + this.shared = devServicesConfig.shared(); + this.serviceName = devServicesConfig.serviceName(); + this.exchanges = devServicesConfig.exchanges() != null + ? devServicesConfig.exchanges().entrySet().stream().map(Exchange::new).collect(Collectors.toList()) : Collections.emptyList(); - this.queues = devServicesConfig.queues != null - ? devServicesConfig.queues.entrySet().stream().map(Queue::new).collect(Collectors.toList()) + this.queues = devServicesConfig.queues() != null + ? devServicesConfig.queues().entrySet().stream().map(Queue::new).collect(Collectors.toList()) : Collections.emptyList(); - this.bindings = devServicesConfig.bindings != null - ? devServicesConfig.bindings.entrySet().stream().map(Binding::new).collect(Collectors.toList()) + this.bindings = devServicesConfig.bindings() != null + ? devServicesConfig.bindings().entrySet().stream().map(Binding::new).collect(Collectors.toList()) : Collections.emptyList(); - this.vhosts = devServicesConfig.vhosts.orElse(Collections.emptyList()); - this.containerEnv = devServicesConfig.containerEnv; + this.vhosts = devServicesConfig.vhosts().orElse(Collections.emptyList()); + this.containerEnv = devServicesConfig.containerEnv(); } @Override diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/SmallRyeReactiveMessagingRabbitMQProcessor.java b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/SmallRyeReactiveMessagingRabbitMQProcessor.java index 6ef67b097a462..3272ce5008feb 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/SmallRyeReactiveMessagingRabbitMQProcessor.java +++ b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/SmallRyeReactiveMessagingRabbitMQProcessor.java @@ -36,12 +36,12 @@ public void dynamicCredentials(RabbitMQRecorder recorder, additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(Identifier.class).build()); - if (rabbitMQBuildTimeConfig.credentialsProvider.isPresent()) { - String credentialsProvider = rabbitMQBuildTimeConfig.credentialsProvider.get(); + if (rabbitMQBuildTimeConfig.credentialsProvider().isPresent()) { + String credentialsProvider = rabbitMQBuildTimeConfig.credentialsProvider().get(); RuntimeValue credentialsProviderLink = recorder.configureOptions( credentialsProvider, - rabbitMQBuildTimeConfig.credentialsProviderName); + rabbitMQBuildTimeConfig.credentialsProviderName()); String identifier = "credentials-provider-link-" + credentialsProvider; diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/runtime/pom.xml b/extensions/smallrye-reactive-messaging-rabbitmq/runtime/pom.xml index ff7ab1c95d033..54b256b2703ee 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/runtime/pom.xml +++ b/extensions/smallrye-reactive-messaging-rabbitmq/runtime/pom.xml @@ -81,9 +81,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging/deployment/pom.xml b/extensions/smallrye-reactive-messaging/deployment/pom.xml index 675ec3b76df01..48bb697915491 100644 --- a/extensions/smallrye-reactive-messaging/deployment/pom.xml +++ b/extensions/smallrye-reactive-messaging/deployment/pom.xml @@ -104,9 +104,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/ReactiveMessagingBuildTimeConfig.java b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/ReactiveMessagingBuildTimeConfig.java index a88551ef62393..f9c105e399192 100644 --- a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/ReactiveMessagingBuildTimeConfig.java +++ b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/ReactiveMessagingBuildTimeConfig.java @@ -1,16 +1,20 @@ package io.quarkus.smallrye.reactivemessaging.deployment; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "messaging", phase = ConfigPhase.BUILD_TIME) -public class ReactiveMessagingBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +@ConfigMapping(prefix = "quarkus.messaging") +public interface ReactiveMessagingBuildTimeConfig { /** * Whether a health check is published in case the smallrye-health extension is present. */ - @ConfigItem(name = "health.enabled", defaultValue = "true") - public boolean healthEnabled; + @WithName("health.enabled") + @WithDefault("true") + boolean healthEnabled(); /** * Whether it should automatically configure the connector attribute of channels that don't have an @@ -20,6 +24,7 @@ public class ReactiveMessagingBuildTimeConfig { * associates the orphans channel to the connector, removing the need to add the .connector * attribute in the application configuration. */ - @ConfigItem(name = "auto-connector-attachment", defaultValue = "true") - public boolean autoConnectorAttachment; + @WithName("auto-connector-attachment") + @WithDefault("true") + boolean autoConnectorAttachment(); } diff --git a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java index abd7dc0c5a2fd..16d9b47dea26c 100644 --- a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java +++ b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java @@ -179,7 +179,7 @@ public List removalExclusions() { @BuildStep public AnnotationsTransformerBuildItem enableMetrics(Optional metricsCapability, ReactiveMessagingConfiguration configuration) { - boolean isMetricEnabled = metricsCapability.isPresent() && configuration.metricsEnabled; + boolean isMetricEnabled = metricsCapability.isPresent() && configuration.metricsEnabled(); boolean useMicrometer = isMetricEnabled && metricsCapability.get().metricsSupported(MetricsFactory.MICROMETER); LOGGER.debug("Metrics Enabled: " + isMetricEnabled + "; Using Micrometer: " + useMicrometer); return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() { @@ -222,14 +222,14 @@ public void enableHealth(ReactiveMessagingBuildTimeConfig buildTimeConfig, BuildProducer transformations) { producer.produce( new HealthBuildItem(SmallRyeReactiveMessagingLivenessCheck.class.getName(), - buildTimeConfig.healthEnabled)); + buildTimeConfig.healthEnabled())); producer.produce( new HealthBuildItem(SmallRyeReactiveMessagingReadinessCheck.class.getName(), - buildTimeConfig.healthEnabled)); + buildTimeConfig.healthEnabled())); producer.produce( new HealthBuildItem(SmallRyeReactiveMessagingStartupCheck.class.getName(), - buildTimeConfig.healthEnabled)); - if (buildTimeConfig.healthEnabled) { + buildTimeConfig.healthEnabled())); + if (buildTimeConfig.healthEnabled()) { beans.produce(new AdditionalBeanBuildItem(HealthCenterFilter.class, HealthCenterInterceptor.class)); transformations.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() { @@ -308,9 +308,9 @@ public void build(SmallRyeReactiveMessagingRecorder recorder, RecorderContext re QuarkusMediatorConfiguration mediatorConfiguration = QuarkusMediatorConfigurationUtil .create(methodInfo, isSuspendMethod, bean, recorderContext, - Thread.currentThread().getContextClassLoader(), conf.strict, + Thread.currentThread().getContextClassLoader(), conf.strict(), consumesFromConnector(methodInfo, connectorManagedIncomingChannels) - ? conf.blockingSignaturesExecutionMode + ? conf.blockingSignaturesExecutionMode() : ReactiveMessagingConfiguration.ExecutionMode.EVENT_LOOP); // disable execution mode setting for inner channels mediatorConfigurations.add(mediatorConfiguration); diff --git a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringProcessor.java b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringProcessor.java index 4edc06b5615a2..c524ccab3069a 100644 --- a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringProcessor.java +++ b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringProcessor.java @@ -363,7 +363,7 @@ public void autoConfigureConnectorForOrphansAndProduceManagedChannels( } } - if (incomingConnectors.size() == 1 && buildTimeConfig.autoConnectorAttachment) { + if (incomingConnectors.size() == 1 && buildTimeConfig.autoConnectorAttachment()) { String connector = incomingConnectors.iterator().next(); // Single incoming connector, set mp.messaging.incoming.orphan-channel.connector for (OrphanChannelBuildItem orphan : orphans) { @@ -378,7 +378,7 @@ public void autoConfigureConnectorForOrphansAndProduceManagedChannels( } } - if (outgoingConnectors.size() == 1 && buildTimeConfig.autoConnectorAttachment) { + if (outgoingConnectors.size() == 1 && buildTimeConfig.autoConnectorAttachment()) { String connector = outgoingConnectors.iterator().next(); // Single outgoing connector, set mp.messaging.outgoing.orphan-channel.connector for (OrphanChannelBuildItem orphan : orphans) { diff --git a/extensions/smallrye-reactive-messaging/runtime/pom.xml b/extensions/smallrye-reactive-messaging/runtime/pom.xml index 3fdbb10bfba31..d905539602a6a 100644 --- a/extensions/smallrye-reactive-messaging/runtime/pom.xml +++ b/extensions/smallrye-reactive-messaging/runtime/pom.xml @@ -107,9 +107,6 @@ ${project.version} - - -AlegacyConfigRoot=true - diff --git a/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/ReactiveMessagingConfiguration.java b/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/ReactiveMessagingConfiguration.java index 94555611afbe4..8ed58c48dfa00 100644 --- a/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/ReactiveMessagingConfiguration.java +++ b/extensions/smallrye-reactive-messaging/runtime/src/main/java/io/quarkus/smallrye/reactivemessaging/runtime/ReactiveMessagingConfiguration.java @@ -1,31 +1,36 @@ package io.quarkus.smallrye.reactivemessaging.runtime; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; -@ConfigRoot(name = "messaging", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) -public class ReactiveMessagingConfiguration { +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +@ConfigMapping(prefix = "quarkus.messaging") +public interface ReactiveMessagingConfiguration { /** * Whether Reactive Messaging metrics are published in case a metrics extension is present * (default to false). */ - @ConfigItem(name = "metrics.enabled") - public boolean metricsEnabled; + @WithName("metrics.enabled") + @WithDefault("false") + boolean metricsEnabled(); /** * Enables or disables the strict validation mode. */ - @ConfigItem(name = "strict", defaultValue = "false") - public boolean strict; + @WithDefault("false") + boolean strict(); /** * Execution mode for the Messaging signatures considered "blocking", defaults to "worker". * For the previous behaviour set to "event-loop". */ - @ConfigItem(name = "blocking.signatures.execution.mode", defaultValue = "worker") - public ExecutionMode blockingSignaturesExecutionMode; + @WithName("blocking.signatures.execution.mode") + @WithDefault("worker") + ExecutionMode blockingSignaturesExecutionMode(); public enum ExecutionMode { EVENT_LOOP,