Replace PolyGerritUiIndexServlet with SingleFileServlet

Change-Id: I19688f1145d67784f71cd9fd060798a51eae8a40
This commit is contained in:
Dave Borowitz 2015-12-14 13:32:15 -05:00
parent 12380e0a0d
commit 6a55317d4c
2 changed files with 14 additions and 41 deletions

View File

@ -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<Path, Resource> cache, Path ui) {
super(cache, true);
index = ui.resolve("index.html");
}
@Override
protected Path getResourcePath(String pathInfo) {
return index;
}
}

View File

@ -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<HttpServlet> 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<Path, Resource> 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");
}