Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for using @ConfigMapping in quarkus extensions #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ quarkus.appinfo.record-build-time=true
quarkus.appinfo.built-for=quarkus-training

# runtime (changeable at runtime)
quarkus.appinfo.run-by=Puzzle ITC GmbH
quarkus.appinfo.run-by=Puzzle ITC GmbH
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();
}
Loading