Skip to content

Commit

Permalink
Prevent restart when named datasources are quoted, or unquoted
Browse files Browse the repository at this point in the history
  • Loading branch information
Malandril committed Jul 6, 2024
1 parent 98b2c06 commit 461df38
Showing 1 changed file with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -50,7 +51,8 @@ public class DevServicesDatasourceProcessor {

// list of devservices properties we should not check for restart
// see issue #30390
private static final Set<String> EXCLUDED_PROPERTIES = Set.of("quarkus.datasource.devservices.enabled");
private static final Set<String> EXCLUDED_PROPERTIES = Set.of("quarkus.datasource.devservices.enabled",
"quarkus.datasource.devservices.reuse");

static volatile List<RunningDevService> databases;

Expand Down Expand Up @@ -79,8 +81,13 @@ DevServicesDatasourceResultBuildItem launchDatabases(
boolean restartRequired = false;
if (!restartRequired) {
for (Map.Entry<String, String> entry : cachedProperties.entrySet()) {
if (!Objects.equals(entry.getValue(),
trim(ConfigProvider.getConfig().getOptionalValue(entry.getKey(), String.class).orElse(null)))) {
String value = ConfigProvider.getConfig()
.getOptionalValue(entry.getKey(), String.class)
.orElse(null);
if (value == null) {
value = getValueWithOrWithoutQuotes(entry.getKey(), dataSourcesBuildTimeConfig.dataSources().keySet());
}
if (!Objects.equals(entry.getValue(), trim(value))) {
restartRequired = true;
break;
}
Expand Down Expand Up @@ -179,6 +186,34 @@ public void run() {
return new DevServicesDatasourceResultBuildItem(results);
}

/**
* Gets the value of the given key trying to quote the datasource if unquoted, and unquote it if quoted
*
* @param key key to get
* @param datasources datasources to try to quote and unqote
* @return the value or else otherwise
*/
private static String getValueWithOrWithoutQuotes(String key, Collection<String> datasources) {
for (String datasource : datasources) {
if (!DataSourceUtil.isDefault(datasource) && key.contains(datasource)) {
String quoted = ".\"" + datasource + "\".";
String unquoted = "." + datasource + ".";
if (key.contains(quoted)) {
String entryWithoutQuote = key.replace(quoted, unquoted);
return ConfigProvider.getConfig()
.getOptionalValue(entryWithoutQuote, String.class)
.orElse(null);
} else {
String entryWithQuotes = key.replace(unquoted, quoted);
return ConfigProvider.getConfig()
.getOptionalValue(entryWithQuotes, String.class)
.orElse(null);
}
}
}
return null;
}

private String trim(String optional) {
if (optional == null) {
return null;
Expand Down

0 comments on commit 461df38

Please sign in to comment.