Skip to content

Commit

Permalink
Only provide quarkus.datasource.jdbc.url from DevServices when Agro…
Browse files Browse the repository at this point in the history
…al is available
  • Loading branch information
radcortez committed Apr 18, 2023
1 parent a8d5a80 commit bfa32d5
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -314,8 +317,17 @@ private RunningDevService startDevDb(String dbName,

Map<String, String> devDebProperties = new HashMap<>();
for (DevServicesDatasourceConfigurationHandlerBuildItem devDbConfigurationHandlerBuildItem : configHandlers) {
devDebProperties.putAll(devDbConfigurationHandlerBuildItem.getConfigProviderFunction()
.apply(dbName, datasource));
Map<String, String> properties = devDbConfigurationHandlerBuildItem.getConfigProviderFunction().apply(dbName,
datasource);
for (Map.Entry<String, String> 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) {
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit bfa32d5

Please sign in to comment.