diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritUiOptions.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritUiOptions.java new file mode 100644 index 0000000000..cd07320a7a --- /dev/null +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritUiOptions.java @@ -0,0 +1,27 @@ +// Copyright (C) 2013 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.httpd; + +public class GerritUiOptions { + private final boolean headless; + + public GerritUiOptions(boolean headless) { + this.headless = headless; + } + + public boolean enableDefaultUi() { + return !headless; + } +} diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java index 8d9d35415e..41efe34180 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java @@ -59,9 +59,11 @@ class UrlModule extends ServletModule { } private final UrlConfig cfg; + private GerritUiOptions uiOptions; - UrlModule(UrlConfig cfg) { + UrlModule(UrlConfig cfg, GerritUiOptions uiOptions) { this.cfg = cfg; + this.uiOptions = uiOptions; } @Override @@ -69,9 +71,11 @@ class UrlModule extends ServletModule { filter("/*").through(Key.get(CacheControlFilter.class)); bind(Key.get(CacheControlFilter.class)).in(SINGLETON); - serve("/").with(HostPageServlet.class); - serve("/Gerrit").with(LegacyGerritServlet.class); - serve("/Gerrit/*").with(legacyGerritScreen()); + if (uiOptions.enableDefaultUi()) { + serve("/").with(HostPageServlet.class); + serve("/Gerrit").with(LegacyGerritServlet.class); + serve("/Gerrit/*").with(legacyGerritScreen()); + } serve("/cat/*").with(CatServlet.class); serve("/logout").with(HttpLogoutServlet.class); serve("/signout").with(HttpLogoutServlet.class); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java index f76927bd6b..f605d541d9 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java @@ -14,8 +14,8 @@ package com.google.gerrit.httpd; -import static com.google.inject.Scopes.SINGLETON; import static com.google.gerrit.extensions.registration.PrivateInternals_DynamicTypes.registerInParentInjectors; +import static com.google.inject.Scopes.SINGLETON; import com.google.gerrit.common.data.GerritConfig; import com.google.gerrit.extensions.registration.DynamicSet; @@ -43,6 +43,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.ProvisionException; +import com.google.inject.name.Named; import com.google.inject.servlet.RequestScoped; import com.google.inject.servlet.ServletModule; @@ -55,15 +56,18 @@ public class WebModule extends FactoryModule { private final UrlModule.UrlConfig urlConfig; private final boolean wantSSL; private final GitWebConfig gitWebConfig; + private final GerritUiOptions uiOptions; @Inject WebModule(final AuthConfig authConfig, final UrlModule.UrlConfig urlConfig, @CanonicalWebUrl @Nullable final String canonicalUrl, + GerritUiOptions uiOptions, final Injector creatingInjector) { this.authConfig = authConfig; this.urlConfig = urlConfig; this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:"); + this.uiOptions = uiOptions; this.gitWebConfig = creatingInjector.createChildInjector(new AbstractModule() { @@ -116,7 +120,7 @@ public class WebModule extends FactoryModule { throw new ProvisionException("Unsupported loginType: " + authConfig.getAuthType()); } - install(new UrlModule(urlConfig)); + install(new UrlModule(urlConfig, uiOptions)); install(new UiRpcModule()); install(new GerritRequestModule()); install(new GitOverHttpServlet.Module()); diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java index 45e63606dd..3dfc5a0f33 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java @@ -19,6 +19,7 @@ import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_U import com.google.gerrit.common.ChangeHookRunner; import com.google.gerrit.httpd.AllRequestFilter; import com.google.gerrit.httpd.CacheBasedWebSession; +import com.google.gerrit.httpd.GerritUiOptions; import com.google.gerrit.httpd.GitOverHttpModule; import com.google.gerrit.httpd.HttpCanonicalWebUrlProvider; import com.google.gerrit.httpd.RequestContextFilter; @@ -65,10 +66,12 @@ import com.google.gwtorm.jdbc.JdbcSchema; import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.SchemaFactory; import com.google.gwtorm.server.StatementExecutor; +import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.Provider; +import com.google.inject.name.Names; import org.eclipse.jgit.lib.Config; import org.kohsuke.args4j.Option; @@ -113,6 +116,9 @@ public class Daemon extends SiteProgram { @Option(name = "--run-id", usage = "Cookie to store in $site_path/logs/gerrit.run") private String runId; + @Option(name = "--headless", usage = "Don't start the UI frontend") + private boolean headless; + private final LifecycleManager manager = new LifecycleManager(); private Injector dbInjector; private Injector cfgInjector; @@ -315,6 +321,12 @@ public class Daemon extends SiteProgram { if (!slave) { modules.add(new MasterNodeStartup()); } + modules.add(new AbstractModule() { + @Override + protected void configure() { + bind(GerritUiOptions.class).toInstance(new GerritUiOptions(headless)); + } + }); return cfgInjector.createChildInjector(modules); } diff --git a/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java b/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java index 19b31d9fbf..3059dfac41 100644 --- a/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java +++ b/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java @@ -18,6 +18,7 @@ import static com.google.inject.Scopes.SINGLETON; import static com.google.inject.Stage.PRODUCTION; import com.google.gerrit.common.ChangeHookRunner; +import com.google.gerrit.httpd.GerritUiOptions; import com.google.gerrit.httpd.auth.openid.OpenIdModule; import com.google.gerrit.httpd.plugins.HttpPluginModule; import com.google.gerrit.lifecycle.LifecycleManager; @@ -241,6 +242,12 @@ public class WebAppInitializer extends GuiceServletContextListener { }); modules.add(SshKeyCacheImpl.module()); modules.add(new MasterNodeStartup()); + modules.add(new AbstractModule() { + @Override + protected void configure() { + bind(GerritUiOptions.class).toInstance(new GerritUiOptions(false)); + } + }); return cfgInjector.createChildInjector(modules); }