Serve gitweb.js when serving gitweb.cgi
Recently gitweb learned how to use JavaScript for some advanced UI features. Make sure we also serve up the gitweb.js file if it is available from the resource directory. Change-Id: Ie25b5f7e4b27d80c946da5e670433fc4d97ad49f Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
b2a249cabd
commit
526490a8b8
|
@ -31,12 +31,12 @@ public class GitWebConfig {
|
|||
private final String url;
|
||||
private final File gitweb_cgi;
|
||||
private final File gitweb_css;
|
||||
private final File gitweb_js;
|
||||
private final File git_logo_png;
|
||||
private GitWebType type;
|
||||
|
||||
@Inject
|
||||
GitWebConfig(final SitePaths sitePaths,
|
||||
@GerritServerConfig final Config cfg) {
|
||||
GitWebConfig(final SitePaths sitePaths, @GerritServerConfig final Config cfg) {
|
||||
final String cfgUrl = cfg.getString("gitweb", null, "url");
|
||||
final String cfgCgi = cfg.getString("gitweb", null, "cgi");
|
||||
|
||||
|
@ -64,6 +64,7 @@ public class GitWebConfig {
|
|||
url = null;
|
||||
gitweb_cgi = null;
|
||||
gitweb_css = null;
|
||||
gitweb_js = null;
|
||||
git_logo_png = null;
|
||||
return;
|
||||
}
|
||||
|
@ -74,6 +75,7 @@ public class GitWebConfig {
|
|||
url = cfgUrl;
|
||||
gitweb_cgi = null;
|
||||
gitweb_css = null;
|
||||
gitweb_js = null;
|
||||
git_logo_png = null;
|
||||
return;
|
||||
}
|
||||
|
@ -113,10 +115,11 @@ public class GitWebConfig {
|
|||
resourcePaths = new String[] {};
|
||||
}
|
||||
|
||||
File css = null, logo = null;
|
||||
File css = null, js = null, logo = null;
|
||||
for (String path : resourcePaths) {
|
||||
File dir = new File(path);
|
||||
css = new File(dir, "gitweb.css");
|
||||
js = new File(dir, "gitweb.js");
|
||||
logo = new File(dir, "git-logo.png");
|
||||
if (css.isFile() && logo.isFile()) {
|
||||
break;
|
||||
|
@ -126,6 +129,7 @@ public class GitWebConfig {
|
|||
url = cgi != null ? "gitweb" : null;
|
||||
gitweb_cgi = cgi;
|
||||
gitweb_css = css;
|
||||
gitweb_js = js;
|
||||
git_logo_png = logo;
|
||||
}
|
||||
|
||||
|
@ -153,6 +157,11 @@ public class GitWebConfig {
|
|||
return gitweb_css;
|
||||
}
|
||||
|
||||
/** @return local path of the {@code gitweb.js} for the CGI. */
|
||||
public File getGitwebJS() {
|
||||
return gitweb_js;
|
||||
}
|
||||
|
||||
/** @return local path of the {@code git-logo.png} for the CGI. */
|
||||
public File getGitLogoPNG() {
|
||||
return git_logo_png;
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright (C) 2010 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.gitweb;
|
||||
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.util.IO;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Singleton
|
||||
class GitWebJavaScriptServlet extends HttpServlet {
|
||||
private final byte[] raw;
|
||||
|
||||
@Inject
|
||||
GitWebJavaScriptServlet(final GitWebConfig gitWebConfig) throws IOException {
|
||||
byte[] png;
|
||||
if (gitWebConfig.getGitwebJS() != null) {
|
||||
try {
|
||||
png = IO.readFully(gitWebConfig.getGitwebJS());
|
||||
} catch (FileNotFoundException e) {
|
||||
png = null;
|
||||
}
|
||||
} else {
|
||||
png = null;
|
||||
}
|
||||
raw = png;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(final HttpServletRequest req,
|
||||
final HttpServletResponse rsp) throws IOException {
|
||||
if (raw != null) {
|
||||
rsp.setContentType("text/javascript");
|
||||
rsp.setContentLength(raw.length);
|
||||
|
||||
final ServletOutputStream os = rsp.getOutputStream();
|
||||
try {
|
||||
os.write(raw);
|
||||
} finally {
|
||||
os.close();
|
||||
}
|
||||
} else {
|
||||
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ public class GitWebModule extends ServletModule {
|
|||
protected void configureServlets() {
|
||||
serve("/gitweb").with(GitWebServlet.class);
|
||||
serve("/gitweb-logo.png").with(GitLogoServlet.class);
|
||||
serve("/gitweb.js").with(GitWebJavaScriptServlet.class);
|
||||
serve("/gitweb-default.css").with(GitWebCssServlet.Default.class);
|
||||
serve("/gitweb-site.css").with(GitWebCssServlet.Site.class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue