org.sonar.server.app.TomcatContexts Maven / Gradle / Ivy
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program 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.
*
* This program 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 com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.FileUtils;
import org.sonar.api.utils.MessageException;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
import static java.lang.String.format;
/**
* Configures Tomcat contexts:
*
* - /deploy delivers the plugins required by analyzers. It maps directory ${sonar.path.data}/web/deploy.
* - / is the regular webapp
*
*/
public class TomcatContexts {
public static final String PROPERTY_CONTEXT = "sonar.web.context";
public static final String WEB_DEPLOY_PATH_RELATIVE_TO_DATA_DIR = "web/deploy";
private final Fs fs;
public TomcatContexts() {
this.fs = new Fs();
}
@VisibleForTesting
TomcatContexts(Fs fs) {
this.fs = fs;
}
public StandardContext configure(Tomcat tomcat, Props props) {
addStaticDir(tomcat, getContextPath(props) + "/deploy", new File(props.nonNullValueAsFile(ProcessProperties.PATH_DATA), WEB_DEPLOY_PATH_RELATIVE_TO_DATA_DIR));
StandardContext webapp = addContext(tomcat, getContextPath(props), webappDir(props));
for (Map.Entry