From bfa32d5dc78ec0d2d9f3358f5035a10e5e94299b Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Tue, 18 Apr 2023 12:31:14 +0100 Subject: [PATCH] Only provide `quarkus.datasource.jdbc.url` from DevServices when Agroal is available --- .../DevServicesDatasourceProcessor.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java index 83af2b468d637..dacf44ae1c64f 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java @@ -1,5 +1,7 @@ package io.quarkus.datasource.deployment.devservices; +import static io.quarkus.bootstrap.classloading.QuarkusClassLoader.isClassPresentAtRuntime; + import java.io.Closeable; import java.util.ArrayList; import java.util.Collections; @@ -9,6 +11,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.function.BooleanSupplier; import java.util.stream.Collectors; import org.eclipse.microprofile.config.ConfigProvider; @@ -314,8 +317,17 @@ private RunningDevService startDevDb(String dbName, Map devDebProperties = new HashMap<>(); for (DevServicesDatasourceConfigurationHandlerBuildItem devDbConfigurationHandlerBuildItem : configHandlers) { - devDebProperties.putAll(devDbConfigurationHandlerBuildItem.getConfigProviderFunction() - .apply(dbName, datasource)); + Map properties = devDbConfigurationHandlerBuildItem.getConfigProviderFunction().apply(dbName, + datasource); + for (Map.Entry entry : properties.entrySet()) { + if (entry.getKey().endsWith("url")) { + if (AgroalExtensionAvailable.IS_AGROAL_EXTENSION_AVAILABLE) { + devDebProperties.put(entry.getKey(), entry.getValue()); + } + } else { + devDebProperties.put(entry.getKey(), entry.getValue()); + } + } } setDataSourceProperties(devDebProperties, dbName, "db-kind", defaultDbKind.get()); if (datasource.getUsername() != null) { @@ -361,4 +373,13 @@ private DevServicesDatasourceResultBuildItem.DbResult toDbResult(RunningDevServi } return new DevServicesDatasourceResultBuildItem.DbResult(devService.getName(), devService.getConfig()); } + + static class AgroalExtensionAvailable implements BooleanSupplier { + private static final boolean IS_AGROAL_EXTENSION_AVAILABLE = isClassPresentAtRuntime("io.quarkus.agroal.DataSource"); + + @Override + public boolean getAsBoolean() { + return IS_AGROAL_EXTENSION_AVAILABLE; + } + } }