}
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;
}
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);
}
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");
}
@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);
}
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());