001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.application; 021 022 import java.io.File; 023 import java.io.IOException; 024 import java.net.URISyntaxException; 025 import java.util.Properties; 026 027 public final class StartServer { 028 private static final String DEFAULT_WEB_HOST = "0.0.0.0"; 029 private static final int DEFAULT_WEB_PORT = 9000; 030 private static final String DEFAULT_WEB_CONTEXT = "/"; 031 private static final int DEFAULT_AJP13_PORT = -1; 032 033 private StartServer() { 034 } 035 036 public static void main(String[] args) throws Exception { 037 configureHome(); 038 039 Properties configuration = getConfiguration(); 040 String host = configuration.getProperty("sonar.web.host", DEFAULT_WEB_HOST); 041 int port = Integer.parseInt(configuration.getProperty("sonar.web.port", "" + DEFAULT_WEB_PORT)); 042 String context = configuration.getProperty("sonar.web.context", DEFAULT_WEB_CONTEXT); 043 int ajp13Port = Integer.parseInt(configuration.getProperty("sonar.ajp13.port", "" + DEFAULT_AJP13_PORT)); 044 JettyEmbedder jetty = new JettyEmbedder(host, port, context, ajp13Port, StartServer.class.getResource("/jetty.xml")); 045 configureRequestLogs(jetty, configuration); 046 047 jetty.start(); 048 Thread.currentThread().join(); 049 } 050 051 private static void configureRequestLogs(JettyEmbedder jetty, Properties configuration) { 052 String filenamePattern = configuration.getProperty("sonar.web.jettyRequestLogs"); 053 if (filenamePattern != null) { 054 jetty.configureRequestLogs(filenamePattern); 055 } 056 } 057 058 private static Properties getConfiguration() throws IOException { 059 Properties properties = new Properties(); 060 properties.load(StartServer.class.getResourceAsStream("/conf/sonar.properties")); 061 return properties; 062 } 063 064 private static void configureHome() throws URISyntaxException { 065 File confFile = new File(StartServer.class.getResource("/conf/sonar.properties").toURI()); 066 System.setProperty("SONAR_HOME" /* see constant org.sonar.server.platform.SonarHome.PROPERTY */, 067 confFile.getParentFile().getParentFile().getAbsolutePath()); 068 } 069 }