From 2932750e364d80c373583e7a72fc8bb391f591c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tama?= Date: Mon, 26 Aug 2024 13:05:09 +0200 Subject: [PATCH] Removes deprecated @ConfigRoot without @ConfigMapping (#351) --- .../ROOT/pages/includes/attributes.adoc | 2 +- .../DevServicesMinioProcessor.java | 18 +++---- .../devservices/MinioBuildTimeConfig.java | 10 ++-- .../MinioDevServicesBuildTimeConfig.java | 35 ++++++------ .../devui/MinioClientDevUIProcessor.java | 2 +- .../client/MinioBuildTimeConfiguration.java | 8 +-- .../minio/client/MinioClients.java | 35 ++++++------ .../client/MinioRuntimeConfiguration.java | 54 +++++++++---------- .../client/MiniosBuildTimeConfiguration.java | 33 ++++++------ .../client/MiniosRuntimeConfiguration.java | 34 ++++++------ .../client/WithMetricsHttpClientProducer.java | 6 +-- pom.xml | 2 +- 12 files changed, 113 insertions(+), 126 deletions(-) diff --git a/docs/modules/ROOT/pages/includes/attributes.adoc b/docs/modules/ROOT/pages/includes/attributes.adoc index de75b76..d628bc0 100644 --- a/docs/modules/ROOT/pages/includes/attributes.adoc +++ b/docs/modules/ROOT/pages/includes/attributes.adoc @@ -1,2 +1,2 @@ -:quarkus-version: 3.12.0 +:quarkus-version: 3.14.0 :quarkus-minio-version: 3.7.5 diff --git a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/DevServicesMinioProcessor.java b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/DevServicesMinioProcessor.java index ff4aab8..79caf1b 100644 --- a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/DevServicesMinioProcessor.java +++ b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/DevServicesMinioProcessor.java @@ -260,7 +260,7 @@ private static String formatPropertyName(String property, String minoClientName) } private MinioDevServiceCfg getConfiguration(MinioBuildTimeConfig cfg) { - MinioDevServicesBuildTimeConfig devServicesConfig = cfg.devservices; + MinioDevServicesBuildTimeConfig devServicesConfig = cfg.devservices(); return new MinioDevServiceCfg(devServicesConfig); } @@ -275,14 +275,14 @@ private static final class MinioDevServiceCfg { private final Map containerEnv; public MinioDevServiceCfg(MinioDevServicesBuildTimeConfig config) { - this.devServicesEnabled = config.enabled.orElse(true); - this.imageName = config.imageName; - this.fixedExposedPort = config.port.orElse(0); - this.shared = config.shared; - this.serviceName = config.serviceName; - this.accessKey = config.accessKey; - this.secretKey = config.secretKey; - this.containerEnv = config.containerEnv; + this.devServicesEnabled = config.enabled(); + this.imageName = config.imageName(); + this.fixedExposedPort = config.port(); + this.shared = config.shared(); + this.serviceName = config.serviceName(); + this.accessKey = config.accessKey(); + this.secretKey = config.secretKey(); + this.containerEnv = config.containerEnv(); } @Override diff --git a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioBuildTimeConfig.java b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioBuildTimeConfig.java index 0985df0..303aed4 100644 --- a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioBuildTimeConfig.java +++ b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioBuildTimeConfig.java @@ -1,15 +1,15 @@ package io.quarkiverse.minio.client.deployment.devservices; -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 = "minio", phase = ConfigPhase.BUILD_TIME) -public class MinioBuildTimeConfig { +@ConfigMapping(prefix = "quarkus.minio") +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +public interface MinioBuildTimeConfig { /** * Configuration for DevServices. DevServices allows Quarkus to automatically start Minio in dev and test mode. */ - @ConfigItem - public MinioDevServicesBuildTimeConfig devservices; + MinioDevServicesBuildTimeConfig devservices(); } diff --git a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioDevServicesBuildTimeConfig.java b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioDevServicesBuildTimeConfig.java index cfc3f46..c86dce3 100644 --- a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioDevServicesBuildTimeConfig.java +++ b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devservices/MinioDevServicesBuildTimeConfig.java @@ -5,31 +5,31 @@ 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 MinioDevServicesBuildTimeConfig { +public interface MinioDevServicesBuildTimeConfig { /** * Enable or disable Dev Services explicitly. Dev Services are automatically enabled unless {@code quarkus.minio.url} is * set. */ - @ConfigItem - public Optional enabled = Optional.empty(); + @WithDefault("true") + Boolean enabled(); /** * Optional fixed port the dev service will listen to. *

* If not defined, the port will be chosen randomly. */ - @ConfigItem - public Optional port; + @WithDefault("0") + Integer port(); /** * The Minio container image to use. */ - @ConfigItem(defaultValue = "minio/minio:RELEASE.2022-10-08T20-11-00Z") - public String imageName; + @WithDefault("minio/minio:RELEASE.2022-10-08T20-11-00Z") + String imageName(); /** * Indicates if the Minio server managed by Quarkus Dev Services is shared. @@ -42,8 +42,8 @@ public class MinioDevServicesBuildTimeConfig { *

* 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-minio} label attached to the started container. @@ -55,25 +55,24 @@ public class MinioDevServicesBuildTimeConfig { *

* This property is used when you need multiple shared Minio servers. */ - @ConfigItem(defaultValue = "minio") - public String serviceName; + @WithDefault("minio") + String serviceName(); /** * Minio root username access key. */ - @ConfigItem(defaultValue = "minioaccess") - public String accessKey; + @WithDefault("minioaccess") + String accessKey(); /** * Minio root username secret key. */ - @ConfigItem(defaultValue = "miniosecret") - public String secretKey; + @WithDefault("miniosecret") + String secretKey(); /** * Extra environment variables that will be passed to the devservice. */ - @ConfigItem @ConfigDocMapKey("environment-variable-name") - public Map containerEnv; + Map containerEnv(); } diff --git a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devui/MinioClientDevUIProcessor.java b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devui/MinioClientDevUIProcessor.java index 2cfaa0b..4a8c147 100644 --- a/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devui/MinioClientDevUIProcessor.java +++ b/minio-client/deployment/src/main/java/io/quarkiverse/minio/client/deployment/devui/MinioClientDevUIProcessor.java @@ -18,7 +18,7 @@ void createCard(BuildProducer cardProducer, MinioBuildTimeCon final CardPageBuildItem card = new CardPageBuildItem(); - card.addBuildTimeData("enabled", devServiceConfig.devservices.enabled.orElse(true)); + card.addBuildTimeData("enabled", devServiceConfig.devservices().enabled()); card.addPage(Page.externalPageBuilder("Min.io console") .icon("font-awesome-solid:signs-post") diff --git a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioBuildTimeConfiguration.java b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioBuildTimeConfiguration.java index 036f1d5..2ca5340 100644 --- a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioBuildTimeConfiguration.java +++ b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioBuildTimeConfiguration.java @@ -1,16 +1,16 @@ package io.quarkiverse.minio.client; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class MinioBuildTimeConfiguration { +public interface MinioBuildTimeConfiguration { /** * Should the extension provide a `MinioClient`. * If set to `false`, you will have to create the clients yourself, * but will still benefit the native compatibility work. */ - @ConfigItem(defaultValue = "true") - public boolean enabled; + @WithDefault("true") + boolean enabled(); } diff --git a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioClients.java b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioClients.java index 040a205..2711fd4 100644 --- a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioClients.java +++ b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioClients.java @@ -80,16 +80,16 @@ public MinioClient createMinioClient(String minioClientName) { MinioRuntimeConfiguration configuration = getAndVerifyConfiguration(minioClientName); MinioClient.Builder builder = MinioClient.builder(); - configuration.getPort() + configuration.port() .ifPresentOrElse( - port -> builder.endpoint(configuration.getUrl(), port, configuration.isTls()), + port -> builder.endpoint(configuration.url(), port, configuration.secure()), () -> builder.endpoint( - HttpUtils.getBaseUrl(configuration.getUrl()).newBuilder() - .scheme(configuration.isTls() ? "https" : "http").build())); + HttpUtils.getBaseUrl(configuration.url()).newBuilder() + .scheme(configuration.secure() ? "https" : "http").build())); - builder.credentials(configuration.getAccessKey(), configuration.getSecretKey()); - configuration.region.ifPresent(builder::region); - if (miniosRuntimeConfiguration.produceMetrics) { + builder.credentials(configuration.accessKey(), configuration.secretKey()); + configuration.region().ifPresent(builder::region); + if (miniosRuntimeConfiguration.produceMetrics()) { httpClientProducer.apply(minioClientName).ifPresent(builder::httpClient); } return builder.build(); @@ -99,16 +99,16 @@ public MinioAsyncClient createMinioAsyncClient(String minioClientName) { MinioRuntimeConfiguration configuration = getAndVerifyConfiguration(minioClientName); MinioAsyncClient.Builder builder = MinioAsyncClient.builder(); - configuration.getPort() + configuration.port() .ifPresentOrElse( - port -> builder.endpoint(configuration.getUrl(), port, configuration.isTls()), + port -> builder.endpoint(configuration.url(), port, configuration.secure()), () -> builder.endpoint( - HttpUtils.getBaseUrl(configuration.getUrl()).newBuilder() - .scheme(configuration.isTls() ? "https" : "http").build())); + HttpUtils.getBaseUrl(configuration.url()).newBuilder() + .scheme(configuration.secure() ? "https" : "http").build())); - builder.credentials(configuration.getAccessKey(), configuration.getSecretKey()); - configuration.region.ifPresent(builder::region); - if (miniosRuntimeConfiguration.produceMetrics) { + builder.credentials(configuration.accessKey(), configuration.secretKey()); + configuration.region().ifPresent(builder::region); + if (miniosRuntimeConfiguration.produceMetrics()) { httpClientProducer.apply(minioClientName).ifPresent(builder::httpClient); } return builder.build(); @@ -121,13 +121,12 @@ private MinioRuntimeConfiguration getAndVerifyConfiguration(String minioClientNa MinioRuntimeConfiguration configuration; if (MiniosBuildTimeConfiguration.isDefault(minioClientName)) { - configuration = miniosRuntimeConfiguration.minio(); + configuration = miniosRuntimeConfiguration.minio().get(); } else { - configuration = miniosRuntimeConfiguration.namedMinioClients().getOrDefault(minioClientName, - new MinioRuntimeConfiguration()); + configuration = miniosRuntimeConfiguration.namedMinioClients().get(minioClientName); } - if (IS_URL_SET.test(configuration.getUrl())) { + if (configuration == null || IS_URL_SET.test(configuration.url())) { String errorMessage; if (MiniosBuildTimeConfiguration.isDefault(minioClientName)) { errorMessage = "\"quarkus.minio.url\" is mandatory and must be a valid url"; diff --git a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioRuntimeConfiguration.java b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioRuntimeConfiguration.java index 9e4b886..d3a0d81 100644 --- a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioRuntimeConfiguration.java +++ b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MinioRuntimeConfiguration.java @@ -2,11 +2,17 @@ import java.util.Optional; +import org.eclipse.microprofile.config.spi.Converter; + import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.Converters; +import io.smallrye.config.WithConverter; +import io.smallrye.config.WithDefault; +@ConfigMapping(prefix = "quarkus.minio") @ConfigGroup -public class MinioRuntimeConfiguration { +public interface MinioRuntimeConfiguration { /** * The minio server URL. @@ -20,32 +26,31 @@ public class MinioRuntimeConfiguration { * * @asciidoclet */ - @ConfigItem - Optional url = Optional.empty(); + @WithConverter(EmptyConverter.class) + String url(); /** * The minio server access key * * @asciidoclet */ - @ConfigItem - Optional accessKey = Optional.empty(); + @WithConverter(EmptyConverter.class) + String accessKey(); /** * The minio server secret key * * @asciidoclet */ - @ConfigItem - Optional secretKey = Optional.empty(); + @WithConverter(EmptyConverter.class) + String secretKey(); /** * An optional bucket region * * @asciidoclet */ - @ConfigItem - Optional region = Optional.empty(); + Optional region(); /** * An optional port number. @@ -53,7 +58,7 @@ public class MinioRuntimeConfiguration { * * @asciidoclet */ - Optional port = Optional.empty(); + Optional port(); /** * An optional boolean to enable secure connection. @@ -61,27 +66,16 @@ public class MinioRuntimeConfiguration { * * @asciidoclet */ - @ConfigItem(defaultValue = "true") - boolean secure; - - public String getUrl() { - return url.orElse(""); - } - - String getAccessKey() { - return accessKey.orElse(""); - } + @WithDefault("true") + boolean secure(); - String getSecretKey() { - return secretKey.orElse(""); - } + class EmptyConverter implements org.eclipse.microprofile.config.spi.Converter { - Optional getPort() { - return port; - } + Converter delegate = Converters.newEmptyValueConverter(value -> value, ""); - Boolean isTls() { - return secure; + @Override + public String convert(String s) throws IllegalArgumentException, NullPointerException { + return delegate.convert(s); + } } - } diff --git a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosBuildTimeConfiguration.java b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosBuildTimeConfiguration.java index 2e3231b..cc78e2b 100644 --- a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosBuildTimeConfiguration.java +++ b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosBuildTimeConfiguration.java @@ -4,42 +4,41 @@ import java.util.Map; import java.util.stream.Collectors; -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.WithParentName; -@ConfigRoot(name = "minio", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) -public class MiniosBuildTimeConfiguration { +@ConfigMapping(prefix = "quarkus.minio") +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +public interface MiniosBuildTimeConfiguration { - public static final String DEFAULT_MINIOCLIENT_NAME = ""; + String DEFAULT_MINIOCLIENT_NAME = ""; /** * The default client */ - @ConfigItem(name = ConfigItem.PARENT) - public MinioBuildTimeConfiguration minio; + @WithParentName() + MinioBuildTimeConfiguration minio(); /** * Additional named client */ - @ConfigItem(name = ConfigItem.PARENT) - public Map namedMinioClients; + @WithParentName() + Map namedMinioClients(); - public Map getMinioClients() { + default Map getMinioClients() { var minioClients = new HashMap(); - if (minio == null) { - minio = new MinioBuildTimeConfiguration(); + if (minio() != null && minio().enabled()) { + minioClients.put(DEFAULT_MINIOCLIENT_NAME, minio()); } - if (minio.enabled) { - minioClients.put(DEFAULT_MINIOCLIENT_NAME, minio); - } - minioClients.putAll(namedMinioClients.entrySet().stream() - .filter(entry -> entry.getValue().enabled) + minioClients.putAll(namedMinioClients().entrySet().stream() + .filter(entry -> entry.getValue().enabled()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); return minioClients; } - public static boolean isDefault(String minioClientName) { + static boolean isDefault(String minioClientName) { return MiniosBuildTimeConfiguration.DEFAULT_MINIOCLIENT_NAME.equals(minioClientName); } } diff --git a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosRuntimeConfiguration.java b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosRuntimeConfiguration.java index 18090ae..29a29c8 100644 --- a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosRuntimeConfiguration.java +++ b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/MiniosRuntimeConfiguration.java @@ -1,13 +1,17 @@ package io.quarkiverse.minio.client; import java.util.Map; +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.WithParentName; -@ConfigRoot(name = "minio", phase = ConfigPhase.RUN_TIME) -public class MiniosRuntimeConfiguration { +@ConfigMapping(prefix = "quarkus.minio") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface MiniosRuntimeConfiguration { /** * If value is `true` (default) and the `io.quarkus.quarkus-micrometer` is present in the class path, @@ -17,32 +21,24 @@ public class MiniosRuntimeConfiguration { * * @asciidoclet */ - @ConfigItem(defaultValue = "true") - public boolean produceMetrics; + @WithDefault("true") + boolean produceMetrics(); /** * If minio clients are to produce metrics, then the uri tag will have a max of 100 values */ - @ConfigItem(defaultValue = "100") - public Integer maximumAllowedTag; + @WithDefault("100") + Integer maximumAllowedTag(); /** * The default client */ - @ConfigItem(name = ConfigItem.PARENT) - public MinioRuntimeConfiguration minio; + @WithParentName() + Optional minio(); /** * Additional named client */ - @ConfigItem(name = ConfigItem.PARENT) - public Map namedMinioClients; - - public MinioRuntimeConfiguration minio() { - return minio; - } - - public Map namedMinioClients() { - return namedMinioClients; - } + @WithParentName() + Map namedMinioClients(); } diff --git a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/WithMetricsHttpClientProducer.java b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/WithMetricsHttpClientProducer.java index 474b524..44af52b 100644 --- a/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/WithMetricsHttpClientProducer.java +++ b/minio-client/runtime/src/main/java/io/quarkiverse/minio/client/WithMetricsHttpClientProducer.java @@ -44,7 +44,7 @@ public WithMetricsHttpClientProducer(MeterRegistry meterRegistry, MiniosRuntimeC @Override public Optional apply(String minioClientName) { - if (!configuration.produceMetrics) { + if (!configuration.produceMetrics()) { return Optional.empty(); } return Optional.of(getHttpClientWithInterceptor(meterRegistry, minioClientName)); @@ -80,9 +80,9 @@ private OkHttpClient getHttpClientWithInterceptor(MeterRegistry meterRegistry, S private MeterFilter maximumAllowedTag(String metricName) { MeterFilter denyFilter = new OnlyOnceLoggingDenyMeterFilter(() -> String .format("Reached the maximum number (%s) of URI tags for '%s'. Are you using path parameters?", - configuration.maximumAllowedTag, metricName)); + configuration.maximumAllowedTag(), metricName)); - return MeterFilter.maximumAllowableTags(metricName, "uri", configuration.maximumAllowedTag, denyFilter); + return MeterFilter.maximumAllowableTags(metricName, "uri", configuration.maximumAllowedTag(), denyFilter); } /** diff --git a/pom.xml b/pom.xml index 5d55f9b..f1d58c5 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 3.13.0 3.3.1 ${version.surefire.plugin} - 3.13.0 + 3.14.0 8.5.11 3.26.3