diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-16 19:05:09 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-16 19:05:09 +0200 |
commit | 8ea5c540ef2c1c9e22e06b717758a0d2dcb647a5 (patch) | |
tree | 12623b8fcbf7404931ecb8cabc42806e9f328384 /sonar-core | |
parent | b86b183dfd764d432e353ce19a243ca321dd4f63 (diff) | |
download | sonarqube-8ea5c540ef2c1c9e22e06b717758a0d2dcb647a5.tar.gz sonarqube-8ea5c540ef2c1c9e22e06b717758a0d2dcb647a5.zip |
Replacement injection of ServletContext by Properties in Platform
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/config/ConfigurationUtils.java | 84 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/config/ConfigurationUtilsTest.java | 73 |
2 files changed, 0 insertions, 157 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/config/ConfigurationUtils.java b/sonar-core/src/main/java/org/sonar/core/config/ConfigurationUtils.java deleted file mode 100644 index d3875f78846..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/config/ConfigurationUtils.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.core.config; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.text.StrSubstitutor; - -import javax.annotation.WillClose; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.Map; -import java.util.Properties; - -/** - * @since 2.12 - */ -public final class ConfigurationUtils { - - private ConfigurationUtils() { - } - - public static void copyProperties(Properties from, Map<String, String> to) { - for (Map.Entry<Object, Object> entry : from.entrySet()) { - String key = (String) entry.getKey(); - to.put(key, entry.getValue().toString()); - } - } - - public static Properties openProperties(File file) throws IOException { - FileInputStream input = FileUtils.openInputStream(file); - return readInputStream(input); - } - - /** - * Note that the input stream is closed in this method. - */ - public static Properties readInputStream(@WillClose InputStream input) throws IOException { - try { - Properties p = new Properties(); - p.load(input); - return p; - - } finally { - IOUtils.closeQuietly(input); - } - } - - public static Properties interpolateEnvVariables(Properties properties) { - return interpolateVariables(properties, System.getenv()); - } - - public static Properties interpolateVariables(Properties properties, Map<String, String> variables) { - Properties result = new Properties(); - Enumeration keys = properties.keys(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - String value = (String) properties.get(key); - String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}"); - result.setProperty(key, interpolatedValue); - } - return result; - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/config/ConfigurationUtilsTest.java b/sonar-core/src/test/java/org/sonar/core/config/ConfigurationUtilsTest.java deleted file mode 100644 index 92452b2338e..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/config/ConfigurationUtilsTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.core.config; - -import com.google.common.collect.Maps; -import org.junit.Test; - -import java.util.Map; -import java.util.Properties; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class ConfigurationUtilsTest { - @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 = Maps.newHashMap(); - variables.put("SONAR_JDBC_URL", "jdbc:h2:mem"); - - Properties output = ConfigurationUtils.interpolateVariables(input, variables); - - assertThat(output.size(), is(3)); - assertThat(output.getProperty("hello"), is("world")); - assertThat(output.getProperty("url"), is("jdbc:h2:mem")); - assertThat(output.getProperty("do_not_change"), is("${SONAR_JDBC_URL}")); - - // input is not changed - assertThat(input.size(), is(3)); - assertThat(input.getProperty("hello"), is("world")); - assertThat(input.getProperty("url"), is("${env:SONAR_JDBC_URL}")); - assertThat(input.getProperty("do_not_change"), is("${SONAR_JDBC_URL}")); - } - - @Test - public void shouldCopyProperties() { - Properties input = new Properties(); - input.setProperty("hello", "world"); - input.setProperty("foo", "bar"); - Map<String, String> output = Maps.newHashMap(); - - ConfigurationUtils.copyProperties(input, output); - - assertThat(output.size(), is(2)); - assertThat(output.get("hello"), is("world")); - assertThat(output.get("foo"), is("bar")); - - // input is not changed - assertThat(input.size(), is(2)); - assertThat(input.getProperty("hello"), is("world")); - assertThat(input.getProperty("foo"), is("bar")); - } -} |