From 296de1827f748dbdf03b19b50fe347cb84e04924 Mon Sep 17 00:00:00 2001 From: christofluethi Date: Tue, 10 Dec 2024 16:17:09 +0100 Subject: [PATCH 1/2] fixes for using @ConfigMapping in quarkus extensions --- .../src/main/resources/application.properties | 6 ++--- .../deployment/AppinfoBuildTimeConfig.java | 23 ++++++++++--------- .../TechlabExtensionAppinfoProcessor.java | 18 +++++++-------- solution/techlab-extension-appinfo/pom.xml | 3 --- .../appinfo/runtime/AppinfoRunTimeConfig.java | 10 ++++---- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/solution/quarkus-appinfo-application/src/main/resources/application.properties b/solution/quarkus-appinfo-application/src/main/resources/application.properties index 9e4556f3..a42ffa3a 100644 --- a/solution/quarkus-appinfo-application/src/main/resources/application.properties +++ b/solution/quarkus-appinfo-application/src/main/resources/application.properties @@ -1,10 +1,10 @@ # Application Name -quarkus.application.name=Demo Application AppInfo +quarkus.application.name=My Demo Application AppInfo # build time (only available at build time) quarkus.appinfo.always-include=true quarkus.appinfo.record-build-time=true -quarkus.appinfo.built-for=quarkus-training +quarkus.appinfo.built-for=quarkus basics training # runtime (changeable at runtime) -quarkus.appinfo.run-by=Puzzle ITC GmbH \ No newline at end of file +quarkus.appinfo.run-by=Tim&Koko AG diff --git a/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/AppinfoBuildTimeConfig.java b/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/AppinfoBuildTimeConfig.java index 1efed2de..fe73e9d3 100644 --- a/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/AppinfoBuildTimeConfig.java +++ b/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/AppinfoBuildTimeConfig.java @@ -1,35 +1,36 @@ package ch.puzzle.quarkustechlab.extensions.appinfo.deployment; import ch.puzzle.quarkustechlab.extensions.appinfo.runtime.AppinfoNames; -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 = AppinfoNames.EXTENSION_NAME, phase = ConfigPhase.BUILD_TIME) -public class AppinfoBuildTimeConfig { +@ConfigMapping(prefix = AppinfoNames.CONFIG_PREFIX) +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +public interface AppinfoBuildTimeConfig { /** * Simple builtFor information string */ - @ConfigItem - String builtFor; + String builtFor(); /** * Include build time collection feature in build */ - @ConfigItem(defaultValue = "true") - boolean recordBuildTime; + @WithDefault("true") + boolean recordBuildTime(); /** * Always include this. By default this will only be included in dev and test. * Setting this to true will also include this in Prod */ - @ConfigItem(defaultValue = "false") - boolean alwaysInclude; + @WithDefault("false") + boolean alwaysInclude(); /** * Specify basePath for extension endpoint */ - @ConfigItem(defaultValue = AppinfoNames.EXTENSION_NAME) - String basePath; + @WithDefault(AppinfoNames.EXTENSION_NAME) + String basePath(); } \ No newline at end of file diff --git a/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/TechlabExtensionAppinfoProcessor.java b/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/TechlabExtensionAppinfoProcessor.java index fcbb3641..66600db5 100644 --- a/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/TechlabExtensionAppinfoProcessor.java +++ b/solution/techlab-extension-appinfo/deployment/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/deployment/TechlabExtensionAppinfoProcessor.java @@ -40,10 +40,10 @@ void syntheticBean(AppinfoBuildTimeConfig appinfoConfig, BuildProducer syntheticBeans) { if(shouldInclude(launchMode, appinfoConfig)) { - String buildTime = appinfoConfig.recordBuildTime ? Instant.now().toString() : null; - String builtFor = appinfoConfig.builtFor; + String buildTime = appinfoConfig.recordBuildTime() ? Instant.now().toString() : null; + String builtFor = appinfoConfig.builtFor(); - logger.info("Adding BuildInfo. RecordBuildTime={}, BuiltFor={}", appinfoConfig.recordBuildTime, builtFor); + logger.info("Adding BuildInfo. RecordBuildTime={}, BuiltFor={}", appinfoConfig.recordBuildTime(), builtFor); syntheticBeans.produce(SyntheticBeanBuildItem.configure(BuildInfo.class).scope(Singleton.class) .runtimeValue(recorder.createBuildInfo(buildTime, builtFor)) @@ -58,7 +58,7 @@ void createServlet(LaunchModeBuildItem launchMode, BuildProducer additionalBean) { if(shouldInclude(launchMode, appinfoConfig)) { - String basePath = appinfoConfig.basePath; + String basePath = appinfoConfig.basePath(); if(basePath.startsWith("/")) { basePath = basePath.replaceFirst("/", ""); } @@ -89,13 +89,13 @@ void registerAdditionalBeans(AppinfoBuildTimeConfig appinfoConfig, @BuildStep StaticMetadataBuildItem createStaticMetadata(AppinfoBuildTimeConfig appInfoBuildTimeConfig) { return new StaticMetadataBuildItem(Version.getVersion(), - appInfoBuildTimeConfig.builtFor, - appInfoBuildTimeConfig.alwaysInclude, - appInfoBuildTimeConfig.basePath, - appInfoBuildTimeConfig.recordBuildTime); + appInfoBuildTimeConfig.builtFor(), + appInfoBuildTimeConfig.alwaysInclude(), + appInfoBuildTimeConfig.basePath(), + appInfoBuildTimeConfig.recordBuildTime()); } private static boolean shouldInclude(LaunchModeBuildItem launchMode, AppinfoBuildTimeConfig appinfoConfig) { - return launchMode.getLaunchMode().isDevOrTest() || appinfoConfig.alwaysInclude; + return launchMode.getLaunchMode().isDevOrTest() || appinfoConfig.alwaysInclude(); } } diff --git a/solution/techlab-extension-appinfo/pom.xml b/solution/techlab-extension-appinfo/pom.xml index 9bfc2075..fd862f27 100644 --- a/solution/techlab-extension-appinfo/pom.xml +++ b/solution/techlab-extension-appinfo/pom.xml @@ -70,9 +70,6 @@ ${compiler-plugin.version} true - - -AlegacyConfigRoot=true - diff --git a/solution/techlab-extension-appinfo/runtime/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/runtime/AppinfoRunTimeConfig.java b/solution/techlab-extension-appinfo/runtime/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/runtime/AppinfoRunTimeConfig.java index fde37c0d..28bd0ace 100644 --- a/solution/techlab-extension-appinfo/runtime/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/runtime/AppinfoRunTimeConfig.java +++ b/solution/techlab-extension-appinfo/runtime/src/main/java/ch/puzzle/quarkustechlab/extensions/appinfo/runtime/AppinfoRunTimeConfig.java @@ -1,15 +1,15 @@ package ch.puzzle.quarkustechlab.extensions.appinfo.runtime; -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 = AppinfoNames.EXTENSION_NAME, phase = ConfigPhase.RUN_TIME) -public class AppinfoRunTimeConfig { +@ConfigMapping(prefix = AppinfoNames.CONFIG_PREFIX) +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface AppinfoRunTimeConfig { /** * Simple runBy information string */ - @ConfigItem - String runBy; + String runBy(); } From e60ad5001eb7d8b581a38dea28686b11fa1752d1 Mon Sep 17 00:00:00 2001 From: christofluethi Date: Tue, 10 Dec 2024 16:23:02 +0100 Subject: [PATCH 2/2] config properties --- .../src/main/resources/application.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solution/quarkus-appinfo-application/src/main/resources/application.properties b/solution/quarkus-appinfo-application/src/main/resources/application.properties index a42ffa3a..8cfffea0 100644 --- a/solution/quarkus-appinfo-application/src/main/resources/application.properties +++ b/solution/quarkus-appinfo-application/src/main/resources/application.properties @@ -1,10 +1,10 @@ # Application Name -quarkus.application.name=My Demo Application AppInfo +quarkus.application.name=Demo Application AppInfo # build time (only available at build time) quarkus.appinfo.always-include=true quarkus.appinfo.record-build-time=true -quarkus.appinfo.built-for=quarkus basics training +quarkus.appinfo.built-for=quarkus-training # runtime (changeable at runtime) -quarkus.appinfo.run-by=Tim&Koko AG +quarkus.appinfo.run-by=Puzzle ITC GmbH