diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-08-04 14:55:21 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-08-04 17:09:50 +0200 |
commit | 17a299b77abc930879e7c2b83664d826bf9f322c (patch) | |
tree | f48ea494da273664dad79192478b9087dbdbe393 /sonar-application/src/main/java/org/sonar/application | |
parent | 62aa23863d60b66aea4e027a1d8899cb10142560 (diff) | |
download | sonarqube-17a299b77abc930879e7c2b83664d826bf9f322c.tar.gz sonarqube-17a299b77abc930879e7c2b83664d826bf9f322c.zip |
SONAR-4898 fix support of properties that don't start with "sonar."
Diffstat (limited to 'sonar-application/src/main/java/org/sonar/application')
-rw-r--r-- | sonar-application/src/main/java/org/sonar/application/App.java | 7 | ||||
-rw-r--r-- | sonar-application/src/main/java/org/sonar/application/Installation.java | 43 |
2 files changed, 33 insertions, 17 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/App.java b/sonar-application/src/main/java/org/sonar/application/App.java index 54642355c3e..2920760f7e4 100644 --- a/sonar-application/src/main/java/org/sonar/application/App.java +++ b/sonar-application/src/main/java/org/sonar/application/App.java @@ -54,7 +54,7 @@ public class App implements ProcessMXBean { .addJavaOpts(String.format("-Djava.io.tmpdir=%s", installation.tempDir().getAbsolutePath())) .addJavaOpts(String.format("-Dsonar.path.logs=%s", installation.logsDir().getAbsolutePath())) .setClassName("org.sonar.search.SearchServer") - .setProperties(installation.props().encryptedProperties()) + .addProperties(installation.props().rawProperties()) .addClasspath(installation.starPath("lib/common")) .addClasspath(installation.starPath("lib/search")); if (elasticsearch.execute()) { @@ -67,9 +67,8 @@ public class App implements ProcessMXBean { .setJmxPort(Integer.parseInt(installation.prop(DefaultSettings.WEB_JMX_PORT_KEY))) .addJavaOpts(installation.prop(DefaultSettings.WEB_JAVA_OPTS_KEY)) .addJavaOpts(String.format("-Djava.io.tmpdir=%s", installation.tempDir().getAbsolutePath())) - .addJavaOpts(String.format("-Dsonar.path.logs=%s", installation.logsDir().getAbsolutePath())) .setClassName("org.sonar.server.app.WebServer") - .setProperties(installation.props().encryptedProperties()) + .addProperties(installation.props().rawProperties()) .addClasspath(installation.starPath("extensions/jdbc-driver/mysql")) .addClasspath(installation.starPath("extensions/jdbc-driver/mssql")) .addClasspath(installation.starPath("extensions/jdbc-driver/oracle")) @@ -123,7 +122,7 @@ public class App implements ProcessMXBean { } public static void main(String[] args) throws Exception { - Installation installation = new Installation(); + Installation installation = Installation.parseArguments(args); new AppLogging().configure(installation); App app = new App(installation); diff --git a/sonar-application/src/main/java/org/sonar/application/Installation.java b/sonar-application/src/main/java/org/sonar/application/Installation.java index eccc7fefd50..8dafc704400 100644 --- a/sonar-application/src/main/java/org/sonar/application/Installation.java +++ b/sonar-application/src/main/java/org/sonar/application/Installation.java @@ -22,6 +22,8 @@ package org.sonar.application; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.sonar.process.ConfigurationUtils; import org.sonar.process.MinimumViableEnvironment; import org.sonar.process.Props; @@ -38,23 +40,19 @@ public class Installation { private File homeDir, tempDir, logsDir; private Props props; - public Installation() throws URISyntaxException, IOException { - Properties systemProperties = new Properties(); - systemProperties.putAll(System.getenv()); - systemProperties.putAll(System.getProperties()); - - init(new MinimumViableEnvironment(), detectHomeDir(), systemProperties); + public Installation(Properties rawProperties) throws Exception { + init(new MinimumViableEnvironment(), detectHomeDir(), rawProperties); } - Installation(MinimumViableEnvironment minimumViableEnvironment, File homeDir, Properties systemProperties) throws URISyntaxException, IOException { - init(minimumViableEnvironment, homeDir, systemProperties); + Installation(Properties rawProperties, MinimumViableEnvironment mve, File homeDir) throws Exception { + init(mve, homeDir, rawProperties); } - void init(MinimumViableEnvironment minViableEnv, File homeDir, Properties systemProperties) throws URISyntaxException, IOException { + void init(MinimumViableEnvironment minViableEnv, File homeDir, Properties rawProperties) throws URISyntaxException, IOException { minViableEnv.check(); this.homeDir = homeDir; - props = initProps(homeDir, systemProperties); + props = initProps(homeDir, rawProperties); DefaultSettings.initDefaults(props); // init file system @@ -70,9 +68,9 @@ public class Installation { } /** - * Load conf/sonar.properties + * Load optional conf/sonar.properties and interpolates environment variables */ - private static Props initProps(File homeDir, Properties systemProperties) throws IOException { + private static Props initProps(File homeDir, Properties rawProperties) throws IOException { Properties p = new Properties(); File propsFile = new File(homeDir, "conf/sonar.properties"); if (propsFile.exists()) { @@ -83,8 +81,9 @@ public class Installation { IOUtils.closeQuietly(reader); } } - p.putAll(systemProperties); + p.putAll(rawProperties); p.setProperty("sonar.path.home", homeDir.getAbsolutePath()); + p = ConfigurationUtils.interpolateVariables(p, System.getenv()); return new Props(p); } @@ -148,4 +147,22 @@ public class Installation { public Props props() { return props; } + + static Installation parseArguments(String[] args) throws Exception { + return new Installation(argumentsToProperties(args)); + } + + static Properties argumentsToProperties(String[] args) { + Properties props = new Properties(); + for (String arg : args) { + if (!arg.startsWith("-D") || !arg.contains("=")) { + throw new IllegalArgumentException(String.format( + "Command-line argument must start with -D, for example -Dsonar.jdbc.username=sonar. Got: %s", arg)); + } + String key = StringUtils.substringBefore(arg, "=").substring(2); + String value = StringUtils.substringAfter(arg, "="); + props.setProperty(key, value); + } + return props; + } } |