Merge branch 'stable-2.13'

* stable-2.13:
  Doc: Update path to jar file in build.md

Change-Id: I57540c37995c645d9a1e075775dd199cc6cd3391
diff --git a/.buckconfig b/.buckconfig
deleted file mode 100644
index b606c45..0000000
--- a/.buckconfig
+++ /dev/null
@@ -1,14 +0,0 @@
-[alias]
-  gitiles = //:gitiles
-  plugin = //:gitiles
-
-[java]
-  src_roots = java, resources
-
-[project]
-  ignore = .git
-
-[cache]
-  mode = dir
-  dir = buck-out/cache
-
diff --git a/BUCK b/BUCK
deleted file mode 100644
index d81cf11..0000000
--- a/BUCK
+++ /dev/null
@@ -1,174 +0,0 @@
-include_defs('//bucklets/gerrit_plugin.bucklet')
-include_defs('//bucklets/maven_jar.bucklet')
-
-define_license('commonmark')
-define_license('autolink')
-
-genrule(
-  name = 'gitiles',
-  cmd = ' && '.join([
-    'cp $(location :gitiles__base) $OUT',
-    'unzip -qd $TMP $(location :gitiles-servlet) "com/google/gitiles/static/*"',
-    'cd $TMP/com/google/gitiles',
-    'mv static +static',
-    'zip -Drq $OUT -g . -i "+static/*"',
-  ]),
-  visibility = ['PUBLIC'],
-  out = 'gitiles.jar',
-)
-
-gerrit_plugin(
-  name = 'gitiles',
-  srcs = glob(['src/main/java/**/*.java']),
-  deps = [
-    ':gitiles-servlet',
-
-    # Deps only needed by Gitiles.
-    ':commons-lang3',
-    ':guice-multibindings',
-    ':nullable-jsr305',
-    ':soy',
-    ':commonmark',
-    ':cm-autolink',
-    ':gfm-tables',
-    ':gfm-strikethrough',
-
-  ],
-  resources = glob(['src/main/resources/**/*']),
-  manifest_entries = [
-    'Gerrit-PluginName: gitiles',
-    'Gerrit-Module: com.googlesource.gerrit.plugins.gitiles.Module',
-    'Gerrit-HttpModule: com.googlesource.gerrit.plugins.gitiles.HttpModule',
-
-    # Gitiles uses /repo to access a repo, so the default plugin layout would
-    # disallow repos named "static" or "Documentation". Paths starting with +
-    # are reserved by Gitiles and can't match repos.
-    'Gerrit-HttpStaticPrefix: +static',
-    'Gerrit-HttpDocumentationPrefix: +Documentation',
-  ],
-  visibility = [],
-  target_suffix = '__base'
-)
-
-java_library(
-  name = 'classpath',
-  deps = [':gitiles__plugin'],
-)
-
-maven_jar(
-  name = 'gitiles-servlet',
-  id = 'com.google.gitiles:gitiles-servlet:0.1-11',
-  sha1 = 'c8fe6a48472a51607103a4b10214867bcc1c63f5',
-  deps = [':prettify'],
-  license = 'Apache2.0',
-  repository = GERRIT,
-  visibility = [],
-)
-
-# prettify must match the version used in Gitiles
-maven_jar(
-  name = 'prettify',
-  id = 'prettify:java-prettify:1.2.1',
-  sha1 = '29ad8d072f9d0b83d1a2e9aa6ccb0905e6d543c6',
-  license = 'Apache2.0',
-  repository = GERRIT,
-  visibility = [],
-)
-
-maven_jar(
-  name = 'commons-lang3',
-  id = 'org.apache.commons:commons-lang3:3.1',
-  sha1 = '905075e6c80f206bbe6cf1e809d2caa69f420c76',
-  license = 'Apache2.0',
-  visibility = [],
-)
-
-# soy version must match version used in Gitiles
-maven_jar(
-  name = 'soy',
-  id = 'com.google.template:soy:2015-04-10',
-  sha1 = 'f2a260c0eafbc5756ccec546efd2ffd5b0a583cb',
-  deps = [':icu4j'],
-  license = 'Apache2.0',
-  visibility = [],
-)
-
-maven_jar(
-  name = 'icu4j',
-  id = 'com.ibm.icu:icu4j:51.1',
-  sha1 = '8ce396c4aed83c0c3de9158dc72c834fd283d5a4',
-  license = 'Apache2.0',
-)
-
-# guice-multibindings must match Guice version used in Gerrit
-maven_jar(
-  name = 'guice-multibindings',
-  id = 'com.google.inject.extensions:guice-multibindings:4.0',
-  sha1 = 'f4509545b4470bbcc865aa500ad6fef2e97d28bf',
-  license = 'Apache2.0',
-  exclude_java_sources = True,
-  exclude = [
-    'META-INF/DEPENDENCIES',
-    'META-INF/LICENSE',
-    'META-INF/NOTICE',
-    'META-INF/maven/com.google.guava/guava/pom.properties',
-    'META-INF/maven/com.google.guava/guava/pom.xml',
-  ],
-  visibility = [],
-)
-
-maven_jar(
-  name = 'nullable-jsr305',
-  id = 'com.google.code.findbugs:jsr305:3.0.0',
-  sha1 = '5871fb60dc68d67da54a663c3fd636a10a532948',
-  license = 'Apache2.0',
-  exclude_java_sources = True,
-  visibility = [],
-)
-
-COMMONMARK_VERSION = '0.6.0'
-maven_jar(
-  name = 'commonmark',
-  id = 'com.atlassian.commonmark:commonmark:' + COMMONMARK_VERSION,
-  sha1 = '5df3f6fa3073966620685924aa22d08ece7213f2',
-  license = 'commonmark',
-  local_license = True,
-)
-
-maven_jar(
-  name = 'cm-autolink',
-  id = 'com.atlassian.commonmark:commonmark-ext-autolink:' + COMMONMARK_VERSION,
-  sha1 = '4d7e828a4651e2f590b4a059925991be58e62da6',
-  license = 'commonmark',
-  local_license = True,
-  deps = [
-    ':commonmark',
-    ':autolink',
-  ],
-  )
-
-maven_jar(
-  name = 'autolink',
-  id = 'org.nibor.autolink:autolink:0.4.0',
-  sha1 = '764f7b0147a0675d971a34282dce9ec76b8307c9',
-  license = 'autolink',
-  local_license = True,
-)
-
-maven_jar(
-  name = 'gfm-strikethrough',
-  id = 'com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:' + COMMONMARK_VERSION,
-  sha1 = '75a95aaec77810496de41239bcc773adfb13285f',
-  license = 'commonmark',
-  local_license = True,
-  deps = [':commonmark'],
-)
-
-maven_jar(
-  name = 'gfm-tables',
-  id = 'com.atlassian.commonmark:commonmark-ext-gfm-tables:' + COMMONMARK_VERSION,
-  sha1 = 'ae1c701517e8116bc205b561b9b215a53df8abc7',
-  license = 'commonmark',
-  local_license = True,
-  deps = [':commonmark'],
-)
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..b5c7a38
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,46 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+genrule(
+    name = "gitiles",
+    srcs = [
+        ":gitiles__base",
+        "@gitiles_servlet//jar",
+    ],
+    outs = ["gitiles.jar"],
+    cmd = " && ".join([
+        "ROOT=$$PWD",
+        "TMP=$$(mktemp -d || mktemp -d -t bazel-tmp)",
+        "cp $(location :gitiles__base) $@",
+        "chmod +w $@",
+        "unzip -qd $$TMP $(location @gitiles_servlet//jar) \"com/google/gitiles/static/*\"",
+        "cd $$TMP/com/google/gitiles",
+        "mv static +static",
+        "zip -Drq $$ROOT/$@ -g . -i \"+static/*\"",
+    ]),
+)
+
+gerrit_plugin(
+    name = "gitiles",
+    srcs = glob(["src/main/java/**/*.java"]),
+    manifest_entries = [
+        "Gerrit-PluginName: gitiles",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.gitiles.Module",
+        "Gerrit-HttpModule: com.googlesource.gerrit.plugins.gitiles.HttpModule",
+        # Gitiles uses /repo to access a repo, so the default plugin layout would
+        # disallow repos named "static" or "Documentation". Paths starting with +
+        # are reserved by Gitiles and can't match repos.
+        "Gerrit-HttpStaticPrefix: +static",
+        "Gerrit-HttpDocumentationPrefix: +Documentation",
+    ],
+    resources = glob(["src/main/resources/**/*"]),
+    target_suffix = "__base",
+    deps = [
+        "@autolink//jar",
+        "@cm_autolink//jar",
+        "@commonmark//jar",
+        "@gfm_strikethrough//jar",
+        "@gfm_tables//jar",
+        "@gitiles_servlet//jar",
+        "@prettify//jar",
+    ],
+)
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
new file mode 100644
index 0000000..94464da
--- /dev/null
+++ b/external_plugin_deps.bzl
@@ -0,0 +1,49 @@
+load("//tools/bzl:maven_jar.bzl", "maven_jar", "GERRIT", "MAVEN_CENTRAL")
+
+COMMONMARK_VERSION = '0.6.0'
+
+def external_plugin_deps():
+  maven_jar(
+    name = 'gitiles_servlet',
+    artifact = 'com.google.gitiles:gitiles-servlet:0.2',
+    sha1 = 'e5530e0c53e24aa814c7f83de644be0ae1cbc193',
+    repository = GERRIT,
+  )
+
+  # prettify must match the version used in Gitiles
+  maven_jar(
+    name = 'prettify',
+    artifact = 'prettify:java-prettify:1.2.1',
+    sha1 = '29ad8d072f9d0b83d1a2e9aa6ccb0905e6d543c6',
+    repository = GERRIT,
+  )
+
+  maven_jar(
+    name = 'commonmark',
+    artifact = 'com.atlassian.commonmark:commonmark:' + COMMONMARK_VERSION,
+    sha1 = '5df3f6fa3073966620685924aa22d08ece7213f2',
+  )
+
+  maven_jar(
+    name = 'cm_autolink',
+    artifact = 'com.atlassian.commonmark:commonmark-ext-autolink:' + COMMONMARK_VERSION,
+    sha1 = '4d7e828a4651e2f590b4a059925991be58e62da6',
+  )
+
+  maven_jar(
+    name = 'autolink',
+    artifact = 'org.nibor.autolink:autolink:0.4.0',
+    sha1 = '764f7b0147a0675d971a34282dce9ec76b8307c9',
+  )
+
+  maven_jar(
+    name = 'gfm_strikethrough',
+    artifact = 'com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:' + COMMONMARK_VERSION,
+    sha1 = '75a95aaec77810496de41239bcc773adfb13285f',
+  )
+
+  maven_jar(
+    name = 'gfm_tables',
+    artifact = 'com.atlassian.commonmark:commonmark-ext-gfm-tables:' + COMMONMARK_VERSION,
+    sha1 = 'ae1c701517e8116bc205b561b9b215a53df8abc7',
+  )
diff --git a/lib/gerrit/BUCK b/lib/gerrit/BUCK
deleted file mode 100644
index a7ab54e..0000000
--- a/lib/gerrit/BUCK
+++ /dev/null
@@ -1,13 +0,0 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
-VER = '2.13'
-REPO = MAVEN_CENTRAL
-
-maven_jar(
-  name = 'plugin-api',
-  id = 'com.google.gerrit:gerrit-plugin-api:' + VER,
-  sha1 = 'e25d55b8f41627c4ae6b9d2069ec398638b219a3',
-  attach_source = False,
-  repository = REPO,
-  license = 'Apache2.0',
-)
diff --git a/lib/jgit/BUCK b/lib/jgit/BUCK
deleted file mode 100644
index 01dc375..0000000
--- a/lib/jgit/BUCK
+++ /dev/null
@@ -1,41 +0,0 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
-REPO = MAVEN_CENTRAL # Leave here even if set to MAVEN_CENTRAL.
-VERS = '4.5.0.201609210915-r'
-
-maven_jar(
-  name = 'jgit',
-  id = 'org.eclipse.jgit:org.eclipse.jgit:' + VERS,
-  bin_sha1 = '3e3d0b73dcf4ad649f37758ea8502d92f3d299de',
-  src_sha1 = 'fc352952db91a4046e4b832145eb2dc8afce8db1',
-  license = 'jgit',
-  repository = REPO,
-  unsign = True,
-  deps = [':ewah'],
-  exclude = [
-    'META-INF/eclipse.inf',
-    'about.html',
-    'plugin.properties',
-  ],
-)
-
-maven_jar(
-  name = 'jgit-servlet',
-  id = 'org.eclipse.jgit:org.eclipse.jgit.http.server:' + VERS,
-  sha1 = '6e36638888918d9941dddec7e2abe1f162cc74d9',
-  license = 'jgit',
-  repository = REPO,
-  deps = [':jgit'],
-  unsign = True,
-  exclude = [
-    'about.html',
-    'plugin.properties',
-  ],
-)
-
-maven_jar(
-  name = 'ewah',
-  id = 'com.googlecode.javaewah:JavaEWAH:0.7.9',
-  sha1 = 'eceaf316a8faf0e794296ebe158ae110c7d72a5a',
-  license = 'Apache2.0',
-)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
index 098910c..de023e0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
@@ -21,15 +21,17 @@
 import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.git.GitRepositoryManager;
