Merge changes Ifddb3dc7,I5870988e,Ic18ee3c0,I827716a8,I2540e902, ...
* changes:
Remove unused HttpServletRequest and HttpServletResponse parameters
Remove unnecessarily nested else blocks
DocServlet#fileTooBig: Remove unused parameter
Add missing serialVersionUIDs
Remove unused Logger instances
Format Java files with google-java-format 1.7
diff --git a/java/com/google/gitiles/DescribeServlet.java b/java/com/google/gitiles/DescribeServlet.java
index ebd2ea4..ae1d4c8 100644
--- a/java/com/google/gitiles/DescribeServlet.java
+++ b/java/com/google/gitiles/DescribeServlet.java
@@ -53,7 +53,7 @@
@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
- String name = describe(ServletUtils.getRepository(req), ViewFilter.getView(req), req, res);
+ String name = describe(ServletUtils.getRepository(req), ViewFilter.getView(req), req);
if (name == null) {
return;
}
@@ -64,7 +64,7 @@
@Override
protected void doGetJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
- String name = describe(ServletUtils.getRepository(req), ViewFilter.getView(req), req, res);
+ String name = describe(ServletUtils.getRepository(req), ViewFilter.getView(req), req);
if (name == null) {
return;
}
@@ -75,9 +75,7 @@
new TypeToken<Map<String, String>>() {}.getType());
}
- private ObjectId resolve(
- Repository repo, GitilesView view, HttpServletRequest req, HttpServletResponse res)
- throws IOException {
+ private ObjectId resolve(Repository repo, GitilesView view) throws IOException {
String rev = view.getPathPart();
try {
return repo.resolve(rev);
@@ -93,19 +91,18 @@
}
}
- private String describe(
- Repository repo, GitilesView view, HttpServletRequest req, HttpServletResponse res)
+ private String describe(Repository repo, GitilesView view, HttpServletRequest req)
throws IOException {
if (!getBooleanParam(view, CONTAINS_PARAM)) {
throw new GitilesRequestFailureException(FailureReason.INCORECT_PARAMETER);
}
- ObjectId id = resolve(repo, view, req, res);
+ ObjectId id = resolve(repo, view);
if (id == null) {
return null;
}
String name;
try (Git git = new Git(repo)) {
- NameRevCommand cmd = nameRevCommand(git, id, req, res);
+ NameRevCommand cmd = nameRevCommand(git, id, req);
if (cmd == null) {
return null;
}
@@ -119,8 +116,8 @@
return name;
}
- private NameRevCommand nameRevCommand(
- Git git, ObjectId id, HttpServletRequest req, HttpServletResponse res) throws IOException {
+ private NameRevCommand nameRevCommand(Git git, ObjectId id, HttpServletRequest req)
+ throws IOException {
GitilesView view = ViewFilter.getView(req);
NameRevCommand cmd = git.nameRev();
boolean all = getBooleanParam(view, ALL_PARAM);
diff --git a/java/com/google/gitiles/GitilesRequestFailureException.java b/java/com/google/gitiles/GitilesRequestFailureException.java
index 91f9cf8..316c023 100644
--- a/java/com/google/gitiles/GitilesRequestFailureException.java
+++ b/java/com/google/gitiles/GitilesRequestFailureException.java
@@ -87,6 +87,7 @@
* MyErrorHandlingFilter} will handle that. You can control how the error should be surfaced.
*/
public final class GitilesRequestFailureException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
private final FailureReason reason;
private String publicErrorMessage;
diff --git a/java/com/google/gitiles/GitwebRedirectFilter.java b/java/com/google/gitiles/GitwebRedirectFilter.java
index 324af72..0d0c74f 100644
--- a/java/com/google/gitiles/GitwebRedirectFilter.java
+++ b/java/com/google/gitiles/GitwebRedirectFilter.java
@@ -25,8 +25,8 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
-import com.google.gitiles.GitilesView.InvalidViewException;
import com.google.gitiles.GitilesRequestFailureException.FailureReason;
+import com.google.gitiles.GitilesView.InvalidViewException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
diff --git a/java/com/google/gitiles/HostIndexServlet.java b/java/com/google/gitiles/HostIndexServlet.java
index ce2ec6b..8b8a252 100644
--- a/java/com/google/gitiles/HostIndexServlet.java
+++ b/java/com/google/gitiles/HostIndexServlet.java
@@ -37,13 +37,10 @@
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Serves the top level index page for a Gitiles host. */
public class HostIndexServlet extends BaseServlet {
private static final long serialVersionUID = 1L;
- private static final Logger log = LoggerFactory.getLogger(HostIndexServlet.class);
protected final GitilesUrls urls;
@@ -54,8 +51,7 @@
}
private Map<String, RepositoryDescription> list(
- HttpServletRequest req, HttpServletResponse res, String prefix, Set<String> branches)
- throws IOException {
+ HttpServletRequest req, String prefix, Set<String> branches) throws IOException {
Map<String, RepositoryDescription> descs;
try {
descs = getAccess(req).listRepositories(prefix, branches);
@@ -88,8 +84,7 @@
GitilesView view = ViewFilter.getView(req);
String prefix = view.getRepositoryPrefix();
if (prefix != null) {
- Map<String, RepositoryDescription> descs =
- list(req, res, prefix, Collections.emptySet());
+ Map<String, RepositoryDescription> descs = list(req, prefix, Collections.emptySet());
if (descs == null) {
return;
}
@@ -111,7 +106,7 @@
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
String prefix = view.getRepositoryPrefix();
- Map<String, RepositoryDescription> descs = list(req, res, prefix, parseShowBranch(req));
+ Map<String, RepositoryDescription> descs = list(req, prefix, parseShowBranch(req));
if (descs == null) {
return;
}
@@ -148,7 +143,7 @@
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
String prefix = ViewFilter.getView(req).getRepositoryPrefix();
Set<String> branches = parseShowBranch(req);
- Map<String, RepositoryDescription> descs = list(req, res, prefix, branches);
+ Map<String, RepositoryDescription> descs = list(req, prefix, branches);
if (descs == null) {
return;
}
@@ -173,7 +168,7 @@
@Override
protected void doGetJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
String prefix = ViewFilter.getView(req).getRepositoryPrefix();
- Map<String, RepositoryDescription> descs = list(req, res, prefix, parseShowBranch(req));
+ Map<String, RepositoryDescription> descs = list(req, prefix, parseShowBranch(req));
if (descs == null) {
return;
}
diff --git a/java/com/google/gitiles/LogServlet.java b/java/com/google/gitiles/LogServlet.java
index 3523846..a91aeab 100644
--- a/java/com/google/gitiles/LogServlet.java
+++ b/java/com/google/gitiles/LogServlet.java
@@ -60,13 +60,10 @@
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Serves an HTML page with a shortlog for commits and paths. */
public class LogServlet extends BaseServlet {
private static final long serialVersionUID = 1L;
- private static final Logger log = LoggerFactory.getLogger(LogServlet.class);
static final String LIMIT_PARAM = "n";
static final String START_PARAM = "s";
diff --git a/java/com/google/gitiles/PathServlet.java b/java/com/google/gitiles/PathServlet.java
index dac38d3..34e0a76 100644
--- a/java/com/google/gitiles/PathServlet.java
+++ b/java/com/google/gitiles/PathServlet.java
@@ -60,14 +60,11 @@
import org.eclipse.jgit.util.QuotedString;
import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Serves an HTML page with detailed information about a path within a tree. */
// TODO(dborowitz): Handle non-UTF-8 names.
public class PathServlet extends BaseServlet {
private static final long serialVersionUID = 1L;
- private static final Logger log = LoggerFactory.getLogger(PathServlet.class);
static final String MODE_HEADER = "X-Gitiles-Path-Mode";
static final String TYPE_HEADER = "X-Gitiles-Object-Type";
diff --git a/java/com/google/gitiles/RevisionServlet.java b/java/com/google/gitiles/RevisionServlet.java
index 8bf661f..38aecb6 100644
--- a/java/com/google/gitiles/RevisionServlet.java
+++ b/java/com/google/gitiles/RevisionServlet.java
@@ -49,8 +49,6 @@
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Serves an HTML page with detailed information about a ref. */
public class RevisionServlet extends BaseServlet {
@@ -60,7 +58,6 @@
Field.setOf(CommitJsonData.DEFAULT_FIELDS, Field.DIFF_TREE);
private static final long serialVersionUID = 1L;
- private static final Logger log = LoggerFactory.getLogger(RevisionServlet.class);
private final Linkifier linkifier;
@@ -154,12 +151,11 @@
ObjectLoader loader = reader.open(view.getRevision().getId());
if (loader.getType() != OBJ_COMMIT) {
throw new GitilesRequestFailureException(FailureReason.UNSUPPORTED_OBJECT_TYPE);
- } else {
- PathServlet.setTypeHeader(res, loader.getType());
- try (Writer writer = startRenderText(req, res);
- OutputStream out = BaseEncoding.base64().encodingStream(writer)) {
- loader.copyTo(out);
- }
+ }
+ PathServlet.setTypeHeader(res, loader.getType());
+ try (Writer writer = startRenderText(req, res);
+ OutputStream out = BaseEncoding.base64().encodingStream(writer)) {
+ loader.copyTo(out);
}
}
}
diff --git a/java/com/google/gitiles/RootedDocServlet.java b/java/com/google/gitiles/RootedDocServlet.java
index bf72b32..8f021e6 100644
--- a/java/com/google/gitiles/RootedDocServlet.java
+++ b/java/com/google/gitiles/RootedDocServlet.java
@@ -33,12 +33,9 @@
import org.eclipse.jgit.transport.resolver.RepositoryResolver;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Serves Markdown at the root of a host. */
public class RootedDocServlet extends HttpServlet {
- private static final Logger log = LoggerFactory.getLogger(ViewFilter.class);
private static final long serialVersionUID = 1L;
public static final String BRANCH = "refs/heads/md-pages";
diff --git a/java/com/google/gitiles/ViewFilter.java b/java/com/google/gitiles/ViewFilter.java
index 590e583..f400ff0 100644
--- a/java/com/google/gitiles/ViewFilter.java
+++ b/java/com/google/gitiles/ViewFilter.java
@@ -28,12 +28,9 @@
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.http.server.ServletUtils;
import org.eclipse.jgit.http.server.glue.WrappedRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Filter to parse URLs and convert them to {@link GitilesView}s. */
public class ViewFilter extends AbstractHttpFilter {
- private static final Logger log = LoggerFactory.getLogger(ViewFilter.class);
// TODO(dborowitz): Make this public in JGit (or implement getRegexGroup
// upstream).
private static final String REGEX_GROUPS_ATTRIBUTE =
diff --git a/java/com/google/gitiles/blame/BlameServlet.java b/java/com/google/gitiles/blame/BlameServlet.java
index f1b9976..0bc061b 100644
--- a/java/com/google/gitiles/blame/BlameServlet.java
+++ b/java/com/google/gitiles/blame/BlameServlet.java
@@ -26,10 +26,10 @@
import com.google.gitiles.DateFormatter;
import com.google.gitiles.DateFormatter.Format;
import com.google.gitiles.GitilesAccess;
-import com.google.gitiles.GitilesView;
-import com.google.gitiles.Renderer;
import com.google.gitiles.GitilesRequestFailureException;
import com.google.gitiles.GitilesRequestFailureException.FailureReason;
+import com.google.gitiles.GitilesView;
+import com.google.gitiles.Renderer;
import com.google.gitiles.ViewFilter;
import com.google.gitiles.blame.cache.BlameCache;
import com.google.gitiles.blame.cache.Region;
@@ -75,7 +75,7 @@
try (RevWalk rw = new RevWalk(repo)) {
GitilesAccess access = getAccess(req);
- RegionResult result = getRegions(view, access, repo, rw, res);
+ RegionResult result = getRegions(view, access, repo, rw);
if (result == null) {
return;
}
@@ -117,7 +117,7 @@
Repository repo = ServletUtils.getRepository(req);
try (RevWalk rw = new RevWalk(repo)) {
- RegionResult result = getRegions(view, getAccess(req), repo, rw, res);
+ RegionResult result = getRegions(view, getAccess(req), repo, rw);
if (result == null) {
return;
}
@@ -155,8 +155,7 @@
}
private RegionResult getRegions(
- GitilesView view, GitilesAccess access, Repository repo, RevWalk rw, HttpServletResponse res)
- throws IOException {
+ GitilesView view, GitilesAccess access, Repository repo, RevWalk rw) throws IOException {
RevCommit currCommit = rw.parseCommit(view.getRevision().getId());
ObjectId currCommitBlobId = resolveBlob(view, rw, currCommit);
if (currCommitBlobId == null) {
diff --git a/java/com/google/gitiles/doc/DocServlet.java b/java/com/google/gitiles/doc/DocServlet.java
index 509f460..ca83ae0 100644
--- a/java/com/google/gitiles/doc/DocServlet.java
+++ b/java/com/google/gitiles/doc/DocServlet.java
@@ -14,8 +14,6 @@
package com.google.gitiles.doc;
-import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
-import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.eclipse.jgit.lib.FileMode.TYPE_FILE;
@@ -30,10 +28,10 @@
import com.google.common.net.HttpHeaders;
import com.google.gitiles.BaseServlet;
import com.google.gitiles.GitilesAccess;
+import com.google.gitiles.GitilesRequestFailureException;
+import com.google.gitiles.GitilesRequestFailureException.FailureReason;
import com.google.gitiles.GitilesView;
import com.google.gitiles.Renderer;
-import com.google.gitiles.GitilesRequestFailureException.FailureReason;
-import com.google.gitiles.GitilesRequestFailureException;
import com.google.gitiles.ViewFilter;
import com.google.gitiles.doc.html.StreamHtmlBuilder;
import java.io.IOException;
@@ -55,11 +53,8 @@
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class DocServlet extends BaseServlet {
- private static final Logger log = LoggerFactory.getLogger(DocServlet.class);
private static final long serialVersionUID = 1L;
private static final String INDEX_MD = "index.md";
@@ -121,8 +116,8 @@
if (navmd != null) {
navmd.read(reader, cfg);
}
- } catch (LargeObjectException.ExceedsLimit errBig) {
- fileTooBig(res, view, errBig);
+ } catch (LargeObjectException.ExceedsLimit e) {
+ fileTooBig(res, view);
return;
}
@@ -272,14 +267,11 @@
return false;
}
- private static void fileTooBig(
- HttpServletResponse res, GitilesView view, LargeObjectException.ExceedsLimit errBig)
- throws IOException {
+ private static void fileTooBig(HttpServletResponse res, GitilesView view) throws IOException {
if (view.getType() == GitilesView.Type.ROOTED_DOC) {
throw new GitilesRequestFailureException(FailureReason.OBJECT_TOO_LARGE);
- } else {
- res.sendRedirect(GitilesView.show().copyFrom(view).toUrl());
}
+ res.sendRedirect(GitilesView.show().copyFrom(view).toUrl());
}
private static class MarkdownFile {
diff --git a/javatests/com/google/gitiles/DefaultErrorHandlingFilterTest.java b/javatests/com/google/gitiles/DefaultErrorHandlingFilterTest.java
index 6832658..b96e43d 100644
--- a/javatests/com/google/gitiles/DefaultErrorHandlingFilterTest.java
+++ b/javatests/com/google/gitiles/DefaultErrorHandlingFilterTest.java
@@ -35,6 +35,8 @@
}
private static class TestServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) {
throw new GitilesRequestFailureException(FailureReason.INCORECT_PARAMETER);
diff --git a/javatests/com/google/gitiles/ViewFilterTest.java b/javatests/com/google/gitiles/ViewFilterTest.java
index d25b6cf..66cd5d8 100644
--- a/javatests/com/google/gitiles/ViewFilterTest.java
+++ b/javatests/com/google/gitiles/ViewFilterTest.java
@@ -251,7 +251,8 @@
assertThat(view.getRevision().getId()).isEqualTo(master);
assertThat(view.getPathPart()).isEqualTo("foo/bar");
- assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+show/stable..master/foo"));
+ assertThrows(
+ GitilesRequestFailureException.class, () -> getView("/repo/+show/stable..master/foo"));
}
@Test
@@ -280,7 +281,8 @@
assertThat(view.getRevision().getId()).isEqualTo(master);
assertThat(view.getPathPart()).isEqualTo("foo/bar.md");
- assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+doc/stable..master/foo"));
+ assertThrows(
+ GitilesRequestFailureException.class, () -> getView("/repo/+doc/stable..master/foo"));
}
@Test
@@ -290,7 +292,8 @@
assertThat(getView("//repo").getType()).isEqualTo(Type.REPOSITORY_INDEX);
assertThat(getView("//repo//").getType()).isEqualTo(Type.REPOSITORY_INDEX);
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+//master"));
- assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+/refs//heads//master"));
+ assertThrows(
+ GitilesRequestFailureException.class, () -> getView("/repo/+/refs//heads//master"));
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+//master//"));
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+//master/foo//bar"));
}
@@ -423,11 +426,14 @@
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+archive"));
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+archive/"));
- assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+archive/master..branch"));
+ assertThrows(
+ GitilesRequestFailureException.class, () -> getView("/repo/+archive/master..branch"));
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+archive/master.foo"));
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+archive/master.zip"));
- assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+archive/master/.tar.gz"));
- assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+archive/master/foo/.tar.gz"));
+ assertThrows(
+ GitilesRequestFailureException.class, () -> getView("/repo/+archive/master/.tar.gz"));
+ assertThrows(
+ GitilesRequestFailureException.class, () -> getView("/repo/+archive/master/foo/.tar.gz"));
view = getView("/repo/+archive/master.tar.gz");
assertThat(view.getType()).isEqualTo(Type.ARCHIVE);
@@ -466,7 +472,8 @@
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+blame"));
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+blame/"));
assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+blame/master"));
- assertThrows(GitilesRequestFailureException.class, () -> getView("/repo/+blame/master..branch"));
+ assertThrows(
+ GitilesRequestFailureException.class, () -> getView("/repo/+blame/master..branch"));
view = getView("/repo/+blame/master/foo/bar");
assertThat(view.getType()).isEqualTo(Type.BLAME);