aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-08-14 09:44:44 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-08-14 09:55:19 +0200
commit46bd831271222c3a9ae5c51a77e1ad693f1cc3e9 (patch)
tree90dac8c9163db7eded304d49d4c0e948ec0177f7
parentefef547461ac486c9f7531204c7eceb95a16b7b9 (diff)
downloadsonarqube-46bd831271222c3a9ae5c51a77e1ad693f1cc3e9.tar.gz
sonarqube-46bd831271222c3a9ae5c51a77e1ad693f1cc3e9.zip
fix quality flaws
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java19
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchServer.java8
-rw-r--r--sonar-application/src/main/java/org/sonar/application/App.java39
-rw-r--r--sonar-application/src/main/java/org/sonar/application/CommandLineParser.java2
-rw-r--r--sonar-application/src/main/java/org/sonar/application/PropsBuilder.java7
5 files changed, 47 insertions, 28 deletions
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
index 49ed4618ed0..627d3f45734 100644
--- a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
+++ b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
@@ -30,6 +30,8 @@ import java.util.concurrent.TimeUnit;
public abstract class MonitoredProcess implements ProcessMXBean {
+ private final static Logger LOGGER = LoggerFactory.getLogger(MonitoredProcess.class);
+
public static final String NAME_PROPERTY = "pName";
private static final long AUTOKILL_TIMEOUT_MS = 30000L;
private static final long AUTOKILL_CHECK_DELAY_MS = 2000L;
@@ -47,11 +49,11 @@ public abstract class MonitoredProcess implements ProcessMXBean {
private ScheduledExecutorService monitor;
private final boolean isMonitored;
- protected MonitoredProcess(Props props) throws Exception {
+ protected MonitoredProcess(Props props) {
this(props, false);
}
- protected MonitoredProcess(Props props, boolean monitor) throws Exception {
+ protected MonitoredProcess(Props props, boolean monitor) {
this.isMonitored = monitor;
this.props = props;
this.name = props.of(NAME_PROPERTY);
@@ -87,12 +89,10 @@ public abstract class MonitoredProcess implements ProcessMXBean {
if (monitor != null) {
throw new IllegalStateException("Already started");
}
-
- Logger logger = LoggerFactory.getLogger(getClass());
- logger.debug("Process[{}] starting", name);
+ LOGGER.debug("Process[{}] starting", name);
scheduleAutokill(this.isMonitored);
doStart();
- logger.debug("Process[{}] started", name);
+ LOGGER.debug("Process[{}] started", name);
}
/**
@@ -127,8 +127,7 @@ public abstract class MonitoredProcess implements ProcessMXBean {
@Override
public final void terminate() {
if (monitor != null) {
- Logger logger = LoggerFactory.getLogger(getClass());
- logger.debug("Process[{}] terminating", name);
+ LOGGER.debug("Process[{}] terminating", name);
monitor.shutdownNow();
monitor = null;
if (pingTask != null) {
@@ -138,10 +137,10 @@ public abstract class MonitoredProcess implements ProcessMXBean {
try {
doTerminate();
} catch (Exception e) {
- LoggerFactory.getLogger(getClass()).error("Fail to terminate " + name, e);
+ LOGGER.error("Fail to terminate " + name, e);
// do not propagate exception
}
- logger.debug("Process[{}] terminated", name);
+ LOGGER.debug("Process[{}] terminated", name);
terminated = true;
}
}
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
index b0b78ff8cb8..79f514643e8 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
@@ -53,13 +53,15 @@ public class SearchServer extends MonitoredProcess {
private Node node;
- public SearchServer(Props props, boolean monitored, boolean blocking) throws Exception {
+ public SearchServer(final Props props, boolean monitored, boolean blocking) {
super(props, monitored);
+
this.isBlocking = blocking;
new MinimumViableSystem().check();
- if (StringUtils.isNotEmpty(props.of(ES_CLUSTER_INET, null))) {
- Collections.addAll(nodes, props.of(ES_CLUSTER_INET).split(","));
+ String ESNodesInets = props.of(ES_CLUSTER_INET);
+ if (StringUtils.isNotEmpty(ESNodesInets)) {
+ Collections.addAll(nodes, ESNodesInets.split(","));
}
}
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();
}