diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-26 10:43:52 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-26 10:43:52 +0200 |
commit | cce3d90c338798f2ce6005f7f3d5d6e2fd808482 (patch) | |
tree | 4f4a36f64d6438586a095a04db7e3f4c1cc940fb | |
parent | d33e0b2fb918d5a9ffd680eb826bd0b54b601c05 (diff) | |
download | sonarqube-cce3d90c338798f2ce6005f7f3d5d6e2fd808482.tar.gz sonarqube-cce3d90c338798f2ce6005f7f3d5d6e2fd808482.zip |
Fix regression : trim values of conf/sonar.properties
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/platform/ServerSettings.java | 17 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java | 19 |
2 files changed, 22 insertions, 14 deletions
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<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); } 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()); |