From 1bd456166c1daad6080d78e19eab32c3fed2ee9f Mon Sep 17 00:00:00 2001 From: Ozan Gunalp Date: Mon, 17 Jun 2024 23:03:57 +0200 Subject: [PATCH] Dev services check property value existence with expression expansion Fixes #41128 --- .../quarkus/runtime/configuration/ConfigUtils.java | 14 ++++++++++++++ .../DevServicesElasticsearchProcessor.java | 2 +- .../dev/HibernateOrmDevServicesProcessor.java | 2 +- .../devservices/InfinispanDevServiceProcessor.java | 4 ++-- .../deployment/DevServicesKafkaProcessor.java | 4 ++-- .../deployment/DevServicesKubernetesProcessor.java | 2 +- .../deployment/DevServicesMongoProcessor.java | 2 +- .../keycloak/KeycloakDevServicesProcessor.java | 4 ++-- .../client/DevServicesRedisProcessor.java | 2 +- .../DevServicesApicurioRegistryProcessor.java | 8 ++++---- .../amqp/deployment/AmqpDevServicesProcessor.java | 6 +++--- .../mqtt/deployment/MqttDevServicesProcessor.java | 4 ++-- .../deployment/PulsarDevServicesProcessor.java | 4 ++-- .../deployment/RabbitMQDevServicesProcessor.java | 6 +++--- 14 files changed, 39 insertions(+), 25 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java index 6b80e16ba3dde..f91b643adf9e9 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java @@ -13,6 +13,7 @@ import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; +import org.eclipse.microprofile.config.ConfigValue; import org.eclipse.microprofile.config.spi.ConfigSource; import io.quarkus.runtime.LaunchMode; @@ -111,6 +112,19 @@ public static boolean isPropertyPresent(String propertyName) { return ConfigProvider.getConfig().unwrap(SmallRyeConfig.class).isPropertyPresent(propertyName); } + /** + * Checks if a property has non-empty value in the current Configuration. + *

