Skip to content

Commit

Permalink
fixes for using @ConfigMapping in quarkus extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
christofluethi committed Dec 10, 2024
1 parent bab1ceb commit 296de18
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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
quarkus.appinfo.run-by=Tim&Koko AG
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ void syntheticBean(AppinfoBuildTimeConfig appinfoConfig,
BuildProducer<SyntheticBeanBuildItem> 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))
Expand All @@ -58,7 +58,7 @@ void createServlet(LaunchModeBuildItem launchMode,
BuildProducer<ServletBuildItem> additionalBean) {

if(shouldInclude(launchMode, appinfoConfig)) {
String basePath = appinfoConfig.basePath;
String basePath = appinfoConfig.basePath();
if(basePath.startsWith("/")) {
basePath = basePath.replaceFirst("/", "");
}
Expand Down Expand Up @@ -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();
}
}
3 changes: 0 additions & 3 deletions solution/techlab-extension-appinfo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
<version>${compiler-plugin.version}</version>
<configuration>
<parameters>true</parameters>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 296de18

Please sign in to comment.