aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-23 00:32:58 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-23 15:34:06 +0200
commit39ecd1902afc8922811f97524dfa77a86912508f (patch)
tree1ba2f7256d1e5e25e6b6031b609b570b7d7df1ae /sonar-application/src
parent5976c31b87f3e021a6dbf3f8cf71f886a16b0f28 (diff)
downloadsonarqube-39ecd1902afc8922811f97524dfa77a86912508f.tar.gz
sonarqube-39ecd1902afc8922811f97524dfa77a86912508f.zip
SONAR-4898 few improvements
Diffstat (limited to 'sonar-application/src')
-rw-r--r--sonar-application/src/main/java/org/sonar/application/Installation.java58
-rw-r--r--sonar-application/src/main/java/org/sonar/application/StartServer.java4
2 files changed, 24 insertions, 38 deletions
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 c6b0f2693fb..ce9c451e4b0 100644
--- a/sonar-application/src/main/java/org/sonar/application/Installation.java
+++ b/sonar-application/src/main/java/org/sonar/application/Installation.java
@@ -24,8 +24,8 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.process.ConfigurationUtils;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.Props;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -33,8 +33,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Properties;
public class Installation {
@@ -42,7 +40,7 @@ public class Installation {
private final File homeDir;
private final File tempDir, dataDir, logsDir, webDir;
- private final Map<String, String> props;
+ private final Props props;
Installation() throws URISyntaxException, IOException {
// home dir guessed with location of lib/sonar-application.jar
@@ -52,8 +50,8 @@ public class Installation {
props = initProps(homeDir);
// init file system
+ this.tempDir = initTempDir("sonar.path.temp", "temp");
this.dataDir = existingDir("sonar.path.data", "data");
- this.tempDir = freshDir("sonar.path.temp", "temp");
this.logsDir = existingDir("sonar.path.logs", "logs");
this.webDir = existingDir("sonar.path.web", "web");
@@ -63,7 +61,7 @@ public class Installation {
/**
* Load conf/sonar.properties
*/
- private static Map<String, String> initProps(File homeDir) throws IOException {
+ private static Props initProps(File homeDir) throws IOException {
Properties p = new Properties();
File propsFile = new File(homeDir, "conf/sonar.properties");
if (propsFile.exists()) {
@@ -78,27 +76,19 @@ public class Installation {
}
p.putAll(System.getenv());
p.putAll(System.getProperties());
- p = ConfigurationUtils.interpolateEnvVariables(p);
- Map<String, String> result = new HashMap<String, String>();
- for (Map.Entry<Object, Object> entry : p.entrySet()) {
- Object val = entry.getValue();
- if (val != null) {
- result.put(entry.getKey().toString(), val.toString());
- }
- }
- result.put("sonar.path.home", homeDir.getAbsolutePath());
- return result;
+ p.setProperty("sonar.path.home", homeDir.getAbsolutePath());
+ return new Props(p);
}
private void initElasticsearch() {
- String port = props.get("sonar.es.port");
- if (port == null || "".equals(port) || "0".equals(port)) {
- props.put("sonar.es.port", String.valueOf(NetworkUtils.freePort()));
+ int port = props.intOf("sonar.es.port", 0);
+ if (port <= 0) {
+ props.set("sonar.es.port", String.valueOf(NetworkUtils.freePort()));
}
- if (props.get("sonar.es.cluster.name") == null) {
- props.put("sonar.es.cluster.name", "sonarqube");
+ if (props.of("sonar.es.cluster.name") == null) {
+ props.set("sonar.es.cluster.name", "sonarqube");
}
- props.put("sonar.es.type", "TRANSPORT");
+ props.set("sonar.es.type", "TRANSPORT");
}
File homeDir() {
@@ -118,10 +108,15 @@ public class Installation {
return FilenameUtils.concat(dir.getAbsolutePath(), "*");
}
- private File freshDir(String propKey, String defaultRelativePath) throws IOException {
+ private File initTempDir(String propKey, String defaultRelativePath) throws IOException {
File dir = configuredDir(propKey, defaultRelativePath);
FileUtils.deleteQuietly(dir);
FileUtils.forceMkdir(dir);
+
+ // verify that temp directory is writable
+ File tempFile = File.createTempFile("check", "tmp", dir);
+ FileUtils.deleteQuietly(tempFile);
+
return dir;
}
@@ -142,25 +137,16 @@ public class Installation {
if (!d.isAbsolute()) {
d = new File(homeDir, path);
}
- props.put(propKey, d.getAbsolutePath());
+ props.set(propKey, d.getAbsolutePath());
return d;
}
- Map<String, String> props() {
- return props;
- }
-
@CheckForNull
String prop(String key, @Nullable String defaultValue) {
- String s = props.get(key);
- return s != null ? s : defaultValue;
+ return props.of(key, defaultValue);
}
- void logInfo(String message) {
- System.out.println(message);
- }
-
- void logError(String message) {
- System.err.println(message);
+ public Props props() {
+ return props;
}
}
diff --git a/sonar-application/src/main/java/org/sonar/application/StartServer.java b/sonar-application/src/main/java/org/sonar/application/StartServer.java
index 851c69070a1..e03235977d1 100644
--- a/sonar-application/src/main/java/org/sonar/application/StartServer.java
+++ b/sonar-application/src/main/java/org/sonar/application/StartServer.java
@@ -51,7 +51,7 @@ public class StartServer {
.addJavaOpts("-Djava.io.tmpdir=" + installation.tempDir().getAbsolutePath())
.addJavaOpts("-Dsonar.path.logs=" + installation.logsDir().getAbsolutePath())
.setClassName("org.sonar.search.ElasticSearch")
- .setProperties(installation.props())
+ .setProperties(installation.props().cryptedProperties())
.addClasspath(installation.starPath("lib/common"))
.addClasspath(installation.starPath("lib/search"))
.execute();
@@ -67,7 +67,7 @@ public class StartServer {
.addJavaOpts("-Djava.io.tmpdir=" + installation.tempDir().getAbsolutePath())
.addJavaOpts("-Dsonar.path.logs=" + installation.logsDir().getAbsolutePath())
.setClassName("org.sonar.server.app.ServerProcess")
- .setProperties(installation.props())
+ .setProperties(installation.props().cryptedProperties())
.addClasspath(installation.starPath("extensions/jdbc-driver/mysql"))
.addClasspath(installation.starPath("extensions/jdbc-driver/mssql"))
.addClasspath(installation.starPath("extensions/jdbc-driver/oracle"))