]> source.dussan.org Git - sonarqube.git/commitdiff
Fix regression : trim values of conf/sonar.properties
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 26 Jul 2012 08:43:52 +0000 (10:43 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 26 Jul 2012 08:43:52 +0000 (10:43 +0200)
sonar-server/src/main/java/org/sonar/server/platform/ServerSettings.java
sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java

index 1958f421cfa4ed940b5dc4707d5140c1eae729a1..f5083b9e8210017a26601ab6d7a1f1775b8c1768 100644 (file)
@@ -70,19 +70,16 @@ public class ServerSettings extends Settings {
   }
 
   private ServerSettings load(Map<String, String> databaseSettings) {
-    properties.clear();
-    properties.put(CoreProperties.SONAR_HOME, sonarHome.getAbsolutePath());
-    properties.put(DEPLOY_DIR, deployDir.getAbsolutePath());
+    clear();
+    setProperty(CoreProperties.SONAR_HOME, sonarHome.getAbsolutePath());
+    setProperty(DEPLOY_DIR, deployDir.getAbsolutePath());
 
     // order is important : the last override the first
-    properties.putAll(databaseSettings);
+    addProperties(databaseSettings);
     loadPropertiesFile(sonarHome);
     addEnvironmentVariables();
     addSystemProperties();
 
-    // update deprecated configuration
-    ConfigurationUtils.copyToCommonsConfiguration(properties, deprecatedConfiguration);
-
     return this;
   }
 
@@ -91,13 +88,9 @@ public class ServerSettings extends Settings {
     if (!propertiesFile.isFile() || !propertiesFile.exists()) {
       throw new IllegalStateException("Properties file does not exist: " + propertiesFile);
     }
-
     try {
       Properties p = ConfigurationUtils.openProperties(propertiesFile);
-      p = ConfigurationUtils.interpolateEnvVariables(p);
-      for (Map.Entry<Object, Object> entry : p.entrySet()) {
-        properties.put(entry.getKey().toString(), entry.getValue().toString());
-      }
+      addProperties(ConfigurationUtils.interpolateEnvVariables(p));
     } catch (Exception e) {
       throw new IllegalStateException("Fail to load configuration file: " + propertiesFile, e);
     }
index 6d18a5b18a2e0144981121f8ea8392438c527832..ec8f71a67acd91c315421feb56d8479abc9abf2c 100644 (file)
@@ -35,7 +35,7 @@ public class ServerSettingsTest {
   private static File home = getHome();
 
   @Test
-  public void shouldLoadPropertiesFile() {
+  public void load_properties_file() {
     ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
 
     assertThat(settings.getString("hello")).isEqualTo("world");
@@ -50,7 +50,7 @@ public class ServerSettingsTest {
   }
 
   @Test(expected = IllegalStateException.class)
-  public void shouldFailIfPropertiesFileNotFound() {
+  public void fail_if_properties_file_is_not_found() {
     File sonarHome = new File("unknown/path");
     new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), sonarHome);
   }
@@ -76,6 +76,21 @@ public class ServerSettingsTest {
     assertThat(settings.getString("in_file")).isEqualTo("true");
   }
 
+  @Test
+  public void synchronize_deprecated_commons_configuration() {
+    BaseConfiguration deprecated = new BaseConfiguration();
+    ServerSettings settings = new ServerSettings(new PropertyDefinitions(), deprecated, new File("."), home);
+
+    assertThat(settings.getString("in_file")).isEqualTo("true");
+    assertThat(deprecated.getString("in_file")).isEqualTo("true");
+
+    assertThat(deprecated.getString("foo")).isNull();
+    settings.setProperty("foo", "bar");
+    assertThat(deprecated.getString("foo")).isEqualTo("bar");
+    settings.removeProperty("foo");
+    assertThat(deprecated.getString("foo")).isNull();
+  }
+
   private static File getHome() {
     try {
       return new File(ServerSettingsTest.class.getResource("/org/sonar/server/platform/ServerSettingsTest/").toURI());