diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-08-14 09:44:44 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-08-14 09:55:19 +0200 |
commit | 46bd831271222c3a9ae5c51a77e1ad693f1cc3e9 (patch) | |
tree | 90dac8c9163db7eded304d49d4c0e948ec0177f7 /sonar-application | |
parent | efef547461ac486c9f7531204c7eceb95a16b7b9 (diff) | |
download | sonarqube-46bd831271222c3a9ae5c51a77e1ad693f1cc3e9.tar.gz sonarqube-46bd831271222c3a9ae5c51a77e1ad693f1cc3e9.zip |
fix quality flaws
Diffstat (limited to 'sonar-application')
3 files changed, 33 insertions, 15 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 fb8941d71b6..29fa2934b9c 100644 --- a/sonar-application/src/main/java/org/sonar/application/App.java +++ b/sonar-application/src/main/java/org/sonar/application/App.java @@ -33,6 +33,8 @@ import org.sonar.process.ProcessWrapper; import org.sonar.process.Props; import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; import java.util.Properties; /** @@ -45,7 +47,7 @@ public class App implements ProcessMXBean { private ProcessWrapper server; private boolean success = false; - public App() throws Exception { + public App() { JmxUtils.registerMBean(this, "SonarQube"); ProcessUtils.addSelfShutdownHook(this); } @@ -57,7 +59,8 @@ public class App implements ProcessMXBean { File homeDir = props.fileOf("sonar.path.home"); File tempDir = props.fileOf("sonar.path.temp"); - elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME) + elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME); + elasticsearch .setWorkDir(homeDir) .setJmxPort(props.intOf(DefaultSettings.SEARCH_JMX_PORT)) .addJavaOpts(props.of(DefaultSettings.SEARCH_JAVA_OPTS)) @@ -78,7 +81,7 @@ public class App implements ProcessMXBean { .setJmxPort(props.intOf(DefaultSettings.WEB_JMX_PORT)) .addJavaOpts(props.of(DefaultSettings.WEB_JAVA_OPTS)) .setTempDirectory(tempDir.getAbsoluteFile()) - // required for logback tomcat valve + // required for logback tomcat valve .setLogDir(props.fileOf("sonar.path.logs")) .setClassName("org.sonar.server.app.WebServer") .addProperties(props.rawProperties()) @@ -143,18 +146,32 @@ public class App implements ProcessMXBean { return success; } - public static void main(String[] args) throws Exception { + public static void main(String[] args) { + new MinimumViableSystem().check(); CommandLineParser cli = new CommandLineParser(); Properties rawProperties = cli.parseArguments(args); - Props props = new PropsBuilder(rawProperties, new JdbcSettings()).build(); - new ProcessLogging().configure(props, "/org/sonar/application/logback.xml"); - App app = new App(); + Props props = null; - // start and wait for shutdown command - app.start(props); + try { + props = new PropsBuilder(rawProperties, new JdbcSettings()).build(); + new ProcessLogging().configure(props, "/org/sonar/application/logback.xml"); + } catch (IOException e) { + throw new IllegalStateException(e.getMessage()); + } catch (URISyntaxException e) { + throw new IllegalStateException(e.getMessage()); + } - LoggerFactory.getLogger(App.class).info("stopped"); - System.exit(app.isSuccess() ? 0 : 1); + App app = new App(); + + try { + // start and wait for shutdown command + app.start(props); + } catch (InterruptedException e) { + LoggerFactory.getLogger(App.class).info("interrupted"); + } finally { + LoggerFactory.getLogger(App.class).info("stopped"); + System.exit(app.isSuccess() ? 0 : 1); + } } } diff --git a/sonar-application/src/main/java/org/sonar/application/CommandLineParser.java b/sonar-application/src/main/java/org/sonar/application/CommandLineParser.java index d2ee78831e0..80ecce12974 100644 --- a/sonar-application/src/main/java/org/sonar/application/CommandLineParser.java +++ b/sonar-application/src/main/java/org/sonar/application/CommandLineParser.java @@ -28,7 +28,7 @@ class CommandLineParser { /** * Build properties from command-line arguments and system properties */ - Properties parseArguments(String[] args) throws Exception { + Properties parseArguments(String[] args) { Properties props = argumentsToProperties(args); // complete with only the system properties that start with "sonar." diff --git a/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java b/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java index 82fe49d181f..0793a314163 100644 --- a/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java +++ b/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java @@ -27,6 +27,7 @@ import org.sonar.process.Props; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.net.URISyntaxException; import java.util.Properties; class PropsBuilder { @@ -41,7 +42,7 @@ class PropsBuilder { this.homeDir = homeDir; } - PropsBuilder(Properties rawProperties, JdbcSettings jdbcSettings) throws Exception { + PropsBuilder(Properties rawProperties, JdbcSettings jdbcSettings) throws URISyntaxException { this(rawProperties, jdbcSettings, detectHomeDir()); } @@ -49,7 +50,7 @@ class PropsBuilder { * Load optional conf/sonar.properties, interpolates environment variables and * initializes file system */ - Props build() throws Exception { + Props build() throws IOException { Properties p = loadPropertiesFile(homeDir); p.putAll(rawProperties); p.setProperty("sonar.path.home", homeDir.getAbsolutePath()); @@ -73,7 +74,7 @@ class PropsBuilder { return props; } - static File detectHomeDir() throws Exception { + static File detectHomeDir() throws URISyntaxException { File appJar = new File(PropsBuilder.class.getProtectionDomain().getCodeSource().getLocation().toURI()); return appJar.getParentFile().getParentFile(); } |