aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-10-04 14:46:47 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-10-05 14:19:56 +0200
commitefff409c5850df93e9fb4f6123fd2818353668b9 (patch)
treeafa9943bc239f9b5e206edc3b258ccd2c0bce101 /sonar-application
parentb6a96c82c5949a67a678a2835115bee17c895275 (diff)
downloadsonarqube-efff409c5850df93e9fb4f6123fd2818353668b9.tar.gz
sonarqube-efff409c5850df93e9fb4f6123fd2818353668b9.zip
Fix Quality flaws, including handling of InterruptedException
Diffstat (limited to 'sonar-application')
-rw-r--r--sonar-application/src/main/java/org/sonar/application/App.java4
-rw-r--r--sonar-application/src/main/java/org/sonar/application/PropsBuilder.java24
2 files changed, 15 insertions, 13 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 059e81c0feb..7ec6052e183 100644
--- a/sonar-application/src/main/java/org/sonar/application/App.java
+++ b/sonar-application/src/main/java/org/sonar/application/App.java
@@ -48,7 +48,7 @@ public class App implements Stoppable {
this.monitor = monitor;
}
- public void start(Props props) {
+ public void start(Props props) throws InterruptedException {
monitor.start(createCommands(props));
monitor.awaitTermination();
}
@@ -134,7 +134,7 @@ public class App implements Stoppable {
return FilenameUtils.concat(dir.getAbsolutePath(), "*");
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) throws InterruptedException {
CommandLineParser cli = new CommandLineParser();
Properties rawProperties = cli.parseArguments(args);
Props props = new PropsBuilder(rawProperties, new JdbcSettings()).build();
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 1e2d25778e2..6101a4e039b 100644
--- a/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java
+++ b/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java
@@ -27,7 +27,6 @@ import java.io.Reader;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
-import org.apache.commons.io.IOUtils;
import org.sonar.process.ConfigurationUtils;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
@@ -44,14 +43,14 @@ class PropsBuilder {
this.homeDir = homeDir;
}
- PropsBuilder(Properties rawProperties, JdbcSettings jdbcSettings) throws URISyntaxException {
+ PropsBuilder(Properties rawProperties, JdbcSettings jdbcSettings) {
this(rawProperties, jdbcSettings, detectHomeDir());
}
/**
* Load optional conf/sonar.properties, interpolates environment variables
*/
- Props build() throws IOException {
+ Props build() {
Properties p = loadPropertiesFile(homeDir);
p.putAll(rawProperties);
p.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
@@ -69,20 +68,23 @@ class PropsBuilder {
return props;
}
- static File detectHomeDir() throws URISyntaxException {
- File appJar = new File(PropsBuilder.class.getProtectionDomain().getCodeSource().getLocation().toURI());
- return appJar.getParentFile().getParentFile();
+ static File detectHomeDir() {
+ try {
+ File appJar = new File(PropsBuilder.class.getProtectionDomain().getCodeSource().getLocation().toURI());
+ return appJar.getParentFile().getParentFile();
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException("Cannot detect path of main jar file", e);
+ }
}
- private static Properties loadPropertiesFile(File homeDir) throws IOException {
+ private static Properties loadPropertiesFile(File homeDir) {
Properties p = new Properties();
File propsFile = new File(homeDir, "conf/sonar.properties");
if (propsFile.exists()) {
- Reader reader = new InputStreamReader(new FileInputStream(propsFile), StandardCharsets.UTF_8);
- try {
+ try (Reader reader = new InputStreamReader(new FileInputStream(propsFile), StandardCharsets.UTF_8)) {
p.load(reader);
- } finally {
- IOUtils.closeQuietly(reader);
+ } catch (IOException e) {
+ throw new IllegalStateException("Cannot open file " + propsFile, e);
}
}
return p;