Merge "Brings Gerrit docs back to life"
This commit is contained in:
commit
04cd02b995
@ -38,6 +38,8 @@ import java.nio.file.FileSystem;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class StaticModule extends ServletModule {
|
||||
public static final String CACHE = "static_content";
|
||||
@ -57,6 +59,7 @@ public class StaticModule extends ServletModule {
|
||||
"/projects/*");
|
||||
|
||||
private static final String GWT_UI_SERVLET = "GwtUiServlet";
|
||||
private static final String DOC_SERVLET = "DocServlet";
|
||||
|
||||
private final GerritOptions options;
|
||||
private Paths paths;
|
||||
@ -75,6 +78,8 @@ public class StaticModule extends ServletModule {
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
serveRegex("^/Documentation/(.+)$").with(
|
||||
Key.get(HttpServlet.class, Names.named(DOC_SERVLET)));
|
||||
serve("/static/*").with(SiteStaticDirectoryServlet.class);
|
||||
install(new CacheModule() {
|
||||
@Override
|
||||
@ -91,6 +96,26 @@ public class StaticModule extends ServletModule {
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(DOC_SERVLET)
|
||||
HttpServlet getDocServlet(@Named(CACHE) Cache<Path, Resource> cache) {
|
||||
Paths p = getPaths();
|
||||
if (p.warFs != null) {
|
||||
return new WarDocServlet(cache, p.warFs);
|
||||
} else {
|
||||
return new HttpServlet() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws IOException {
|
||||
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class GwtUiModule extends ServletModule {
|
||||
@Override
|
||||
public void configureServlets() {
|
||||
|
@ -0,0 +1,36 @@
|
||||
// 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.FileSystem;
|
||||
import java.nio.file.Path;
|
||||
|
||||
class WarDocServlet extends ResourceServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final FileSystem warFs;
|
||||
|
||||
WarDocServlet(Cache<Path, Resource> cache, FileSystem warFs) {
|
||||
super(cache, false);
|
||||
this.warFs = warFs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Path getResourcePath(String pathInfo) {
|
||||
return warFs.getPath("/Documentation/" + pathInfo);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user