]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19960 Drop environment variable interpolation in sonar.properties
authorEric Giffon <eric.giffon@sonarsource.com>
Thu, 24 Aug 2023 12:52:43 +0000 (14:52 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 25 Aug 2023 20:02:41 +0000 (20:02 +0000)
server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java
server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
server/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java

index e0e642771413d03c0328f2ba0e23f7b3a774ebbe..c96f054417ddc9a66a1fdaabb3920f9bfdc08028 100644 (file)
@@ -34,7 +34,6 @@ import java.util.stream.Collectors;
 import org.slf4j.LoggerFactory;
 import org.sonar.core.extension.ServiceLoaderWrapper;
 import org.sonar.core.util.SettingFormatter;
-import org.sonar.process.ConfigurationUtils;
 import org.sonar.process.NetworkUtilsImpl;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
@@ -110,7 +109,6 @@ public class AppSettingsLoaderImpl implements AppSettingsLoader {
     loadPropertiesFromEnvironment(system, p, keysOverridableFromEnv);
     p.putAll(CommandLineParser.parseArguments(cliArguments));
     p.setProperty(PATH_HOME.getKey(), homeDir.getAbsolutePath());
-    p = ConfigurationUtils.interpolateVariables(p, system.getenv());
 
     // the difference between Properties and Props is that the latter
     // supports decryption of values, so it must be used when values
index f034ae71dd9983418e2f05c394e0585722c8381f..eeac5496d981347d4b878628633ba69e8490a834 100644 (file)
@@ -24,44 +24,17 @@ import java.io.FileInputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
-import java.util.Enumeration;
-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
   }
 
-  public static Properties interpolateVariables(Properties properties, Map<String, String> variables) {
-    Properties result = new Properties();
-    Enumeration<Object> keys = properties.keys();
-    while (keys.hasMoreElements()) {
-      String key = (String) keys.nextElement();
-      String value = (String) properties.get(key);
-      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;
-  }
-
   static Props loadPropsFromCommandLineArgs(String[] args) {
     if (args.length != 1) {
       throw new IllegalArgumentException("Only a single command-line argument is accepted " +
index e344711b6d63237b5a8230130ca2e807d3db7fef..f9a3bdf061e7f0121fcd263ca8540b25626d80c9 100644 (file)
@@ -21,9 +21,6 @@ package org.sonar.process;
 
 import java.io.File;
 import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
 import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
 import org.junit.Test;
@@ -38,29 +35,6 @@ public class ConfigurationUtilsTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  @Test
-  public void shouldInterpolateVariables() {
-    Properties input = new Properties();
-    input.setProperty("hello", "world");
-    input.setProperty("url", "${env:SONAR_JDBC_URL}");
-    input.setProperty("do_not_change", "${SONAR_JDBC_URL}");
-    Map<String, String> variables = new HashMap<>();
-    variables.put("SONAR_JDBC_URL", "jdbc:h2:mem");
-
-    Properties output = ConfigurationUtils.interpolateVariables(input, variables);
-
-    assertThat(output).hasSize(3);
-    assertThat(output.getProperty("hello")).isEqualTo("world");
-    assertThat(output.getProperty("url")).isEqualTo("jdbc:h2:mem");
-    assertThat(output.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}");
-
-    // input is not changed
-    assertThat(input).hasSize(3);
-    assertThat(input.getProperty("hello")).isEqualTo("world");
-    assertThat(input.getProperty("url")).isEqualTo("${env:SONAR_JDBC_URL}");
-    assertThat(input.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}");
-  }
-
   @Test
   public void loadPropsFromCommandLineArgs_missing_argument() {
     try {