aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-23 14:42:58 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-23 15:34:08 +0200
commit9c29050c2d83a4cf28bda17c9ba08c420338d4e6 (patch)
tree54f29e122cbb080698f7dd65148876df72930b1c
parent5932476ce437e867b0d295c9ebd522219d76b924 (diff)
downloadsonarqube-9c29050c2d83a4cf28bda17c9ba08c420338d4e6.tar.gz
sonarqube-9c29050c2d83a4cf28bda17c9ba08c420338d4e6.zip
SONAR-4898 improve management of sonar.path.* properties
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java4
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java2
-rw-r--r--server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java1
-rw-r--r--server/sonar-server-app/src/main/java/org/sonar/server/app/EmbeddedTomcat.java27
-rw-r--r--server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java53
-rw-r--r--server/sonar-server-app/src/main/java/org/sonar/server/app/Logging.java11
-rw-r--r--server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java3
-rw-r--r--server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java8
8 files changed, 29 insertions, 80 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java b/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
index ff617e4ab67..91caca0a2e7 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
@@ -31,10 +31,6 @@ public final class ConfigurationUtils {
// Utility class
}
- public static Properties interpolateEnvVariables(Properties properties) {
- return interpolateVariables(properties, System.getenv());
- }
-
public static Properties interpolateVariables(Properties properties, Map<String, String> variables) {
Properties result = new Properties();
Enumeration keys = properties.keys();
diff --git a/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java b/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java
index dc1aae83833..83b11cbc08c 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java
@@ -164,7 +164,7 @@ public class ElasticSearch extends Process {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
- ;
+
}
}
}
diff --git a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java
index 62950bee734..2eedf391b80 100644
--- a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java
+++ b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java
@@ -85,6 +85,7 @@ public class ElasticSearchTest {
properties.setProperty(Process.NAME_PROPERTY, "ES");
properties.setProperty("sonar.path.data", tempDirectory.getAbsolutePath());
properties.setProperty(ElasticSearch.ES_PORT_PROPERTY, Integer.toString(freeESPort));
+ properties.setProperty(ElasticSearch.ES_CLUSTER_PROPERTY, "sonarqube");
elasticSearch = new ElasticSearch(new Props(properties));
new Thread(new Runnable() {
diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/EmbeddedTomcat.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
index 971414b10dd..50239fe282d 100644
--- a/server/sonar-server-app/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
+++ b/server/sonar-server-app/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
@@ -23,20 +23,19 @@ import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.FileUtils;
+import org.sonar.process.Props;
import java.io.File;
class EmbeddedTomcat {
- public static final String TEMP_RELATIVE_PATH = "temp/tomcat";
-
- private final Env env;
+ private final Props props;
private Tomcat tomcat = null;
private Thread hook = null;
private boolean stopping = false, ready = false;
- EmbeddedTomcat(Env env) {
- this.env = env;
+ EmbeddedTomcat(Props props) {
+ this.props = props;
}
void start() {
@@ -54,16 +53,17 @@ class EmbeddedTomcat {
tomcat = new Tomcat();
// Initialize directories
- String basedir = env.freshDir(TEMP_RELATIVE_PATH).getCanonicalPath();
+ File tomcatDir = tomcatBasedir();
+ String basedir = tomcatDir.getAbsolutePath();
tomcat.setBaseDir(basedir);
tomcat.getHost().setAppBase(basedir);
tomcat.getHost().setAutoDeploy(false);
tomcat.getHost().setCreateDirs(false);
tomcat.getHost().setDeployOnStartup(true);
- Logging.configure(tomcat, env, env.props());
- Connectors.configure(tomcat, env.props());
- Webapp.configure(tomcat, env, env.props());
+ Logging.configure(tomcat, props);
+ Connectors.configure(tomcat, props);
+ Webapp.configure(tomcat, props);
tomcat.start();
addShutdownHook();
ready = true;
@@ -75,6 +75,10 @@ class EmbeddedTomcat {
stop();
}
+ private File tomcatBasedir() {
+ return new File(props.of("sonar.path.temp"), "tomcat");
+ }
+
private void addShutdownHook() {
hook = new Thread() {
@Override
@@ -101,8 +105,7 @@ class EmbeddedTomcat {
tomcat = null;
stopping = false;
ready = false;
- File tempDir = env.file(TEMP_RELATIVE_PATH);
- FileUtils.deleteQuietly(tempDir);
+ FileUtils.deleteQuietly(tomcatBasedir());
} catch (LifecycleException e) {
throw new IllegalStateException("Fail to stop web server", e);
@@ -116,7 +119,7 @@ class EmbeddedTomcat {
}
}
- boolean isReady( ){
+ boolean isReady() {
return ready;
}
diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java
deleted file mode 100644
index a9b9f7c278c..00000000000
--- a/server/sonar-server-app/src/main/java/org/sonar/server/app/Env.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.app;
-
-import org.apache.commons.io.FileUtils;
-import org.sonar.process.Props;
-
-import java.io.File;
-
-class Env {
-
- private final Props props;
-
- Env(Props props) {
- this.props = props;
- }
-
- Props props() {
- return props;
- }
-
- File rootDir() {
- return new File(props.of("sonar.path.home"));
- }
-
- File file(String relativePath) {
- return new File(rootDir(), relativePath);
- }
-
- File freshDir(String relativePath) {
- File dir = new File(rootDir(), relativePath);
- FileUtils.deleteQuietly(dir);
- dir.mkdirs();
- return dir;
- }
-}
diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/Logging.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/Logging.java
index 45c4afefeb7..a4d1aaeec28 100644
--- a/server/sonar-server-app/src/main/java/org/sonar/server/app/Logging.java
+++ b/server/sonar-server-app/src/main/java/org/sonar/server/app/Logging.java
@@ -28,11 +28,12 @@ import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.sonar.process.Props;
+import java.io.File;
import java.util.logging.LogManager;
class Logging {
- static final String ACCESS_RELATIVE_PATH = "web/WEB-INF/config/logback-access.xml";
+ static final String ACCESS_RELATIVE_PATH = "WEB-INF/config/logback-access.xml";
static final String PROPERTY_ENABLE_ACCESS_LOGS = "sonar.web.accessLogs.enable";
static void init() {
@@ -41,21 +42,21 @@ class Logging {
SLF4JBridgeHandler.install();
}
- static void configure(Tomcat tomcat, Env env, Props props) {
+ static void configure(Tomcat tomcat, Props props) {
tomcat.setSilent(false);
tomcat.getService().addLifecycleListener(new LifecycleLogger(console()));
- configureLogbackAccess(tomcat, env, props);
+ configureLogbackAccess(tomcat, props);
}
static Logger console() {
return LoggerFactory.getLogger("console");
}
- private static void configureLogbackAccess(Tomcat tomcat, Env env, Props props) {
+ private static void configureLogbackAccess(Tomcat tomcat, Props props) {
if (props.booleanOf(PROPERTY_ENABLE_ACCESS_LOGS, true)) {
LogbackValve valve = new LogbackValve();
valve.setQuiet(true);
- valve.setFilename(env.file(ACCESS_RELATIVE_PATH).getAbsolutePath());
+ valve.setFilename(new File(props.of("sonar.path.web"), ACCESS_RELATIVE_PATH).getAbsolutePath());
tomcat.getHost().getPipeline().addValve(valve);
}
}
diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java
index ee303b8313b..35c9aba1e8f 100644
--- a/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java
+++ b/server/sonar-server-app/src/main/java/org/sonar/server/app/ServerProcess.java
@@ -26,8 +26,7 @@ public class ServerProcess extends org.sonar.process.Process {
public ServerProcess(String[] args) {
super(args);
Logging.init();
- Env env = new Env(props);
- this.tomcat = new EmbeddedTomcat(env);
+ this.tomcat = new EmbeddedTomcat(props);
}
@Override
diff --git a/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java b/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java
index 9f98faf2ec6..b3846901994 100644
--- a/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java
+++ b/server/sonar-server-app/src/main/java/org/sonar/server/app/Webapp.java
@@ -24,6 +24,7 @@ import org.apache.catalina.startup.Tomcat;
import org.slf4j.LoggerFactory;
import org.sonar.process.Props;
+import java.io.File;
import java.util.Map;
class Webapp {
@@ -34,10 +35,11 @@ class Webapp {
private static final String PROPERTY_LOG_PROFILING_LEVEL = "sonar.log.profilingLevel";
private static final String PROPERTY_LOG_CONSOLE = "sonar.log.console";
- static void configure(Tomcat tomcat, Env env, Props props) {
+ static void configure(Tomcat tomcat, Props props) {
try {
- Context context = tomcat.addWebapp(getContextPath(props), env.file("web").getAbsolutePath());
- context.setConfigFile(env.file("web/META-INF/context.xml").toURI().toURL());
+ String webDir = props.of("sonar.path.web");
+ Context context = tomcat.addWebapp(getContextPath(props), webDir);
+ context.setConfigFile(new File(webDir, "META-INF/context.xml").toURI().toURL());
context.addParameter(PROPERTY_LOG_PROFILING_LEVEL, props.of(PROPERTY_LOG_PROFILING_LEVEL, "NONE"));
context.addParameter(PROPERTY_LOG_CONSOLE, props.of(PROPERTY_LOG_CONSOLE, "false"));
for (Map.Entry<Object, Object> entry : props.cryptedProperties().entrySet()) {