diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/PolyGerritUiIndexServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/PolyGerritUiIndexServlet.java deleted file mode 100644 index 3b225c900a..0000000000 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/PolyGerritUiIndexServlet.java +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2015 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.raw; - -import com.google.common.cache.Cache; - -import java.nio.file.Path; - -class PolyGerritUiIndexServlet extends ResourceServlet { - private static final long serialVersionUID = 1L; - - private final Path index; - - PolyGerritUiIndexServlet(Cache cache, Path ui) { - super(cache, true); - index = ui.resolve("index.html"); - } - - @Override - protected Path getResourcePath(String pathInfo) { - return index; - } -} diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java index 3ae36ffe61..a34137e50d 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java @@ -73,6 +73,8 @@ public class StaticModule extends ServletModule { private static final String DOC_SERVLET = "DocServlet"; private static final String FAVICON_SERVLET = "FaviconServlet"; private static final String GWT_UI_SERVLET = "GwtUiServlet"; + private static final String POLYGERRIT_INDEX_SERVLET = + "PolyGerritUiIndexServlet"; private static final String ROBOTS_TXT_SERVLET = "RobotsTxtServlet"; private final GerritOptions options; @@ -228,18 +230,21 @@ public class StaticModule extends ServletModule { // separate servlet. } + Key indexKey = named(POLYGERRIT_INDEX_SERVLET); for (String p : POLYGERRIT_INDEX_PATHS) { filter(p).through(XsrfCookieFilter.class); - serve(p).with(PolyGerritUiIndexServlet.class); + serve(p).with(indexKey); } serve("/*").with(PolyGerritUiServlet.class); } @Provides @Singleton - PolyGerritUiIndexServlet getPolyGerritUiIndexServlet( + @Named(POLYGERRIT_INDEX_SERVLET) + HttpServlet getPolyGerritUiIndexServlet( @Named(CACHE) Cache cache) { - return new PolyGerritUiIndexServlet(cache, polyGerritBasePath()); + return new SingleFileServlet( + cache, polyGerritBasePath().resolve("index.html"), isDev()); } @Provides @@ -256,14 +261,17 @@ public class StaticModule extends ServletModule { return new BowerComponentsServlet(cache, getPaths().buckOut); } + private boolean isDev() { + return options.forcePolyGerritDev() || getPaths().warFs == null; + } + private Path polyGerritBasePath() { Paths p = getPaths(); - boolean forceDev = options.forcePolyGerritDev(); - if (forceDev) { + if (options.forcePolyGerritDev()) { checkArgument(p.buckOut != null, "no buck-out directory found for PolyGerrit developer mode"); } - return forceDev || p.warFs == null + return isDev() ? p.buckOut.getParent().resolve("polygerrit-ui").resolve("app") : p.warFs.getPath("/polygerrit_ui"); }