aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-application')
-rw-r--r--sonar-application/assembly.xml50
-rw-r--r--sonar-application/pom.xml67
-rw-r--r--sonar-application/src/main/assembly/conf/wrapper.conf5
-rw-r--r--sonar-application/src/main/java/org/sonar/application/Connectors.java161
-rw-r--r--sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java133
-rw-r--r--sonar-application/src/main/java/org/sonar/application/Logging.java80
-rw-r--r--sonar-application/src/main/java/org/sonar/application/NullJarScanner.java36
-rw-r--r--sonar-application/src/main/java/org/sonar/application/StartServer.java51
-rw-r--r--sonar-application/src/main/java/org/sonar/application/Webapp.java69
-rw-r--r--sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java340
-rw-r--r--sonar-application/src/test/java/org/sonar/application/LoggingTest.java91
-rw-r--r--sonar-application/src/test/java/org/sonar/application/NullJarScannerTest.java43
-rw-r--r--sonar-application/src/test/java/org/sonar/application/StartServerTest.java151
-rw-r--r--sonar-application/src/test/java/org/sonar/application/WebappTest.java121
14 files changed, 47 insertions, 1351 deletions
diff --git a/sonar-application/assembly.xml b/sonar-application/assembly.xml
index bc4eed0b655..c897becdee0 100644
--- a/sonar-application/assembly.xml
+++ b/sonar-application/assembly.xml
@@ -7,17 +7,31 @@
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<!-- Libraries -->
+
<dependencySet>
<outputDirectory>lib</outputDirectory>
+ <useTransitiveDependencies>false</useTransitiveDependencies>
+ <useTransitiveFiltering>false</useTransitiveFiltering>
+ <useProjectArtifact>true</useProjectArtifact>
+ <includes>
+ <include>org.codehaus.sonar:sonar-application</include>
+ <include>tanukisoft:wrapper</include>
+ </includes>
+ </dependencySet>
+
+
+ <dependencySet>
+ <outputDirectory>lib/common</outputDirectory>
<useTransitiveFiltering>true</useTransitiveFiltering>
+ <useProjectArtifact>false</useProjectArtifact>
<excludes>
<exclude>mysql:mysql-connector-java</exclude>
<exclude>org.postgresql:postgresql</exclude>
<exclude>net.sourceforge.jtds:jtds</exclude>
<exclude>tanukisoft:wrapper</exclude>
- <exclude>org.codehaus.sonar:sonar-search</exclude>
- <exclude>org.codehaus.sonar:sonar-process</exclude>
+ <exclude>org.codehaus.sonar:sonar-server-app</exclude>
<exclude>org.codehaus.sonar:sonar-web</exclude>
+ <exclude>org.codehaus.sonar:sonar-search</exclude>
<exclude>org.codehaus.sonar.plugins:*</exclude>
<exclude>org.codehaus.sonar-plugins.java:*</exclude>
<exclude>org.codehaus.sonar:sonar-batch-maven-compat</exclude>
@@ -27,23 +41,27 @@
<dependencySet>
<outputDirectory>lib/search</outputDirectory>
+ <useProjectArtifact>false</useProjectArtifact>
+ <useTransitiveDependencies>true</useTransitiveDependencies>
<useTransitiveFiltering>true</useTransitiveFiltering>
- <outputDirectory>lib</outputDirectory>
- <useTransitiveFiltering>true</useTransitiveFiltering>
- <excludes>
- <exclude>mysql:mysql-connector-java</exclude>
- <exclude>org.postgresql:postgresql</exclude>
- <exclude>net.sourceforge.jtds:jtds</exclude>
- <exclude>tanukisoft:wrapper</exclude>
- <exclude>org.codehaus.sonar:sonar-search</exclude>
- <exclude>org.codehaus.sonar:sonar-process</exclude>
- <exclude>org.codehaus.sonar:sonar-web</exclude>
- <exclude>org.codehaus.sonar.plugins:*</exclude>
- <exclude>org.codehaus.sonar-plugins.java:*</exclude>
- <exclude>org.codehaus.sonar:sonar-batch-maven-compat</exclude>
- </excludes>
+ <includes>
+ <include>org.codehaus.sonar:sonar-search</include>
+ </includes>
+ <scope>runtime</scope>
+ </dependencySet>
+ <dependencySet>
+ <outputDirectory>lib/server</outputDirectory>
+ <useTransitiveDependencies>true</useTransitiveDependencies>
+ <useTransitiveFiltering>true</useTransitiveFiltering>
+ <includes>
+ <include>org.codehaus.sonar:sonar-server-app</include>
+ </includes>
+ <scope>runtime</scope>
</dependencySet>
+
+
+
<dependencySet>
<outputDirectory>lib/batch</outputDirectory>
<useTransitiveDependencies>false</useTransitiveDependencies>
diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml
index 85255196142..2ac77222a32 100644
--- a/sonar-application/pom.xml
+++ b/sonar-application/pom.xml
@@ -15,83 +15,37 @@
<description>Package the standalone distribution</description>
<dependencies>
+
+
<dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-process</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jul-to-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-access</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>sonar-batch-maven-compat</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-logging-juli</artifactId>
- </dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-process</artifactId>
+ <artifactId>sonar-server-app</artifactId>
<version>${project.version}</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-server-app</artifactId>
+ <artifactId>sonar-search</artifactId>
<version>${project.version}</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-search</artifactId>
+ <artifactId>sonar-batch-maven-compat</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
-
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-web</artifactId>
@@ -99,6 +53,7 @@
<type>war</type>
<scope>runtime</scope>
</dependency>
+
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
diff --git a/sonar-application/src/main/assembly/conf/wrapper.conf b/sonar-application/src/main/assembly/conf/wrapper.conf
index 0bd63d41d28..751038ab671 100644
--- a/sonar-application/src/main/assembly/conf/wrapper.conf
+++ b/sonar-application/src/main/assembly/conf/wrapper.conf
@@ -31,9 +31,8 @@ wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
-wrapper.java.classpath.1=../../lib/proc/*.jar
-wrapper.java.classpath.2=../../lib/jsw/*.jar
-wrapper.java.classpath.3=../../lib/*.jar
+wrapper.java.classpath.1=../../lib/common/*.jar
+wrapper.java.classpath.2=../../lib/*.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
diff --git a/sonar-application/src/main/java/org/sonar/application/Connectors.java b/sonar-application/src/main/java/org/sonar/application/Connectors.java
deleted file mode 100644
index 68c216fe516..00000000000
--- a/sonar-application/src/main/java/org/sonar/application/Connectors.java
+++ /dev/null
@@ -1,161 +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.application;
-
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Nullable;
-import java.util.*;
-
-class Connectors {
-
- private static final int DISABLED_PORT = -1;
- static final String HTTP_PROTOCOL = "HTTP/1.1";
- static final String AJP_PROTOCOL = "AJP/1.3";
-
- static void configure(Tomcat tomcat, Props props) {
- configureShutdown(tomcat, props);
- configureConnectors(tomcat, props);
- }
-
- private static void configureConnectors(Tomcat tomcat, Props props) {
- List<Connector> connectors = new ArrayList<Connector>();
- connectors.addAll(Arrays.asList(newHttpConnector(props), newAjpConnector(props), newHttpsConnector(props)));
- connectors.removeAll(Collections.singleton(null));
-
- verify(connectors);
-
- tomcat.setConnector(connectors.get(0));
- for (Connector connector : connectors) {
- tomcat.getService().addConnector(connector);
- }
- }
-
- private static void verify(List<Connector> connectors) {
- if (connectors.isEmpty()) {
- throw new IllegalStateException("HTTP connectors are disabled");
- }
- Set<Integer> ports = new HashSet<Integer>();
- for (Connector connector : connectors) {
- int port = connector.getPort();
- if (ports.contains(port)) {
- throw new IllegalStateException(String.format("HTTP, AJP and HTTPS must not use the same port %d", port));
- }
- ports.add(port);
- }
- }
-
- private static void configureShutdown(Tomcat tomcat, Props props) {
- String shutdownToken = props.of("sonar.web.shutdown.token");
- Integer shutdownPort = props.intOf("sonar.web.shutdown.port");
- if (shutdownToken != null && !"".equals(shutdownToken) && shutdownPort != null) {
- tomcat.getServer().setPort(shutdownPort);
- tomcat.getServer().setShutdown(shutdownToken);
- info("Shutdown command is enabled on port " + shutdownPort);
- }
- }
-
- @Nullable
- private static Connector newHttpConnector(Props props) {
- Connector connector = null;
- // Not named "sonar.web.http.port" to keep backward-compatibility
- int port = props.intOf("sonar.web.port", 9000);
- if (port > DISABLED_PORT) {
- connector = newConnector(props, HTTP_PROTOCOL, "http");
- connector.setPort(port);
- info("HTTP connector is enabled on port " + port);
- }
- return connector;
- }
-
- @Nullable
- private static Connector newAjpConnector(Props props) {
- Connector connector = null;
- int port = props.intOf("sonar.ajp.port", DISABLED_PORT);
- if (port > DISABLED_PORT) {
- connector = newConnector(props, AJP_PROTOCOL, "http");
- connector.setPort(port);
- info("AJP connector is enabled on port " + port);
- }
- return connector;
- }
-
- @Nullable
- private static Connector newHttpsConnector(Props props) {
- Connector connector = null;
- int port = props.intOf("sonar.web.https.port", DISABLED_PORT);
- if (port > DISABLED_PORT) {
- connector = newConnector(props, HTTP_PROTOCOL, "https");
- connector.setPort(port);
- connector.setSecure(true);
- connector.setScheme("https");
- setConnectorAttribute(connector, "keyAlias", props.of("sonar.web.https.keyAlias"));
- String keyPassword = props.of("sonar.web.https.keyPass", "changeit");
- setConnectorAttribute(connector, "keyPass", keyPassword);
- setConnectorAttribute(connector, "keystorePass", props.of("sonar.web.https.keystorePass", keyPassword));
- setConnectorAttribute(connector, "keystoreFile", props.of("sonar.web.https.keystoreFile"));
- setConnectorAttribute(connector, "keystoreType", props.of("sonar.web.https.keystoreType", "JKS"));
- setConnectorAttribute(connector, "keystoreProvider", props.of("sonar.web.https.keystoreProvider"));
- setConnectorAttribute(connector, "truststorePass", props.of("sonar.web.https.truststorePass", "changeit"));
- setConnectorAttribute(connector, "truststoreFile", props.of("sonar.web.https.truststoreFile"));
- setConnectorAttribute(connector, "truststoreType", props.of("sonar.web.https.truststoreType", "JKS"));
- setConnectorAttribute(connector, "truststoreProvider", props.of("sonar.web.https.truststoreProvider"));
- setConnectorAttribute(connector, "clientAuth", props.of("sonar.web.https.clientAuth", "false"));
- setConnectorAttribute(connector, "sslProtocol", "TLS");
- setConnectorAttribute(connector, "SSLEnabled", true);
- info("HTTPS connector is enabled on port " + port);
- }
- return connector;
- }
-
- private static Connector newConnector(Props props, String protocol, String scheme) {
- Connector connector = new Connector(protocol);
- connector.setURIEncoding("UTF-8");
- connector.setProperty("address", props.of("sonar.web.host", "0.0.0.0"));
- configurePool(props, connector, scheme);
- configureCompression(connector);
- return connector;
- }
-
- private static void configurePool(Props props, Connector connector, String scheme) {
- connector.setProperty("acceptorThreadCount", String.valueOf(2));
- connector.setProperty("minSpareThreads", String.valueOf(props.intOf("sonar.web." + scheme + ".minThreads", 5)));
- connector.setProperty("maxThreads", String.valueOf(props.intOf("sonar.web." + scheme + ".maxThreads", 50)));
- connector.setProperty("acceptCount", String.valueOf(props.intOf("sonar.web." + scheme + ".acceptCount", 25)));
- }
-
- private static void configureCompression(Connector connector) {
- connector.setProperty("compression", "on");
- connector.setProperty("compressionMinSize", "1024");
- connector.setProperty("compressableMimeType", "text/html,text/xml,text/plain,text/css,application/json,application/javascript");
- }
-
- private static void setConnectorAttribute(Connector c, String key, @Nullable Object value) {
- if (value != null) {
- c.setAttribute(key, value);
- }
- }
-
- private static void info(String message) {
- LoggerFactory.getLogger(Connectors.class).info(message);
- }
-}
diff --git a/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java b/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
deleted file mode 100644
index ceca36c6718..00000000000
--- a/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
+++ /dev/null
@@ -1,133 +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.application;
-
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
-import org.apache.commons.io.FileUtils;
-
-import java.io.File;
-import java.io.IOException;
-
-class EmbeddedTomcat {
-
- public static final String TEMP_RELATIVE_PATH = "temp/tomcat";
-
- private final Env env;
- private Tomcat tomcat = null;
- private Thread hook = null;
- private boolean stopping = false, ready = false;
-
- EmbeddedTomcat(Env env) {
- this.env = env;
- }
-
- void start() throws IOException, LifecycleException {
- if (tomcat != null || hook != null) {
- throw new IllegalStateException("Server is already started");
- }
-
- // '%2F' (slash /) and '%5C' (backslash \) are permitted as path delimiters in URLs
- // See Ruby on Rails url_for
- System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
-
- System.setProperty("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true");
-
- // Required for webapp and logback xml files
- System.setProperty("SONAR_HOME", env.rootDir().getAbsolutePath());
-
- tomcat = new Tomcat();
-
- // Initialize directories
- String basedir = env.freshDir(TEMP_RELATIVE_PATH).getCanonicalPath();
- tomcat.setBaseDir(basedir);
- tomcat.getHost().setAppBase(basedir);
- tomcat.getHost().setAutoDeploy(false);
- tomcat.getHost().setCreateDirs(false);
- tomcat.getHost().setDeployOnStartup(true);
-
- Props props = Props.create(env);
-
- Logging.configure(tomcat, env, props);
- Connectors.configure(tomcat, props);
- Webapp.configure(tomcat, env, props);
- tomcat.start();
- addShutdownHook();
- ready = true;
- tomcat.getServer().await();
-
- // Shutdown command received
- stop();
- }
-
- private void addShutdownHook() {
- hook = new Thread() {
- @Override
- public void run() {
- EmbeddedTomcat.this.doStop();
- }
- };
- Runtime.getRuntime().addShutdownHook(hook);
- }
-
-
- void stop() {
- removeShutdownHook();
- doStop();
- }
-
- private synchronized void doStop() {
- try {
- if (tomcat != null && !stopping) {
- stopping = true;
- tomcat.stop();
- tomcat.destroy();
- }
- tomcat = null;
- stopping = false;
- ready = false;
- File tempDir = env.file(TEMP_RELATIVE_PATH);
- FileUtils.deleteQuietly(tempDir);
-
- } catch (LifecycleException e) {
- throw new IllegalStateException("Fail to stop web server", e);
- }
- }
-
- private void removeShutdownHook() {
- if (hook != null && !hook.isAlive()) {
- Runtime.getRuntime().removeShutdownHook(hook);
- hook = null;
- }
- }
-
- boolean isReady( ){
- return ready;
- }
-
- int port() {
- Connector[] connectors = tomcat.getService().findConnectors();
- if (connectors.length > 0) {
- return connectors[0].getLocalPort();
- }
- return -1;
- }
-}
diff --git a/sonar-application/src/main/java/org/sonar/application/Logging.java b/sonar-application/src/main/java/org/sonar/application/Logging.java
deleted file mode 100644
index 1de67e61d77..00000000000
--- a/sonar-application/src/main/java/org/sonar/application/Logging.java
+++ /dev/null
@@ -1,80 +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.application;
-
-import ch.qos.logback.access.tomcat.LogbackValve;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.startup.Tomcat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.bridge.SLF4JBridgeHandler;
-
-import java.util.logging.LogManager;
-
-class Logging {
-
- static final String ACCESS_RELATIVE_PATH = "web/WEB-INF/config/logback-access.xml";
- static final String PROPERTY_ENABLE_ACCESS_LOGS = "sonar.web.accessLogs.enable";
-
- static void init() {
- // Configure java.util.logging, used by Tomcat, in order to forward to slf4j
- LogManager.getLogManager().reset();
- SLF4JBridgeHandler.install();
- }
-
- static void configure(Tomcat tomcat, Env env, Props props) {
- tomcat.setSilent(false);
- tomcat.getService().addLifecycleListener(new LifecycleLogger(console()));
- configureLogbackAccess(tomcat, env, props);
- }
-
- static Logger console() {
- return LoggerFactory.getLogger("console");
- }
-
- private static void configureLogbackAccess(Tomcat tomcat, Env env, 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());
- tomcat.getHost().getPipeline().addValve(valve);
- }
- }
-
- static class LifecycleLogger implements LifecycleListener {
- private Logger logger;
-
- LifecycleLogger(Logger logger) {
- this.logger = logger;
- }
-
- @Override
- public void lifecycleEvent(LifecycleEvent event) {
- if ("after_start".equals(event.getType())) {
- logger.info("Web server is started");
-
- } else if ("after_destroy".equals(event.getType())) {
- logger.info("Web server is stopped");
- }
- }
- }
-
-}
diff --git a/sonar-application/src/main/java/org/sonar/application/NullJarScanner.java b/sonar-application/src/main/java/org/sonar/application/NullJarScanner.java
deleted file mode 100644
index 36c9f4c9597..00000000000
--- a/sonar-application/src/main/java/org/sonar/application/NullJarScanner.java
+++ /dev/null
@@ -1,36 +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.application;
-
-import org.apache.tomcat.JarScanner;
-import org.apache.tomcat.JarScannerCallback;
-
-import javax.servlet.ServletContext;
-import java.util.Set;
-
-/**
- * Disable taglib and web-fragment.xml scanning of Tomcat. Should speed up startup.
- */
-class NullJarScanner implements JarScanner {
- @Override
- public void scan(ServletContext context, ClassLoader classloader, JarScannerCallback callback, Set<String> jarsToSkip) {
- // doing nothing is fast!
- }
-}
diff --git a/sonar-application/src/main/java/org/sonar/application/StartServer.java b/sonar-application/src/main/java/org/sonar/application/StartServer.java
deleted file mode 100644
index dd51a5247c4..00000000000
--- a/sonar-application/src/main/java/org/sonar/application/StartServer.java
+++ /dev/null
@@ -1,51 +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.application;
-
-import org.apache.catalina.LifecycleException;
-
-import java.io.IOException;
-
-public final class StartServer {
-
- private final EmbeddedTomcat tomcat;
-
- public StartServer(Env env) {
- Logging.init();
- env.verifyWritableTempDir();
- this.tomcat = new EmbeddedTomcat(env);
- }
-
- void start() throws IOException, LifecycleException {
- tomcat.start();
- }
-
- int port() {
- return tomcat.port();
- }
-
- void stop() {
- tomcat.stop();
- }
-
- public static void main(String[] args) throws Exception {
- new StartServer(new Env()).start();
- }
-}
diff --git a/sonar-application/src/main/java/org/sonar/application/Webapp.java b/sonar-application/src/main/java/org/sonar/application/Webapp.java
deleted file mode 100644
index 082ebdecdea..00000000000
--- a/sonar-application/src/main/java/org/sonar/application/Webapp.java
+++ /dev/null
@@ -1,69 +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.application;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.startup.Tomcat;
-import org.slf4j.LoggerFactory;
-
-class Webapp {
-
- private static final String JRUBY_MAX_RUNTIMES = "jruby.max.runtimes";
- private static final String RAILS_ENV = "rails.env";
- private static final String PROPERTY_CONTEXT = "sonar.web.context";
- 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) {
- try {
- Context context = tomcat.addWebapp(getContextPath(props), env.file("web").getAbsolutePath());
- context.setConfigFile(env.file("web/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"));
-
- configureRailsMode(props, context);
- context.setJarScanner(new NullJarScanner());
-
- } catch (Exception e) {
- throw new IllegalStateException("Fail to configure webapp", e);
- }
- }
-
- static String getContextPath(Props props) {
- String context = props.of(PROPERTY_CONTEXT, "");
- if ("/".equals(context)) {
- context = "";
- } else if (!"".equals(context) && !context.startsWith("/")) {
- throw new IllegalStateException(String.format("Value of '%s' must start with a forward slash: '%s'", PROPERTY_CONTEXT, context));
- }
- return context;
- }
-
- static void configureRailsMode(Props props, Context context) {
- if (props.booleanOf("sonar.rails.dev")) {
- context.addParameter(RAILS_ENV, "development");
- context.addParameter(JRUBY_MAX_RUNTIMES, "3");
- LoggerFactory.getLogger(Webapp.class).warn("\n\n\n------ RAILS DEVELOPMENT MODE IS ENABLED ------\n\n\n");
- } else {
- context.addParameter(RAILS_ENV, "production");
- context.addParameter(JRUBY_MAX_RUNTIMES, "1");
- }
- }
-}
diff --git a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java b/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java
deleted file mode 100644
index da105cf9b86..00000000000
--- a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java
+++ /dev/null
@@ -1,340 +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.application;
-
-import com.google.common.collect.ImmutableMap;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.mockito.Mockito;
-
-import java.net.InetAddress;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.*;
-
-public class ConnectorsTest {
-
- Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS);
-
- //---- connectors
-
- @Test
- public void configure_thread_pool() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.http.minThreads", "2");
- p.setProperty("sonar.web.http.maxThreads", "30");
- p.setProperty("sonar.web.http.acceptCount", "20");
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat).setConnector(argThat(new PropertiesMatcher(
- ImmutableMap.<String, Object>of("minSpareThreads", 2, "maxThreads", 30, "acceptCount", 20)
- )));
- }
-
- @Test
- public void configure_default_thread_pool() throws Exception {
- Props props = new Props(new Properties());
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat).setConnector(argThat(new PropertiesMatcher(
- ImmutableMap.<String, Object>of("minSpareThreads", 5, "maxThreads", 50, "acceptCount", 25)
- )));
- }
-
- @Test
- public void different_thread_pools_for_connectors() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.port", "9000");
- p.setProperty("sonar.web.http.minThreads", "2");
- p.setProperty("sonar.web.https.port", "9443");
- p.setProperty("sonar.web.https.minThreads", "5");
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getPort() == 9000 && c.getProperty("minSpareThreads").equals(2);
- }
- }));
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getPort() == 9443 && c.getProperty("minSpareThreads").equals(5);
- }
- }));
- }
-
- @Test
- public void fail_if_http_connectors_are_disabled() {
- Properties p = new Properties();
- p.setProperty("sonar.web.port", "-1");
- p.setProperty("sonar.web.https.port", "-1");
- Props props = new Props(p);
-
- try {
- Connectors.configure(tomcat, props);
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("HTTP connectors are disabled");
- }
- }
-
- @Test
- public void only_https_is_enabled() {
- Properties p = new Properties();
- p.setProperty("sonar.web.port", "-1");
- p.setProperty("sonar.web.https.port", "9443");
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat).setConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("https") && c.getPort() == 9443
- && c.getProperty("clientAuth").equals("false");
- }
- }));
- }
-
- @Test
- public void all_connectors_are_enabled() {
- Properties p = new Properties();
- p.setProperty("sonar.web.port", "9000");
- p.setProperty("sonar.ajp.port", "9009");
- p.setProperty("sonar.web.https.port", "9443");
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("http") && c.getPort() == 9000 && c.getProtocol().equals(Connectors.HTTP_PROTOCOL);
- }
- }));
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("http") && c.getPort() == 9009 && c.getProtocol().equals(Connectors.AJP_PROTOCOL);
- }
- }));
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("https") && c.getPort() == 9443 && c.getProtocol().equals(Connectors.HTTP_PROTOCOL);
- }
- }));
- }
-
- @Test
- public void http_and_ajp_and_https_ports_should_be_different() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.port", "9000");
- p.setProperty("sonar.ajp.port", "9000");
- p.setProperty("sonar.web.https.port", "9000");
-
- try {
- Connectors.configure(tomcat, new Props(p));
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("HTTP, AJP and HTTPS must not use the same port 9000");
- }
- }
-
- @Test
- public void bind_to_all_addresses_by_default() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.port", "9000");
- p.setProperty("sonar.ajp.port", "9009");
- p.setProperty("sonar.web.https.port", "9443");
-
- Connectors.configure(tomcat, new Props(p));
-
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("0.0.0.0");
- }
- }));
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("http") && c.getPort() == 9009 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("0.0.0.0");
- }
- }));
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("https") && c.getPort() == 9443 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("0.0.0.0");
- }
- }));
- }
-
- @Test
- public void bind_to_specific_address() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.port", "9000");
- p.setProperty("sonar.web.https.port", "9443");
- p.setProperty("sonar.web.host", "1.2.3.4");
-
- Connectors.configure(tomcat, new Props(p));
-
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("1.2.3.4");
- }
- }));
- verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("https") && c.getPort() == 9443 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("1.2.3.4");
- }
- }));
- }
-
-
- //---- shutdown port
-
- @Test
- public void enable_shutdown_port() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.shutdown.port", "9010");
- p.setProperty("sonar.web.shutdown.token", "SHUTDOWN");
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat.getServer()).setPort(9010);
- verify(tomcat.getServer()).setShutdown("SHUTDOWN");
- }
-
- @Test
- public void disable_shutdown_port_by_default() throws Exception {
- Props props = new Props(new Properties());
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat.getServer(), never()).setPort(anyInt());
- verify(tomcat.getServer(), never()).setShutdown(anyString());
- }
-
- @Test
- public void disable_shutdown_port_if_missing_token() throws Exception {
- Properties p = new Properties();
- // only the port, but not the token
- p.setProperty("sonar.web.shutdown.port", "9010");
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat.getServer(), never()).setPort(anyInt());
- verify(tomcat.getServer(), never()).setShutdown(anyString());
- }
-
- @Test
- public void enable_client_auth() throws Exception {
-
- Properties p = new Properties();
-
- p.setProperty("sonar.web.port", "-1");
- p.setProperty("sonar.web.https.port", "9443");
- p.setProperty("sonar.web.https.clientAuth", "want");
-
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat).setConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("https") && c.getProperty("clientAuth").equals("want");
- }
- }));
- }
-
- @Test
- public void require_client_auth() throws Exception {
-
- Properties p = new Properties();
-
- p.setProperty("sonar.web.port", "-1");
- p.setProperty("sonar.web.https.port", "9443");
- p.setProperty("sonar.web.https.clientAuth", "true");
-
- Props props = new Props(p);
-
- Connectors.configure(tomcat, props);
-
- verify(tomcat).setConnector(argThat(new ArgumentMatcher<Connector>() {
- @Override
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- return c.getScheme().equals("https") && c.getProperty("clientAuth").equals("true");
- }
- }));
- }
-
-
-
- private static class PropertiesMatcher extends ArgumentMatcher<Connector> {
- private final Map<String, Object> expected;
-
- PropertiesMatcher(Map<String, Object> expected) {
- this.expected = expected;
- }
-
- public boolean matches(Object o) {
- Connector c = (Connector) o;
- for (Map.Entry<String, Object> entry : expected.entrySet()) {
- if (!entry.getValue().equals(c.getProperty(entry.getKey()))) {
- return false;
- }
- }
- return true;
- }
- }
-}
diff --git a/sonar-application/src/test/java/org/sonar/application/LoggingTest.java b/sonar-application/src/test/java/org/sonar/application/LoggingTest.java
deleted file mode 100644
index 1ff7b194d56..00000000000
--- a/sonar-application/src/test/java/org/sonar/application/LoggingTest.java
+++ /dev/null
@@ -1,91 +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.application;
-
-import ch.qos.logback.access.tomcat.LogbackValve;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.Valve;
-import org.apache.catalina.startup.Tomcat;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.mockito.ArgumentMatcher;
-import org.mockito.Mockito;
-import org.slf4j.Logger;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class LoggingTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Before
- public void setHome() throws IOException {
- File homeDir = temp.newFolder("home");
- System.setProperty("SONAR_HOME", homeDir.getAbsolutePath());
- }
-
- @Test
- public void enable_access_logs_by_Default() throws Exception {
- Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS);
- Props props = new Props(new Properties());
- Env env = mock(Env.class);
- when(env.file(Logging.ACCESS_RELATIVE_PATH)).thenReturn(temp.newFile("logback-access.xml"));
- Logging.configure(tomcat, env, props);
-
- verify(tomcat.getHost().getPipeline()).addValve(argThat(new ArgumentMatcher<Valve>() {
- @Override
- public boolean matches(Object o) {
- LogbackValve v = (LogbackValve) o;
- String confFile = v.getFilename();
- return confFile.endsWith("logback-access.xml");
- }
- }));
- }
-
- @Test
- public void log_when_started_and_stopped() {
- Logger logger = mock(Logger.class);
- Logging.LifecycleLogger listener = new Logging.LifecycleLogger(logger);
-
- LifecycleEvent event = new LifecycleEvent(mock(Lifecycle.class), "before_init", null);
- listener.lifecycleEvent(event);
- verifyZeroInteractions(logger);
-
- event = new LifecycleEvent(mock(Lifecycle.class), "after_start", null);
- listener.lifecycleEvent(event);
- verify(logger).info("Web server is started");
-
- event = new LifecycleEvent(mock(Lifecycle.class), "after_destroy", null);
- listener.lifecycleEvent(event);
- verify(logger).info("Web server is stopped");
- }
-}
diff --git a/sonar-application/src/test/java/org/sonar/application/NullJarScannerTest.java b/sonar-application/src/test/java/org/sonar/application/NullJarScannerTest.java
deleted file mode 100644
index 4654152b639..00000000000
--- a/sonar-application/src/test/java/org/sonar/application/NullJarScannerTest.java
+++ /dev/null
@@ -1,43 +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.application;
-
-import org.apache.tomcat.JarScannerCallback;
-import org.junit.Test;
-
-import javax.servlet.ServletContext;
-import java.util.HashSet;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
-public class NullJarScannerTest {
-
- @Test
- public void does_nothing() {
- ServletContext context = mock(ServletContext.class);
- ClassLoader classloader = mock(ClassLoader.class);
- JarScannerCallback callback = mock(JarScannerCallback.class);
-
- new NullJarScanner().scan(context, classloader, callback, new HashSet<String>());
-
- verifyZeroInteractions(context, classloader, callback);
- }
-}
diff --git a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
deleted file mode 100644
index 33bdd787db5..00000000000
--- a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
+++ /dev/null
@@ -1,151 +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.application;
-
-import com.github.kevinsawicki.http.HttpRequest;
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class StartServerTest {
-
- Env env;
- StartServer starter;
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Before
- public void prepare_app() throws Exception {
- File confFile = new File("src/test/fake-app/conf/sonar.properties");
- if (!confFile.exists()) {
- confFile = new File("sonar-application/src/test/fake-app/conf/sonar.properties");
- }
-
- File rootDir = temp.newFolder();
- FileUtils.copyDirectory(confFile.getParentFile().getParentFile(), rootDir);
- env = new Env(new File(rootDir, "conf/sonar.properties").toURL());
- starter = new StartServer(env);
- }
-
- @Test
- public void start_server() throws Exception {
- BackgroundThread background = new BackgroundThread(starter);
- int port = 0;
- try {
- background.start();
- boolean started = false;
- for (int i = 0; i < 400; i++) {
- // Waiting for server to be started.
- // A random and open port is used (see conf/sonar.properties)
- Thread.sleep(300L);
- if (verifyUp() && verifyLogs()) {
- port = starter.port();
- started = true;
- break;
- }
- }
- assertThat(started).isTrue();
- } finally {
- starter.stop();
- }
-
- // Server is down
- try {
- assertThat(HttpRequest.get("http://localhost:" + port).ok()).isFalse();
- } catch (HttpRequest.HttpRequestException e) {
- // ok
- }
- }
-
- private boolean verifyUp() {
- if (starter.port() > 0) {
- String url = "http://localhost:" + starter.port() + "/index.html";
- HttpRequest request = HttpRequest.get(url);
- if (request.ok() && "Hello World".equals(request.body(HttpRequest.CHARSET_UTF8))) {
- return true;
- }
- }
- return false;
- }
-
- private boolean verifyLogs() {
- File logFile = env.file("logs/access.log");
- return logFile.isFile() && logFile.exists() && logFile.length()>0;
- }
-
- @Test
- public void fail_if_started_twice() throws Exception {
- BackgroundThread background = new BackgroundThread(starter);
- try {
- background.start();
- boolean started = false;
- for (int i = 0; i < 100; i++) {
- // Waiting for server to be started.
- // A random and open port is used (see conf/sonar.properties)
- Thread.sleep(500L);
- if (starter.port() > 0) {
- try {
- starter.start();
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Server is already started");
- started = true;
- break;
- }
- }
- }
- assertThat(started).isTrue();
-
- } finally {
- starter.stop();
- }
- }
-
- @Test
- public void ignore_stop_if_not_running() throws Exception {
- starter.stop();
- starter.stop();
- }
-
- static class BackgroundThread extends Thread {
- private StartServer server;
-
- BackgroundThread(StartServer server) {
- this.server = server;
- }
-
- @Override
- public void run() {
- try {
- server.start();
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
- }
-}
diff --git a/sonar-application/src/test/java/org/sonar/application/WebappTest.java b/sonar-application/src/test/java/org/sonar/application/WebappTest.java
deleted file mode 100644
index ccfe6d3fb52..00000000000
--- a/sonar-application/src/test/java/org/sonar/application/WebappTest.java
+++ /dev/null
@@ -1,121 +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.application;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.startup.Tomcat;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class WebappTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- private Env env;
-
- @Before
- public void initEnv() throws IOException {
- env = mock(Env.class);
- File sonarHome = temp.newFolder("home");
- when(env.rootDir()).thenReturn(sonarHome);
- System.setProperty("SONAR_HOME", sonarHome.getAbsolutePath());
- }
-
- @Test
- public void fail_on_error() throws Exception {
- File webDir = temp.newFolder("web");
- when(env.file("web")).thenReturn(webDir);
-
- Tomcat tomcat = mock(Tomcat.class, RETURNS_DEEP_STUBS);
- when(tomcat.addContext("", webDir.getAbsolutePath())).thenThrow(new NullPointerException());
-
- try {
- Webapp.configure(tomcat, env, new Props(new Properties()));
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Fail to configure webapp");
- }
- }
-
- @Test
- public void configure_dev_mode() throws Exception {
- Props props = mock(Props.class);
- when(props.booleanOf("sonar.rails.dev")).thenReturn(true);
- Context context = mock(Context.class);
-
- Webapp.configureRailsMode(props, context);
-
- verify(context).addParameter("jruby.max.runtimes", "3");
- verify(context).addParameter("rails.env", "development");
- }
-
- @Test
- public void configure_production_mode() throws Exception {
- Props props = mock(Props.class);
- when(props.booleanOf("sonar.rails.dev")).thenReturn(false);
- Context context = mock(Context.class);
-
- Webapp.configureRailsMode(props, context);
-
- verify(context).addParameter("jruby.max.runtimes", "1");
- verify(context).addParameter("rails.env", "production");
- }
-
- @Test
- public void context_path_must_start_with_slash() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.context", "foo");
-
- try {
- Webapp.getContextPath(new Props(p));
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Value of 'sonar.web.context' must start with a forward slash: 'foo'");
- }
- }
-
- @Test
- public void root_context_path_must_be_blank() throws Exception {
- Properties p = new Properties();
- p.setProperty("sonar.web.context", "/");
-
- assertThat(Webapp.getContextPath(new Props(p))).isEqualTo("");
- }
-
- @Test
- public void default_context_path_is_root() throws Exception {
- String context = Webapp.getContextPath(new Props(new Properties()));
- assertThat(context).isEqualTo("");
- }
-}