Log.setLog(new JettyTreeLogger(branch));
// Turn off XML validation.
System.setProperty("org.mortbay.xml.XmlParser.Validating", "false");
AbstractConnector connector = getConnector();
if (bindAddress != null) {
connector.setHost(bindAddress.toString());
}
connector.setPort(port);
// Don't share ports with an existing process.
connector.setReuseAddress(false);
// Linux keeps the port blocked after shutdown if we don't disable this.
connector.setSoLingerTime(0);
Server server = new Server();
server.addConnector(connector);
// warDir is "$top/gerrit-gwtui/target/gwt-hosted-mode"
//
File top = warDir.getParentFile().getParentFile().getParentFile();
File app = new File(top, "gerrit-war/src/main/webapp");
File webxml = new File(app, "WEB-INF/web.xml");
// Jetty won't start unless this directory exists.
if (!warDir.exists() && !warDir.mkdirs())
logger.branch(TreeLogger.ERROR, "Cannot create "+warDir, null);
// Create a new web app in the war directory.
//
WebAppContext wac =
new MyWebAppContext(warDir.getAbsolutePath(), "/");
wac.setDescriptor(webxml.getAbsolutePath());
RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(new JettyRequestLogger(logger));
logHandler.setHandler(wac);
server.setHandler(logHandler);
server.start();
server.setStopAtShutdown(true);
// Now that we're started, log to the top level logger.
Log.setLog(new JettyTreeLogger(logger));
return new JettyServletContainer(logger, server, wac, connector
.getLocalPort(), warDir);
}