+ * This method is similar to {@link #isPropertyPresent(String)}, but does not ignore expression expansion. + * + * @param propertyName the property name. + * @return true if the property is present or false otherwise. + */ + public static boolean isPropertyNonEmpty(String propertyName) { + ConfigValue configValue = ConfigProvider.getConfig().getConfigValue(propertyName); + return configValue.getValue() != null && !configValue.getValue().isEmpty(); + } + /** * Checks if any of the given properties is present in the current Configuration. *

diff --git a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java index 2308d705a40e9..3d401315a7965 100644 --- a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java +++ b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/DevServicesElasticsearchProcessor.java @@ -169,7 +169,7 @@ private DevServicesResultBuildItem.RunningDevService startElasticsearch( for (String hostsConfigProperty : buildItemConfig.hostsConfigProperties) { // Check if elasticsearch hosts property is set - if (ConfigUtils.isPropertyPresent(hostsConfigProperty)) { + if (ConfigUtils.isPropertyNonEmpty(hostsConfigProperty)) { log.debugf("Not starting Dev Services for Elasticsearch, the %s property is configured.", hostsConfigProperty); return null; } diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/dev/HibernateOrmDevServicesProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/dev/HibernateOrmDevServicesProcessor.java index a6c15baddbba7..86cc5d5ac9e9b 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/dev/HibernateOrmDevServicesProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/dev/HibernateOrmDevServicesProcessor.java @@ -46,7 +46,7 @@ void devServicesAutoGenerateByDefault(List s String databaseGenerationPropertyKey = HibernateOrmRuntimeConfig.puPropertyKey(entry.getKey(), "database.generation"); if (!ConfigUtils.isAnyPropertyPresent(propertyKeysIndicatingDataSourceConfigured) - && !ConfigUtils.isPropertyPresent(databaseGenerationPropertyKey)) { + && !ConfigUtils.isPropertyNonEmpty(databaseGenerationPropertyKey)) { devServicesAdditionalConfigProducer .produce(new DevServicesAdditionalConfigBuildItem(devServicesConfig -> { // Only force DB generation if the datasource is configured through dev services diff --git a/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java b/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java index 91d451d6e1fc0..3c99fc0c4aecf 100644 --- a/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java +++ b/extensions/infinispan-client/deployment/src/main/java/io/quarkus/infinispan/client/deployment/devservices/InfinispanDevServiceProcessor.java @@ -190,8 +190,8 @@ private RunningDevService startContainer(String clientName, DockerStatusBuildIte String configPrefix = getConfigPrefix(clientName); - boolean needToStart = !ConfigUtils.isPropertyPresent(configPrefix + "hosts") - && !ConfigUtils.isPropertyPresent(configPrefix + "server-list"); + boolean needToStart = !ConfigUtils.isPropertyNonEmpty(configPrefix + "hosts") + && !ConfigUtils.isPropertyNonEmpty(configPrefix + "server-list"); if (!needToStart) { log.debug("Not starting Dev Services for Infinispan as 'hosts', 'uri' or 'server-list' have been provided"); diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java index 312628e10b9ac..61d5e1846f993 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java @@ -202,7 +202,7 @@ private RunningDevService startKafka(DockerStatusBuildItem dockerStatusBuildItem } // Check if kafka.bootstrap.servers is set - if (ConfigUtils.isPropertyPresent(KAFKA_BOOTSTRAP_SERVERS)) { + if (ConfigUtils.isPropertyNonEmpty(KAFKA_BOOTSTRAP_SERVERS)) { log.debug("Not starting dev services for Kafka, the kafka.bootstrap.servers is configured."); return null; } @@ -295,7 +295,7 @@ private boolean hasKafkaChannelWithoutBootstrapServers() { && "smallrye-kafka".equals(config.getOptionalValue(name, String.class).orElse("ignored")); boolean isConfigured = false; if ((isIncoming || isOutgoing) && isKafka) { - isConfigured = ConfigUtils.isPropertyPresent(name.replace(".connector", ".bootstrap.servers")); + isConfigured = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".bootstrap.servers")); } if (!isConfigured) { return true; diff --git a/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java b/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java index ea20e633cfaa0..ed0cad0ca9c5a 100644 --- a/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java +++ b/extensions/kubernetes-client/deployment/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java @@ -169,7 +169,7 @@ private RunningDevService startKubernetes(DockerStatusBuildItem dockerStatusBuil } // Check if kubernetes-client.api-server-url is set - if (ConfigUtils.isPropertyPresent(KUBERNETES_CLIENT_MASTER_URL)) { + if (ConfigUtils.isPropertyNonEmpty(KUBERNETES_CLIENT_MASTER_URL)) { log.debug("Not starting Dev Services for Kubernetes, the " + KUBERNETES_CLIENT_MASTER_URL + " is configured."); return null; } diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java index a098970bf6d76..00dd9770f8f3f 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java @@ -162,7 +162,7 @@ private RunningDevService startMongo(DockerStatusBuildItem dockerStatusBuildItem String configPrefix = getConfigPrefix(connectionName); // TODO: do we need to check the hosts as well? - boolean needToStart = !ConfigUtils.isPropertyPresent(configPrefix + "connection-string"); + boolean needToStart = !ConfigUtils.isPropertyNonEmpty(configPrefix + "connection-string"); if (!needToStart) { // a connection string has been provided log.debug("Not starting devservices for " + (isDefault(connectionName) ? "default datasource" : connectionName) diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java index 4ab77d13b638a..5be9dbb80fb33 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java @@ -336,11 +336,11 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild LOG.debug("Not starting Dev Services for Keycloak as 'quarkus.oidc.tenant.enabled' is false"); return null; } - if (ConfigUtils.isPropertyPresent(AUTH_SERVER_URL_CONFIG_KEY)) { + if (ConfigUtils.isPropertyNonEmpty(AUTH_SERVER_URL_CONFIG_KEY)) { LOG.debug("Not starting Dev Services for Keycloak as 'quarkus.oidc.auth-server-url' has been provided"); return null; } - if (ConfigUtils.isPropertyPresent(PROVIDER_CONFIG_KEY)) { + if (ConfigUtils.isPropertyNonEmpty(PROVIDER_CONFIG_KEY)) { LOG.debug("Not starting Dev Services for Keycloak as 'quarkus.oidc.provider' has been provided"); return null; } diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/DevServicesRedisProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/DevServicesRedisProcessor.java index 5f7f898c18643..56055d9d5c9c4 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/DevServicesRedisProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/DevServicesRedisProcessor.java @@ -159,7 +159,7 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild String configPrefix = getConfigPrefix(name); - boolean needToStart = !ConfigUtils.isPropertyPresent(configPrefix + RedisConfig.HOSTS_CONFIG_NAME); + boolean needToStart = !ConfigUtils.isPropertyNonEmpty(configPrefix + RedisConfig.HOSTS_CONFIG_NAME); if (!needToStart) { log.debug("Not starting devservices for " + (RedisConfig.isDefaultClient(name) ? "default redis client" : name) + " as hosts have been provided"); diff --git a/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java b/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java index b80ab5eb86163..5441f7b3ac50f 100644 --- a/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java +++ b/extensions/schema-registry/devservice/deployment/src/main/java/io/quarkus/apicurio/registry/devservice/DevServicesApicurioRegistryProcessor.java @@ -146,12 +146,12 @@ private RunningDevService startApicurioRegistry(DockerStatusBuildItem dockerStat return null; } - if (ConfigUtils.isPropertyPresent(APICURIO_REGISTRY_URL_CONFIG)) { + if (ConfigUtils.isPropertyNonEmpty(APICURIO_REGISTRY_URL_CONFIG)) { log.debug("Not starting dev services for Apicurio Registry, " + APICURIO_REGISTRY_URL_CONFIG + " is configured."); return null; } - if (ConfigUtils.isPropertyPresent(CONFLUENT_SCHEMA_REGISTRY_URL_CONFIG)) { + if (ConfigUtils.isPropertyNonEmpty(CONFLUENT_SCHEMA_REGISTRY_URL_CONFIG)) { log.debug("Not starting dev services for Apicurio Registry, " + CONFLUENT_SCHEMA_REGISTRY_URL_CONFIG + " is configured."); return null; @@ -198,8 +198,8 @@ private boolean hasKafkaChannelWithoutRegistry() { && "smallrye-kafka".equals(config.getOptionalValue(name, String.class).orElse("ignored")); boolean isConfigured = false; if ((isIncoming || isOutgoing) && isKafka) { - isConfigured = ConfigUtils.isPropertyPresent(name.replace(".connector", ".apicurio.registry.url")) - || ConfigUtils.isPropertyPresent(name.replace(".connector", ".schema.registry.url")); + isConfigured = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".apicurio.registry.url")) + || ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".schema.registry.url")); } if (!isConfigured) { return true; diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java index 4797f9cf9907d..73b02c0e7492a 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/AmqpDevServicesProcessor.java @@ -163,7 +163,7 @@ private RunningDevService startAmqpBroker(DockerStatusBuildItem dockerStatusBuil } // Check if amqp.port or amqp.host are set - if (ConfigUtils.isPropertyPresent(AMQP_HOST_PROP) || ConfigUtils.isPropertyPresent(AMQP_PORT_PROP)) { + if (ConfigUtils.isPropertyNonEmpty(AMQP_HOST_PROP) || ConfigUtils.isPropertyNonEmpty(AMQP_PORT_PROP)) { log.debug("Not starting Dev Services for AMQP, the amqp.host and/or amqp.port are configured."); return null; } @@ -223,8 +223,8 @@ private boolean hasAmqpChannelWithoutHostAndPort() { if ((isIncoming || isOutgoing) && isConnector) { String connectorValue = config.getValue(name, String.class); boolean isAmqp = connectorValue.equalsIgnoreCase("smallrye-amqp"); - boolean hasHost = ConfigUtils.isPropertyPresent(name.replace(".connector", ".host")); - boolean hasPort = ConfigUtils.isPropertyPresent(name.replace(".connector", ".port")); + boolean hasHost = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".host")); + boolean hasPort = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".port")); isConfigured = isAmqp && (hasHost || hasPort); } diff --git a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java index 1fdc9fafa53cd..38f7a60150f23 100644 --- a/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-mqtt/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/mqtt/deployment/MqttDevServicesProcessor.java @@ -207,8 +207,8 @@ private boolean hasMqttChannelWithoutHostAndPort() { if ((isIncoming || isOutgoing) && isConnector) { String connectorValue = config.getValue(name, String.class); boolean isMqtt = connectorValue.equalsIgnoreCase("smallrye-mqtt"); - boolean hasHost = ConfigUtils.isPropertyPresent(name.replace(".connector", ".host")); - boolean hasPort = ConfigUtils.isPropertyPresent(name.replace(".connector", ".port")); + boolean hasHost = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".host")); + boolean hasPort = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".port")); isConfigured = isMqtt && (hasHost || hasPort); if (!isConfigured) { return true; diff --git a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java index f4d7dbc302eae..47b8a318ae0e0 100644 --- a/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java @@ -146,7 +146,7 @@ private RunningDevService startPulsarContainer(DockerStatusBuildItem dockerStatu } // Check if pulsar.serviceUrl is set - if (ConfigUtils.isPropertyPresent(PULSAR_CLIENT_SERVICE_URL)) { + if (ConfigUtils.isPropertyNonEmpty(PULSAR_CLIENT_SERVICE_URL)) { log.debug("Not starting Dev Services for Pulsar, the pulsar.serviceUrl is configured."); return null; } @@ -216,7 +216,7 @@ private boolean hasPulsarChannelWithoutHostAndPort() { if ((isIncoming || isOutgoing) && isConnector) { String connectorValue = config.getValue(name, String.class); boolean isPulsar = connectorValue.equalsIgnoreCase("smallrye-pulsar"); - boolean hasServiceUrl = ConfigUtils.isPropertyPresent(name.replace(".connector", ".serviceUrl")); + boolean hasServiceUrl = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".serviceUrl")); isConfigured = isPulsar && hasServiceUrl; } diff --git a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java index c396889739d77..89e0ba1f1c0a7 100644 --- a/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java +++ b/extensions/smallrye-reactive-messaging-rabbitmq/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/deployment/RabbitMQDevServicesProcessor.java @@ -159,7 +159,7 @@ private RunningDevService startRabbitMQBroker(DockerStatusBuildItem dockerStatus } // Check if rabbitmq-port or rabbitmq-host are set - if (ConfigUtils.isPropertyPresent(RABBITMQ_HOST_PROP) || ConfigUtils.isPropertyPresent(RABBITMQ_PORT_PROP)) { + if (ConfigUtils.isPropertyNonEmpty(RABBITMQ_HOST_PROP) || ConfigUtils.isPropertyNonEmpty(RABBITMQ_PORT_PROP)) { log.debug("Not starting Dev Services for RabbitMQ, the rabbitmq-host and/or rabbitmq-port are configured."); return null; } @@ -229,8 +229,8 @@ private boolean hasRabbitMQChannelWithoutHostAndPort() { if ((isIncoming || isOutgoing) && isConnector) { String connectorValue = config.getValue(name, String.class); boolean isRabbitMQ = connectorValue.equalsIgnoreCase("smallrye-rabbitmq"); - boolean hasHost = ConfigUtils.isPropertyPresent(name.replace(".connector", ".host")); - boolean hasPort = ConfigUtils.isPropertyPresent(name.replace(".connector", ".port")); + boolean hasHost = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".host")); + boolean hasPort = ConfigUtils.isPropertyNonEmpty(name.replace(".connector", ".port")); isConfigured = isRabbitMQ && (hasHost || hasPort); }