+import com.google.gerrit.server.git.SearchingChangeCacheImpl;
 import com.google.gerrit.server.git.TagCache;
 import com.google.gerrit.server.git.VisibleRefFilter;
-import com.google.gerrit.server.git.SearchingChangeCacheImpl;
 import com.google.gerrit.server.notedb.ChangeNotes;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.project.ProjectControl;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
-
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
 import org.eclipse.jgit.attributes.AttributesNodeProvider;
 import org.eclipse.jgit.lib.ObjectDatabase;
 import org.eclipse.jgit.lib.Ref;
@@ -41,10 +43,6 @@
 import org.eclipse.jgit.lib.RepositoryBuilder;
 import org.eclipse.jgit.lib.StoredConfig;
 
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
 class FilteredRepository extends Repository {
   static class Factory {
     private final Provider<ReviewDb> db;
@@ -56,7 +54,8 @@
     private final SearchingChangeCacheImpl changeCache;
 
     @Inject
-    Factory(Provider<ReviewDb> db,
+    Factory(
+        Provider<ReviewDb> db,
         ProjectControl.GenericFactory projectControlFactory,
         Provider<CurrentUser> userProvider,
         GitRepositoryManager repoManager,
@@ -72,24 +71,24 @@
       this.changeCache = changeCache;
     }
 
-    FilteredRepository create(Project.NameKey name)
-        throws NoSuchProjectException, IOException {
+    FilteredRepository create(Project.NameKey name) throws NoSuchProjectException, IOException {
       ProjectControl ctl = projectControlFactory.controlFor(name, userProvider.get());
       if (!ctl.isVisible()) {
         throw new NoSuchProjectException(name);
       }
       Repository repo = repoManager.openRepository(name);
-      return new FilteredRepository(ctl, repo,
-          new VisibleRefFilter(tagCache, changeNotesFactory, changeCache, repo,
-              ctl, db.get(), true));
+      return new FilteredRepository(
+          ctl,
+          repo,
+          new VisibleRefFilter(
+              tagCache, changeNotesFactory, changeCache, repo, ctl, db.get(), true));
     }
   }
 
   private final Repository delegate;
   private final RefDatabase refdb;
 
-  private FilteredRepository(ProjectControl ctl, Repository delegate,
-      VisibleRefFilter refFilter) {
+  private FilteredRepository(ProjectControl ctl, Repository delegate, VisibleRefFilter refFilter) {
     super(toBuilder(delegate));
     this.delegate = delegate;
     if (ctl.allRefsAreVisible()) {
@@ -100,8 +99,8 @@
   }
 
   private static RepositoryBuilder toBuilder(Repository repo) {
-    RepositoryBuilder b = new RepositoryBuilder().setGitDir(repo.getDirectory())
-      .setFS(repo.getFS());
+    RepositoryBuilder b =
+        new RepositoryBuilder().setGitDir(repo.getDirectory()).setFS(repo.getFS());
     if (!repo.isBare()) {
       b.setWorkTree(repo.getWorkTree()).setIndexFile(repo.getIndexFile());
     }
@@ -185,8 +184,7 @@
     }
 
     @Override
-    public RefRename newRename(String fromName, String toName)
-        throws IOException {
+    public RefRename newRename(String fromName, String toName) throws IOException {
       throw new UnsupportedOperationException(); // Gitiles is read-only.
     }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
index d7af64e..4e7e612 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
@@ -31,18 +31,15 @@
 import com.google.gitiles.RepositoryDescription;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
-
-import org.eclipse.jgit.errors.RepositoryNotFoundException;
-import org.eclipse.jgit.lib.Config;
-import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
-import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
-
 import java.io.IOException;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
-
 import javax.servlet.http.HttpServletRequest;
+import org.eclipse.jgit.errors.RepositoryNotFoundException;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
+import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
 
 class GerritGitilesAccess implements GitilesAccess {
   // Assisted injection doesn't work with the overridden method, so write the
@@ -56,7 +53,8 @@
     private final String anonymousCowardName;
 
     @Inject
-    Factory(ProjectCache projectCache,
+    Factory(
+        ProjectCache projectCache,
         ProjectJson projectJson,
         Provider<ListProjects> listProjects,
         GitilesUrls urls,
@@ -97,8 +95,8 @@
 
   @Override
   public Map<String, RepositoryDescription> listRepositories(
-      @Nullable String prefix, Set<String> branches) throws ServiceNotEnabledException,
-      ServiceNotAuthorizedException, IOException  {
+      @Nullable String prefix, Set<String> branches)
+      throws ServiceNotEnabledException, ServiceNotAuthorizedException, IOException {
     ListProjects lp = listProjects.get();
     lp.setShowDescription(true);
     lp.setAll(true);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GitilesWeblinks.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GitilesWeblinks.java
index 5933929..4ec8a2d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GitilesWeblinks.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GitilesWeblinks.java
@@ -14,62 +14,77 @@
 
 package com.googlesource.gerrit.plugins.gitiles;
 
+import com.google.common.base.MoreObjects;
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.common.WebLinkInfo;
 import com.google.gerrit.extensions.webui.BranchWebLink;
 import com.google.gerrit.extensions.webui.FileHistoryWebLink;
 import com.google.gerrit.extensions.webui.FileWebLink;
+import com.google.gerrit.extensions.webui.ParentWebLink;
 import com.google.gerrit.extensions.webui.PatchSetWebLink;
 import com.google.gerrit.extensions.webui.ProjectWebLink;
 import com.google.gerrit.server.config.PluginConfigFactory;
 import com.google.inject.Inject;
-import com.google.common.base.MoreObjects;
-
 import org.eclipse.jgit.lib.Config;
 
-public class GitilesWeblinks implements BranchWebLink, FileWebLink,
-    PatchSetWebLink, ProjectWebLink, FileHistoryWebLink {
+public class GitilesWeblinks
+    implements BranchWebLink,
+        FileWebLink,
+        PatchSetWebLink,
+        ProjectWebLink,
+        FileHistoryWebLink,
+        ParentWebLink {
   private final String name;
   private final String baseUrl;
+  private final String target;
 
   @Inject
-  public GitilesWeblinks(@PluginName String pluginName,
-                         PluginConfigFactory configFactory) {
+  public GitilesWeblinks(@PluginName String pluginName, PluginConfigFactory configFactory) {
     Config config = configFactory.getGlobalPluginConfig("gitiles");
-    name = MoreObjects.firstNonNull(
-                          config.getString("gerrit", null, "linkname"),
-                          "browse");
+    name = MoreObjects.firstNonNull(config.getString("gerrit", null, "linkname"), "browse");
     baseUrl = "plugins/" + pluginName;
+
+    target = MoreObjects.firstNonNull(config.getString("gerrit", null, "target"), Target.BLANK);
   }
 
   @Override
   public WebLinkInfo getProjectWeblink(String projectName) {
-    return new WebLinkInfo(name, null, String.format("%s/%s", baseUrl,
-        projectName), Target.BLANK);
+    return new WebLinkInfo(name, null, String.format("%s/%s", baseUrl, projectName), target);
   }
 
   @Override
   public WebLinkInfo getPatchSetWebLink(String projectName, String commit) {
-    return new WebLinkInfo(name, null, String.format("%s/%s/+/%s", baseUrl,
-        projectName, commit), Target.BLANK);
+    return new WebLinkInfo(
+        name, null, String.format("%s/%s/+/%s", baseUrl, projectName, commit), target);
   }
 
   @Override
-  public WebLinkInfo getFileWebLink(String projectName, String revision,
-      String fileName) {
-    return new WebLinkInfo(name, null, String.format("%s/%s/+/%s/%s", baseUrl,
-        projectName, revision, fileName), Target.BLANK);
+  public WebLinkInfo getParentWebLink(String projectName, String commit) {
+    return new WebLinkInfo(
+        name, null, String.format("%s/%s/+/%s", baseUrl, projectName, commit), target);
+  }
+
+  @Override
+  public WebLinkInfo getFileWebLink(String projectName, String revision, String fileName) {
+    return new WebLinkInfo(
+        name,
+        null,
+        String.format("%s/%s/+/%s/%s", baseUrl, projectName, revision, fileName),
+        target);
   }
 
   @Override
   public WebLinkInfo getBranchWebLink(String projectName, String branchName) {
-    return new WebLinkInfo(name, null, String.format("%s/%s/+/%s", baseUrl,
-        projectName, branchName), Target.BLANK);
+    return new WebLinkInfo(
+        name, null, String.format("%s/%s/+/%s", baseUrl, projectName, branchName), target);
   }
 
   @Override
   public WebLinkInfo getFileHistoryWebLink(String projectName, String revision, String fileName) {
-    return new WebLinkInfo(name, null, String.format("%s/%s/+log/%s/%s", baseUrl,
-        projectName, revision, fileName), Target.BLANK);
+    return new WebLinkInfo(
+        name,
+        null,
+        String.format("%s/%s/+log/%s/%s", baseUrl, projectName, revision, fileName),
+        target);
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
index c1163cf..9402bf4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
@@ -26,20 +26,10 @@
 import com.google.inject.Singleton;
 import com.google.inject.name.Named;
 import com.google.inject.servlet.ServletModule;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-import org.eclipse.jgit.lib.Config;
-import org.eclipse.jgit.storage.file.FileBasedConfig;
-import org.eclipse.jgit.transport.resolver.RepositoryResolver;
-import org.eclipse.jgit.util.FS;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
-
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -48,6 +38,13 @@
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.transport.resolver.RepositoryResolver;
+import org.eclipse.jgit.util.FS;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 class HttpModule extends ServletModule {
   private final Provider<CurrentUser> userProvider;
@@ -62,8 +59,8 @@
   protected Filter createPathFilter() {
     return new Filter() {
       @Override
-      public void doFilter(ServletRequest request, ServletResponse response,
-          FilterChain chain) throws IOException, ServletException {
+      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+          throws IOException, ServletException {
         HttpServletRequestWrapper wrappedRequest =
             new HttpServletRequestWrapper((HttpServletRequest) request) {
               @Override
@@ -89,8 +86,7 @@
     };
   }
 
-  private static final Logger log = LoggerFactory
-      .getLogger(HttpModule.class);
+  private static final Logger log = LoggerFactory.getLogger(HttpModule.class);
 
   @Override
   protected void configureServlets() {
@@ -109,11 +105,14 @@
 
   @Provides
   @Singleton
-  GitilesServlet getServlet(@Named("gitiles") Config cfg, GitilesUrls urls,
+  GitilesServlet getServlet(
+      @Named("gitiles") Config cfg,
+      GitilesUrls urls,
       GitilesAccess.Factory accessFactory,
       RepositoryResolver<HttpServletRequest> resolver,
       MenuFilter menuFilter) {
-    GitilesServlet s = new GitilesServlet(cfg, null, urls, accessFactory, resolver, null, null, null, null);
+    GitilesServlet s =
+        new GitilesServlet(cfg, null, urls, accessFactory, resolver, null, null, null, null);
     for (GitilesView.Type view : GitilesView.Type.values()) {
       s.addFilter(view, menuFilter);
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/LoginFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/LoginFilter.java
index 42d1837..7009f1a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/LoginFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/LoginFilter.java
@@ -20,9 +20,7 @@
 import com.google.gitiles.GitilesUrls;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
-
 import java.io.IOException;
-
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -44,40 +42,39 @@
   }
 
   @Override
-  public void doFilter(ServletRequest request, ServletResponse response,
-      FilterChain chain) throws IOException, ServletException {
+  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+      throws IOException, ServletException {
     final HttpServletRequest req = (HttpServletRequest) request;
-    HttpServletResponseWrapper rsp = new HttpServletResponseWrapper((HttpServletResponse) response) {
-      @Override
-      public void sendError(int sc) throws IOException {
-        CurrentUser user = userProvider.get();
-        if (sc == SC_UNAUTHORIZED && !(user instanceof IdentifiedUser)) {
-          sendRedirect(getLoginRedirectUrl(req));
-          return;
-        }
-        super.sendError(sc);
-      }
+    HttpServletResponseWrapper rsp =
+        new HttpServletResponseWrapper((HttpServletResponse) response) {
+          @Override
+          public void sendError(int sc) throws IOException {
+            CurrentUser user = userProvider.get();
+            if (sc == SC_UNAUTHORIZED && !(user instanceof IdentifiedUser)) {
+              sendRedirect(getLoginRedirectUrl(req));
+              return;
+            }
+            super.sendError(sc);
+          }
 
-      @Override
-      public void sendError(int sc, String msg) throws IOException {
-        CurrentUser user = userProvider.get();
-        if (sc == SC_UNAUTHORIZED && !(user instanceof IdentifiedUser)) {
-          sendRedirect(getLoginRedirectUrl(req));
-          return;
-        }
-        super.sendError(sc, msg);
-      }
-    };
+          @Override
+          public void sendError(int sc, String msg) throws IOException {
+            CurrentUser user = userProvider.get();
+            if (sc == SC_UNAUTHORIZED && !(user instanceof IdentifiedUser)) {
+              sendRedirect(getLoginRedirectUrl(req));
+              return;
+            }
+            super.sendError(sc, msg);
+          }
+        };
     chain.doFilter(request, rsp);
   }
 
   @Override
-  public void init(FilterConfig filterConfig) throws ServletException {
-  }
+  public void init(FilterConfig filterConfig) throws ServletException {}
 
   @Override
-  public void destroy() {
-  }
+  public void destroy() {}
 
   private String getLoginRedirectUrl(HttpServletRequest req) {
     String baseUrl = urls.getBaseGerritUrl(req);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
index 76e3584..058dd2b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
@@ -21,10 +21,8 @@
 import com.google.gitiles.GitilesUrls;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
-
 import java.io.IOException;
 import java.util.List;
-
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -44,30 +42,25 @@
   }
 
   @Override
-  public void doFilter(ServletRequest request, ServletResponse response,
-      FilterChain chain) throws IOException, ServletException {
+  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+      throws IOException, ServletException {
     HttpServletRequest req = (HttpServletRequest) request;
     CurrentUser user = userProvider.get();
     List<Object> entries = Lists.newArrayListWithCapacity(3);
     entries.add(BaseServlet.menuEntry("Code Review", urls.getBaseGerritUrl(req)));
     if (user instanceof IdentifiedUser) {
-      entries
-          .add(BaseServlet.menuEntry(((IdentifiedUser) user).getName(), null));
-      entries.add(BaseServlet.menuEntry("Sign Out", urls.getBaseGerritUrl(req)
-          + "logout"));
+      entries.add(BaseServlet.menuEntry(((IdentifiedUser) user).getName(), null));
+      entries.add(BaseServlet.menuEntry("Sign Out", urls.getBaseGerritUrl(req) + "logout"));
     } else {
-      entries.add(BaseServlet.menuEntry("Sign In", urls.getBaseGerritUrl(req)
-          + "login"));
+      entries.add(BaseServlet.menuEntry("Sign In", urls.getBaseGerritUrl(req) + "login"));
     }
     BaseServlet.putSoyData(req, "menuEntries", entries);
     chain.doFilter(request, response);
   }
 
   @Override
-  public void init(FilterConfig filterConfig) throws ServletException {
-  }
+  public void init(FilterConfig filterConfig) throws ServletException {}
 
   @Override
-  public void destroy() {
-  }
+  public void destroy() {}
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
index 82ded08..343e716 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
@@ -20,6 +20,7 @@
 import com.google.gerrit.extensions.webui.BranchWebLink;
 import com.google.gerrit.extensions.webui.FileHistoryWebLink;
 import com.google.gerrit.extensions.webui.FileWebLink;
+import com.google.gerrit.extensions.webui.ParentWebLink;
 import com.google.gerrit.extensions.webui.PatchSetWebLink;
 import com.google.gerrit.extensions.webui.ProjectWebLink;
 import com.google.gerrit.lifecycle.LifecycleModule;
@@ -34,17 +35,14 @@
 import com.google.inject.ProvisionException;
 import com.google.inject.Singleton;
 import com.google.inject.TypeLiteral;
-
-import org.eclipse.jgit.lib.Config;
-import org.eclipse.jgit.transport.resolver.RepositoryResolver;
-
 import java.net.InetAddress;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.List;
-
 import javax.servlet.http.HttpServletRequest;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.transport.resolver.RepositoryResolver;
 
 class Module extends LifecycleModule {
   @Override
@@ -52,6 +50,7 @@
     DynamicSet.bind(binder(), BranchWebLink.class).to(GitilesWeblinks.class);
     DynamicSet.bind(binder(), FileHistoryWebLink.class).to(GitilesWeblinks.class);
     DynamicSet.bind(binder(), FileWebLink.class).to(GitilesWeblinks.class);
+    DynamicSet.bind(binder(), ParentWebLink.class).to(GitilesWeblinks.class);
     DynamicSet.bind(binder(), PatchSetWebLink.class).to(GitilesWeblinks.class);
     DynamicSet.bind(binder(), ProjectWebLink.class).to(GitilesWeblinks.class);
     bind(GitilesAccess.Factory.class).to(GerritGitilesAccess.Factory.class);
@@ -60,7 +59,8 @@
   }
 
   @Provides
-  GitilesUrls getGitilesUrls(@GerritServerConfig Config gerritConfig,
+  GitilesUrls getGitilesUrls(
+      @GerritServerConfig Config gerritConfig,
       @Nullable @CanonicalWebUrl String gerritUrl,
       @SshAdvertisedAddresses List<String> advertisedSshAddresses)
       throws MalformedURLException, UnknownHostException {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java
index f47d7c0..4b08996 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java
@@ -21,20 +21,16 @@
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
-
+import java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
 import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.transport.ServiceMayNotContinueException;
 import org.eclipse.jgit.transport.resolver.RepositoryResolver;
 import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
 
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-
 class Resolver implements RepositoryResolver<HttpServletRequest> {
-  private static final String NAME_KEY_ATTRIBUTE = Resolver.class.getName()
-      + "/NameKey";
+  private static final String NAME_KEY_ATTRIBUTE = Resolver.class.getName() + "/NameKey";
   private final Provider<CurrentUser> userProvider;
 
   static Project.NameKey getNameKey(HttpServletRequest req) {
@@ -44,8 +40,7 @@
   private final FilteredRepository.Factory repoFactory;
 
   @Inject
-  Resolver(FilteredRepository.Factory repoFactory,
-      Provider<CurrentUser> userProvider) {
+  Resolver(FilteredRepository.Factory repoFactory, Provider<CurrentUser> userProvider) {
     this.repoFactory = repoFactory;
     this.userProvider = userProvider;
   }
@@ -53,10 +48,14 @@
   @Override
   public Repository open(HttpServletRequest req, String name)
       throws RepositoryNotFoundException, ServiceMayNotContinueException,
-      ServiceNotAuthorizedException {
+          ServiceNotAuthorizedException {
     Project.NameKey oldName = getNameKey(req);
-    checkState(oldName == null, "Resolved multiple repositories on %s: %s, %s",
-        req.getRequestURL(), oldName, name);
+    checkState(
+        oldName == null,
+        "Resolved multiple repositories on %s: %s, %s",
+        req.getRequestURL(),
+        oldName,
+        name);
     Project.NameKey nameKey = new Project.NameKey(name);
     req.setAttribute(NAME_KEY_ATTRIBUTE, nameKey);
     try {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/SetContextClassLoader.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/SetContextClassLoader.java
index e14454f..40baabd 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/SetContextClassLoader.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/SetContextClassLoader.java
@@ -15,9 +15,7 @@
 package com.googlesource.gerrit.plugins.gitiles;
 
 import com.google.inject.Singleton;
-
 import java.io.IOException;
-
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -29,12 +27,11 @@
 public class SetContextClassLoader implements Filter {
 
   @Override
-  public void init(FilterConfig arg0) throws ServletException {
-  }
+  public void init(FilterConfig arg0) throws ServletException {}
 
   @Override
-  public void doFilter(ServletRequest request, ServletResponse response,
-      FilterChain chain) throws IOException, ServletException {
+  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+      throws IOException, ServletException {
     Thread t = Thread.currentThread();
     ClassLoader old = t.getContextClassLoader();
     try {
@@ -46,6 +43,5 @@
   }
 
   @Override
-  public void destroy() {
-  }
+  public void destroy() {}
 }
diff --git a/src/main/resources/+Documentation/build.md b/src/main/resources/+Documentation/build.md
index 46d0f53..7b18329 100644
--- a/src/main/resources/+Documentation/build.md
+++ b/src/main/resources/+Documentation/build.md
@@ -1,74 +1,40 @@
 Build
 =====
 
-This plugin can be built with Buck.
+This plugin is built with Bazel.
 
-Buck
-----
+Clone (or link) this plugin to the `plugins` directory of Gerrit's source tree.
 
-Two build modes are supported: Standalone and in Gerrit tree.
-The standalone build mode is recommended, as this mode doesn't require
-the Gerrit tree to exist locally.
-
-
-### Build standalone
-
-Clone bucklets library:
+Put the external dependency Bazel build file into the Gerrit /plugins directory,
+replacing the existing empty one.
 
 ```
-  git clone https://gerrit.googlesource.com/bucklets
-
-```
-and link it to gitiles plugin directory:
-
-```
-  cd gitiles && ln -s ../bucklets .
+  cd gerrit/plugins
+  rm external_plugin_deps.bzl
+  ln -s gitiles/external_plugin_deps.bzl .
 ```
 
-Add link to the .buckversion file:
+Then issue
 
 ```
-  cd gitiles && ln -s bucklets/buckversion .buckversion
+  cd ..
+  bazel build plugins/gitiles
 ```
 
-Add link to the .watchmanconfig file:
-
-```
-  cd gitiles && ln -s bucklets/watchmanconfig .watchmanconfig
-```
-
-To build the plugin, issue the following command:
-
-```
-  buck build plugin
-```
+in the root of Gerrit's source tree to build
 
 The output is created in
 
 ```
-  buck-out/gen/gitiles.jar
+  bazel-genfiles/plugins/gitiles/gitiles.jar
 ```
 
-### Build in Gerrit tree
-
-Clone or link this plugin to the plugins directory of Gerrit's source
-tree, and issue the command:
-
-```
-  buck build plugins/gitiles
-```
-
-The output is created in
-
-```
-  buck-out/gen/plugins/gitiles/gitiles/gitiles.jar
-```
-
-This project can be imported into the Eclipse IDE:
+This project can be imported into the Eclipse IDE. Add the plugin name to the
+`CUSTOM_PLUGINS` set in Gerrit core in `tools/bzl/plugins.bzl`, and execute:
 
 ```
   ./tools/eclipse/project.py
 ```
 
 How to build the Gerrit Plugin API is described in the [Gerrit
-documentation](../../../Documentation/dev-buck.html#_extension_and_plugin_api_jar_files).
+documentation](../../../Documentation/dev-bazel.html#_extension_and_plugin_api_jar_files).
diff --git a/src/main/resources/+Documentation/config.md b/src/main/resources/+Documentation/config.md
index c5e9b54..abb6b71 100644
--- a/src/main/resources/+Documentation/config.md
+++ b/src/main/resources/+Documentation/config.md
@@ -30,9 +30,14 @@
 to the gitiles plugin can also be configured.
 
 The name of the link that appears in Gerrit can be configured with
-`gerrit.linkname`.
+`gerrit.linkname`. Defaults to `browse` if not set.
+
+The link frame target name can be configured with `gerrit.target`. Valid values
+are defined in the [W3C HTML Specification](https://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-frame-target).
+Defaults to `_blank` if not set.
 
 ```
   [gerrit]
-    linkname = browse
+    linkname = gitiles
+    target = _self
 ```