From: Simon Brandhof Date: Thu, 26 Jul 2012 08:43:52 +0000 (+0200) Subject: Fix regression : trim values of conf/sonar.properties X-Git-Tag: 3.2~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cce3d90c338798f2ce6005f7f3d5d6e2fd808482;p=sonarqube.git Fix regression : trim values of conf/sonar.properties --- diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerSettings.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerSettings.java index 1958f421cfa..f5083b9e821 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/ServerSettings.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerSettings.java @@ -70,19 +70,16 @@ public class ServerSettings extends Settings { } private ServerSettings load(Map 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 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); } diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java index 6d18a5b18a2..ec8f71a67ac 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java @@ -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());