@@ -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(); |
@@ -164,7 +164,7 @@ public class ElasticSearch extends Process { | |||
try { | |||
Thread.sleep(100); | |||
} catch (InterruptedException e) { | |||
; | |||
} | |||
} | |||
} |
@@ -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() { |
@@ -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; | |||
} | |||
@@ -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; | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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 |
@@ -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()) { |