aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-08-26 18:28:55 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-08-26 18:45:51 +0200
commitc2d7e44f722f3c14af036553fdc001408f47343a (patch)
treebd11dfa755ee93946cc5e5197fcadd271aad83f3 /sonar-application/src
parentcd5e247daf7096f3c62ada0c65d2657b954195c1 (diff)
downloadsonarqube-c2d7e44f722f3c14af036553fdc001408f47343a.tar.gz
sonarqube-c2d7e44f722f3c14af036553fdc001408f47343a.zip
Fix some quality flaws
Diffstat (limited to 'sonar-application/src')
-rw-r--r--sonar-application/src/main/java/org/sonar/application/App.java35
-rw-r--r--sonar-application/src/main/java/org/sonar/application/DefaultSettings.java2
-rw-r--r--sonar-application/src/main/java/org/sonar/application/JdbcSettings.java2
-rw-r--r--sonar-application/src/main/java/org/sonar/application/PropsBuilder.java2
-rw-r--r--sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java12
-rw-r--r--sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java8
-rw-r--r--sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java16
7 files changed, 35 insertions, 42 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 43c192bf716..784d75ef299 100644
--- a/sonar-application/src/main/java/org/sonar/application/App.java
+++ b/sonar-application/src/main/java/org/sonar/application/App.java
@@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
import org.sonar.process.JmxUtils;
import org.sonar.process.MinimumViableSystem;
import org.sonar.process.Monitor;
-import org.sonar.process.MonitoredProcess;
import org.sonar.process.ProcessLogging;
import org.sonar.process.ProcessMXBean;
import org.sonar.process.ProcessUtils;
@@ -35,8 +34,6 @@ import org.sonar.process.Props;
import org.sonar.search.SearchServer;
import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
import java.util.Properties;
/**
@@ -60,13 +57,13 @@ public class App implements ProcessMXBean {
monitor.start();
- File homeDir = props.fileOf("sonar.path.home");
- File tempDir = props.fileOf("sonar.path.temp");
+ File homeDir = props.nonNullValueAsFile("sonar.path.home");
+ File tempDir = props.nonNullValueAsFile("sonar.path.temp");
elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME);
elasticsearch
.setWorkDir(homeDir)
- .setJmxPort(props.intOf(DefaultSettings.SEARCH_JMX_PORT))
- .addJavaOpts(props.of(DefaultSettings.SEARCH_JAVA_OPTS))
+ .setJmxPort(props.valueAsInt(DefaultSettings.SEARCH_JMX_PORT))
+ .addJavaOpts(props.value(DefaultSettings.SEARCH_JAVA_OPTS))
.setTempDirectory(tempDir.getAbsoluteFile())
.setClassName("org.sonar.search.SearchServer")
.addProperties(props.rawProperties())
@@ -78,19 +75,19 @@ public class App implements ProcessMXBean {
logger.info("search server is up");
// do not yet start SQ in cluster mode. See SONAR-5483 & SONAR-5391
- if (StringUtils.isEmpty(props.of(DefaultSettings.CLUSTER_MASTER, null))) {
+ if (StringUtils.isEmpty(props.value(DefaultSettings.CLUSTER_MASTER))) {
server = new ProcessWrapper(JmxUtils.WEB_SERVER_NAME)
.setWorkDir(homeDir)
- .setJmxPort(props.intOf(DefaultSettings.WEB_JMX_PORT))
- .addJavaOpts(props.of(DefaultSettings.WEB_JAVA_OPTS))
+ .setJmxPort(props.valueAsInt(DefaultSettings.WEB_JMX_PORT))
+ .addJavaOpts(props.nonNullValue(DefaultSettings.WEB_JAVA_OPTS))
.setTempDirectory(tempDir.getAbsoluteFile())
- // required for logback tomcat valve
- .setLogDir(props.fileOf("sonar.path.logs"))
+ // required for logback tomcat valve
+ .setLogDir(props.nonNullValueAsFile("sonar.path.logs"))
.setClassName("org.sonar.server.app.WebServer")
.addProperties(props.rawProperties())
.addClasspath("./lib/common/*")
.addClasspath("./lib/server/*");
- String driverPath = props.of(JdbcSettings.PROPERTY_DRIVER_PATH);
+ String driverPath = props.value(JdbcSettings.PROPERTY_DRIVER_PATH);
if (driverPath != null) {
server.addClasspath(driverPath);
}
@@ -150,27 +147,23 @@ public class App implements ProcessMXBean {
}
public static void main(String[] args) {
-
new MinimumViableSystem().check();
CommandLineParser cli = new CommandLineParser();
Properties rawProperties = cli.parseArguments(args);
- Props props = null;
+ Props 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());
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
}
App app = new App();
-
try {
// start and wait for shutdown command
if (props.contains(SearchServer.ES_CLUSTER_INET)) {
- LoggerFactory.getLogger(App.class).info("SonarQube slave configured to join SonarQube master : {}", props.of(SearchServer.ES_CLUSTER_INET));
+ LoggerFactory.getLogger(App.class).info("SonarQube slave configured to join SonarQube master : {}", props.value(SearchServer.ES_CLUSTER_INET));
}
app.start(props);
} catch (InterruptedException e) {
diff --git a/sonar-application/src/main/java/org/sonar/application/DefaultSettings.java b/sonar-application/src/main/java/org/sonar/application/DefaultSettings.java
index e6d737487ac..0a85182cc21 100644
--- a/sonar-application/src/main/java/org/sonar/application/DefaultSettings.java
+++ b/sonar-application/src/main/java/org/sonar/application/DefaultSettings.java
@@ -55,7 +55,7 @@ class DefaultSettings {
// init ports
for (Map.Entry<String, Integer> entry : defaultPorts().entrySet()) {
String key = entry.getKey();
- int port = props.intOf(key, -1);
+ int port = props.valueAsInt(key, -1);
if (port == -1) {
// default port
props.set(key, String.valueOf((int) entry.getValue()));
diff --git a/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java b/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
index 300de2421dd..ff88ae0f9c0 100644
--- a/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
+++ b/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
@@ -50,7 +50,7 @@ public class JdbcSettings {
}
public void checkAndComplete(File homeDir, Props props) {
- String url = props.of(DefaultSettings.JDBC_URL);
+ String url = props.value(DefaultSettings.JDBC_URL);
Provider provider = driverProvider(url);
checkUrlParameters(provider, url);
String driverPath = driverPath(homeDir, provider);
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 0793a314163..f736658db7b 100644
--- a/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java
+++ b/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java
@@ -111,7 +111,7 @@ class PropsBuilder {
}
private File configureDir(Props props, String propKey, String defaultRelativePath) {
- String path = props.of(propKey, defaultRelativePath);
+ String path = props.value(propKey, defaultRelativePath);
File d = new File(path);
if (!d.isAbsolute()) {
d = new File(homeDir, path);
diff --git a/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java b/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
index 15892f29942..16a9cc9f1f8 100644
--- a/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
@@ -33,10 +33,10 @@ public class DefaultSettingsTest {
Props props = new Props(new Properties());
DefaultSettings.init(props);
- assertThat(props.of("sonar.search.javaOpts")).contains("-Xmx");
- assertThat(props.intOf("sonar.web.jmxPort")).isEqualTo(9003);
- assertThat(props.intOf("sonar.search.jmxPort")).isEqualTo(9002);
- assertThat(props.of("sonar.jdbc.username")).isEqualTo("sonar");
+ assertThat(props.value("sonar.search.javaOpts")).contains("-Xmx");
+ assertThat(props.valueAsInt("sonar.web.jmxPort")).isEqualTo(9003);
+ assertThat(props.valueAsInt("sonar.search.jmxPort")).isEqualTo(9002);
+ assertThat(props.value("sonar.jdbc.username")).isEqualTo("sonar");
}
@Test
@@ -46,7 +46,7 @@ public class DefaultSettingsTest {
Props props = new Props(p);
DefaultSettings.init(props);
- assertThat(props.of("sonar.jdbc.username")).isEqualTo("angela");
+ assertThat(props.value("sonar.jdbc.username")).isEqualTo("angela");
}
@Test
@@ -56,6 +56,6 @@ public class DefaultSettingsTest {
Props props = new Props(p);
DefaultSettings.init(props);
- assertThat(props.intOf("sonar.web.jmxPort")).isGreaterThan(0);
+ assertThat(props.valueAsInt("sonar.web.jmxPort")).isGreaterThan(0);
}
}
diff --git a/sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java b/sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java
index d7c44d3caf4..ad603c4e453 100644
--- a/sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java
@@ -89,7 +89,7 @@ public class JdbcSettingsTest {
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:oracle:thin:@localhost/XE");
settings.checkAndComplete(home, props);
- assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+ assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
}
@Test
@@ -98,7 +98,7 @@ public class JdbcSettingsTest {
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar");
settings.checkAndComplete(home, props);
- assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isNull();
+ assertThat(props.value(JdbcSettings.PROPERTY_DRIVER_PATH)).isNull();
}
@Test
@@ -110,7 +110,7 @@ public class JdbcSettingsTest {
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
settings.checkAndComplete(home, props);
- assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+ assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
}
@Test
@@ -122,7 +122,7 @@ public class JdbcSettingsTest {
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor");
settings.checkAndComplete(home, props);
- assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+ assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
}
@Test
diff --git a/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java b/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java
index 0c89e72dd97..be6387c212c 100644
--- a/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java
@@ -60,20 +60,20 @@ public class PropsBuilderTest {
Props props = new PropsBuilder(rawProperties, jdbcSettings, homeDir).build();
- assertThat(props.fileOf("sonar.path.logs")).isEqualTo(logsDir);
- assertThat(props.fileOf("sonar.path.home")).isEqualTo(homeDir);
+ assertThat(props.nonNullValueAsFile("sonar.path.logs")).isEqualTo(logsDir);
+ assertThat(props.nonNullValueAsFile("sonar.path.home")).isEqualTo(homeDir);
// create <HOME>/temp
- File tempDir = props.fileOf("sonar.path.temp");
+ File tempDir = props.nonNullValueAsFile("sonar.path.temp");
assertThat(tempDir).isDirectory().exists();
assertThat(tempDir.getName()).isEqualTo("temp");
assertThat(tempDir.getParentFile()).isEqualTo(homeDir);
- assertThat(props.of("foo")).isEqualTo("bar");
- assertThat(props.of("unknown")).isNull();
+ assertThat(props.value("foo")).isEqualTo("bar");
+ assertThat(props.value("unknown")).isNull();
// default properties
- assertThat(props.intOf("sonar.search.port")).isEqualTo(9001);
+ assertThat(props.valueAsInt("sonar.search.port")).isEqualTo(9001);
}
@Test
@@ -113,8 +113,8 @@ public class PropsBuilderTest {
rawProperties.setProperty("sonar.origin", "raw");
Props props = new PropsBuilder(rawProperties, jdbcSettings, homeDir).build();
- assertThat(props.of("sonar.jdbc.username")).isEqualTo("angela");
+ assertThat(props.value("sonar.jdbc.username")).isEqualTo("angela");
// command-line arguments override sonar.properties file
- assertThat(props.of("sonar.origin")).isEqualTo("raw");
+ assertThat(props.value("sonar.origin")).isEqualTo("raw");
}
}