Skip to content

Commit

Permalink
Switch to @ConfigMapping (#238)
Browse files Browse the repository at this point in the history
The legacy config classes will go away at some point in the future so
let's be prepared and migrate to @ConfigMapping.
  • Loading branch information
gsmet authored Feb 12, 2025
1 parent a5125af commit 83a273b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
3 changes: 0 additions & 3 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,34 @@
import java.util.Optional;

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.WithConverter;
import io.smallrye.config.WithDefault;
import net.thisptr.jackson.jq.Version;

@ConfigRoot(name = JacksonJqConfig.CONFIG_PREFIX, phase = ConfigPhase.BUILD_TIME)
public class JacksonJqConfig {
static final String CONFIG_PREFIX = "jackson.jq";
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
@ConfigMapping(prefix = "quarkus.jackson.jq")
public interface JacksonJqConfig {

/**
* Configure function related config
*/
@ConfigItem
public FunctionsConfig functions;
FunctionsConfig functions();

@ConfigGroup
public static class FunctionsConfig {
public interface FunctionsConfig {
/**
* The supported jq version
*/
@ConfigItem(defaultValue = "1.6")
@WithDefault("1.6")
@WithConverter(JacksonJqVersionConverter.class)
public Version version;
Version version();

/**
* List of functions to exclude
*/
@ConfigItem
public Optional<List<String>> excludes;
Optional<List<String>> excludes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ SyntheticBeanBuildItem quarkusScopeBean(
RecorderContext context) throws Exception {

IndexView indexView = combinedIndex.getIndex();
List<String> excludes = config.functions.excludes.orElseGet(Collections::emptyList);
List<String> excludes = config.functions().excludes().orElseGet(Collections::emptyList);

RuntimeValue<Scope> root = recorder.createScope();
RuntimeValue<Scope> local = recorder.createScope(root);

// load built-in int functions
lookupFunctionsFromConfig(archives, config).forEach(e -> {
if (!excludes.contains(e.name)) {
recorder.addFunction(root, e.name, e.args, e.body, config.functions.version.toString());
recorder.addFunction(root, e.name, e.args, e.body, config.functions().version().toString());
}
});
lookupFunctions(indexView, config, context, BuiltinFunction.class).forEach(f -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static List<JqJson.JqFuncDef> lookupFunctionsFromConfig(
.collect(Collectors.joining());

mapper.readValue(functions, JqJson.class).functions.stream()
.filter(f -> f.version == null || f.version.contains(config.functions.version))
.filter(f -> f.version == null || f.version.contains(config.functions().version()))
.forEach(answer::add);
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ static List<JacksonJqFunctionBuildItem> lookupFunctions(
context.newInstance(ci.name().toString()));

if (version != null && !version.asString().isEmpty()) {
if (!VersionRange.valueOf(version.asString()).contains(config.functions.version)) {
if (!VersionRange.valueOf(version.asString()).contains(config.functions().version())) {
continue;
}
}
Expand Down

0 comments on commit 83a273b

Please sign in to comment.