aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-02-20 10:35:52 +0100
committerSonarTech <sonartech@sonarsource.com>2020-02-22 20:46:10 +0100
commit00e018351cc66ed73ddb0042af06b1cb3e5da9b1 (patch)
treeb9821ca7d1cf8dd14d68e5b7b5321b45d810cccf /server
parentb1e40415a161a5ecdad7a321ac22a1b30710301f (diff)
downloadsonarqube-00e018351cc66ed73ddb0042af06b1cb3e5da9b1.tar.gz
sonarqube-00e018351cc66ed73ddb0042af06b1cb3e5da9b1.zip
SONAR-13113 deprecate environment variable interpolation mechanism in sonar.properties
Diffstat (limited to 'server')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java b/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
index c47bfaf144c..89c30cead79 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
@@ -29,10 +29,16 @@ import java.util.Map;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.text.StrSubstitutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.core.util.SettingFormatter;
import static org.sonar.process.FileUtils2.deleteQuietly;
public final class ConfigurationUtils {
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigurationUtils.class);
+ private static final String ENV_VAR_INTERPOLATION_PREFIX = "${env:";
+ private static final String ENV_VAR_INTERPOLATION_POSTFIX = "}";
private ConfigurationUtils() {
// Utility class
@@ -40,11 +46,17 @@ public final class ConfigurationUtils {
public static Properties interpolateVariables(Properties properties, Map<String, String> variables) {
Properties result = new Properties();
- Enumeration keys = properties.keys();
+ Enumeration<Object> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String value = (String) properties.get(key);
- String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}");
+ if (value.contains(ENV_VAR_INTERPOLATION_PREFIX)) {
+ String environmentVariableName = SettingFormatter.fromJavaPropertyToEnvVariable(key);
+ LOG.warn("Referencing environment variables in configuration is deprecated and will be removed in a future version of SonarQube. " +
+ "You should stop using '{}' in your configuration and use the '{}' environment variable instead.", value, environmentVariableName);
+ }
+
+ String interpolatedValue = StrSubstitutor.replace(value, variables, ENV_VAR_INTERPOLATION_PREFIX, ENV_VAR_INTERPOLATION_POSTFIX);
result.setProperty(key, interpolatedValue);
}
return result;