Merge branch 'stable-2.16'

* stable-2.16:
  Upgrade bazlets to latest stable-2.16 to build with 2.16.7 API
  Upgrade bazlets to latest stable-2.15 to build with 2.15.12 API
  Upgrade bazlets to latest stable-2.14 to build with 2.14.19 API

Change-Id: I1df79f175861e798f5db161579bf57f0a97a9fd4
diff --git a/.bazelignore b/.bazelignore
deleted file mode 100644
index 30f1613..0000000
--- a/.bazelignore
+++ /dev/null
@@ -1 +0,0 @@
-eclipse-out
diff --git a/.bazelrc b/.bazelrc
deleted file mode 100644
index 4ed16cf..0000000
--- a/.bazelrc
+++ /dev/null
@@ -1,2 +0,0 @@
-build --workspace_status_command=./tools/workspace-status.sh
-test --build_tests_only
diff --git a/BUILD b/BUILD
index 3428c43..394861c 100644
--- a/BUILD
+++ b/BUILD
@@ -35,25 +35,7 @@
     ],
     resources = glob(["src/main/resources/**/*"]),
     target_suffix = "__base",
-    deps = [
-        ":gitiles__plugin_deps",
-    ],
-)
-
-java_library(
-    name = "gitiles__plugin_deps",
-    visibility = ["//visibility:public"],
-    exports = [
-        "@autolink//jar",
-        "@cm-autolink//jar",
-        "@commonmark//jar",
-        "@commons-lang3//jar",
-        "@commons-text//jar",
-        "@gfm-strikethrough//jar",
-        "@gfm-tables//jar",
-        "@gitiles-servlet//jar",
-        "@prettify//jar",
-    ],
+    deps = ["//lib/gitiles"],
 )
 
 java_library(
@@ -62,6 +44,6 @@
     visibility = ["//visibility:public"],
     exports = [
         ":gitiles__plugin",
-        ":gitiles__plugin_deps",
+        "//lib/gitiles",
     ],
 )
diff --git a/LICENSE-autolink b/LICENSE-autolink
deleted file mode 100644
index 565820a..0000000
--- a/LICENSE-autolink
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2015 Robin Stocker
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/LICENSE-commonmark b/LICENSE-commonmark
deleted file mode 100644
index 3fecb98..0000000
--- a/LICENSE-commonmark
+++ /dev/null
@@ -1,23 +0,0 @@
-Copyright (c) 2015-2016, Atlassian Pty Ltd
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this
-  list of conditions and the following disclaimer.
-
-  * Redistributions in binary form must reproduce the above copyright notice,
-    this list of conditions and the following disclaimer in the documentation
-      and/or other materials provided with the distribution.
-
-      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-      AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-      IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-      DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-      FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-      DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-      SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-      CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-      OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/WORKSPACE b/WORKSPACE
deleted file mode 100644
index 19991fe..0000000
--- a/WORKSPACE
+++ /dev/null
@@ -1,30 +0,0 @@
-workspace(name = "gitiles")
-
-load("//:bazlets.bzl", "load_bazlets")
-
-load_bazlets(
-    commit = "5c1e201c6835e56a69a980c72206431e2a9d7d80",
-    #local_path = "/home/<user>/projects/bazlets",
-)
-
-# Snapshot Plugin API
-#load(
-#   "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
-#   "gerrit_api_maven_local",
-#)
-
-# Load snapshot Plugin API
-#gerrit_api_maven_local()
-
-# Release Plugin API
-load(
-    "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
-    "gerrit_api",
-)
-
-# Load release Plugin API
-gerrit_api()
-
-load("//:external_plugin_deps.bzl", "external_plugin_deps")
-
-external_plugin_deps()
diff --git a/bazlets.bzl b/bazlets.bzl
deleted file mode 100644
index f089af4..0000000
--- a/bazlets.bzl
+++ /dev/null
@@ -1,18 +0,0 @@
-load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
-
-NAME = "com_googlesource_gerrit_bazlets"
-
-def load_bazlets(
-        commit,
-        local_path = None):
-    if not local_path:
-        git_repository(
-            name = NAME,
-            remote = "https://gerrit.googlesource.com/bazlets",
-            commit = commit,
-        )
-    else:
-        native.local_repository(
-            name = NAME,
-            path = local_path,
-        )
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
deleted file mode 100644
index 5f4313d..0000000
--- a/external_plugin_deps.bzl
+++ /dev/null
@@ -1,61 +0,0 @@
-load("//tools/bzl:maven_jar.bzl", "GERRIT", "MAVEN_CENTRAL", "MAVEN_LOCAL", "maven_jar")
-
-COMMONMARK_VERSION = "0.10.0"
-
-def external_plugin_deps():
-    maven_jar(
-        name = "gitiles-servlet",
-        artifact = "com.google.gitiles:gitiles-servlet:0.2-7",
-        sha1 = "f23b22cb27fe5c4a78f761492082159d17873f57",
-        repository = GERRIT,
-    )
-
-    # prettify must match the version used in Gitiles
-    maven_jar(
-        name = "prettify",
-        artifact = "com.github.twalcari:java-prettify:1.2.2",
-        sha1 = "b8ba1c1eb8b2e45cfd465d01218c6060e887572e",
-    )
-
-    maven_jar(
-        name = "commons-lang3",
-        artifact = "org.apache.commons:commons-lang3:3.7",
-        sha1 = "557edd918fd41f9260963583ebf5a61a43a6b423",
-    )
-
-    maven_jar(
-        name = "commons-text",
-        artifact = "org.apache.commons:commons-text:1.2",
-        sha1 = "74acdec7237f576c4803fff0c1008ab8a3808b2b",
-    )
-
-    # commonmark must match the version used in Gitiles
-    maven_jar(
-        name = "commonmark",
-        artifact = "com.atlassian.commonmark:commonmark:" + COMMONMARK_VERSION,
-        sha1 = "119cb7bedc3570d9ecb64ec69ab7686b5c20559b",
-    )
-
-    maven_jar(
-        name = "cm-autolink",
-        artifact = "com.atlassian.commonmark:commonmark-ext-autolink:" + COMMONMARK_VERSION,
-        sha1 = "a6056a5efbd68f57d420bc51bbc54b28a5d3c56b",
-    )
-
-    maven_jar(
-        name = "autolink",
-        artifact = "org.nibor.autolink:autolink:0.7.0",
-        sha1 = "649f9f13422cf50c926febe6035662ae25dc89b2",
-    )
-
-    maven_jar(
-        name = "gfm-strikethrough",
-        artifact = "com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:" + COMMONMARK_VERSION,
-        sha1 = "40837da951b421b545edddac57012e15fcc9e63c",
-    )
-
-    maven_jar(
-        name = "gfm-tables",
-        artifact = "com.atlassian.commonmark:commonmark-ext-gfm-tables:" + COMMONMARK_VERSION,
-        sha1 = "c075db2a3301100cf70c7dced8ecf86b494458a2",
-    )
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 3dee013..0a4d3bf 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
@@ -199,11 +199,7 @@
         return null;
       }
       try {
-        return perm.filter(
-                ImmutableMap.of(name, ref),
-                git,
-                RefFilterOptions.builder().setFilterTagsSeparately(true).build())
-            .get(name);
+        return perm.filter(ImmutableMap.of(name, ref), git, RefFilterOptions.defaults()).get(name);
       } catch (PermissionBackendException e) {
         throw new IOException(e);
       }
@@ -216,10 +212,7 @@
         return null;
       }
       try {
-        return perm.filter(
-                ImmutableMap.of(ref.getName(), ref),
-                git,
-                RefFilterOptions.builder().setFilterTagsSeparately(true).build())
+        return perm.filter(ImmutableMap.of(ref.getName(), ref), git, RefFilterOptions.defaults())
             .get(ref.getName());
       } catch (PermissionBackendException e) {
         throw new IOException(e);
@@ -232,9 +225,7 @@
       try {
         refs =
             perm.filter(
-                git.getRefDatabase().getRefs(prefix),
-                git,
-                RefFilterOptions.builder().setFilterTagsSeparately(true).build());
+                git.getRefDatabase().getRefsByPrefix(prefix), git, RefFilterOptions.defaults());
       } catch (PermissionBackendException e) {
         throw new IOException(e);
       }
diff --git a/src/main/resources/+Documentation/build.md b/src/main/resources/+Documentation/build.md
deleted file mode 100644
index 12e6726..0000000
--- a/src/main/resources/+Documentation/build.md
+++ /dev/null
@@ -1,81 +0,0 @@
-Build
-=====
-
-This plugin is built with Bazel, and two build modes are supported:
-
-* Standalone
-* In Gerrit tree
-
-Standalone build mode is recommended, as this mode doesn't require local Gerrit
-tree to exist. Moreover, there are additional manual steps required when building
-in Gerrit tree mode (see corresponding section).
-
-## Build standalone
-
-To build the plugin, issue the following command:
-
-```
-  bazel build @PLUGIN@
-```
-
-The output is created in
-
-```
-  bazel-genfiles/@PLUGIN@.jar
-```
-
-To package the plugin sources run:
-
-```
-  bazel build lib@PLUGIN@__plugin-src.jar
-```
-
-The output is created in:
-
-```
-  bazel-bin/lib@PLUGIN@__plugin-src.jar
-```
-
-This project can be imported into the Eclipse IDE:
-
-```
-  ./tools/eclipse/project.sh
-```
-
-## Build in Gerrit tree
-
-Clone (or link) this plugin to the `plugins` directory of Gerrit's source tree.
-
-Put the external dependency Bazel build file into the Gerrit /plugins directory,
-replacing the existing empty one.
-
-```
-  cd gerrit/plugins
-  rm external_plugin_deps.bzl
-  ln -s gitiles/external_plugin_deps.bzl .
-```
-
-Then issue
-
-```
-  cd ..
-  bazel build plugins/gitiles
-```
-
-in the root of Gerrit's source tree to build
-
-The output is created in
-
-```
-  bazel-genfiles/plugins/gitiles/gitiles.jar
-```
-
-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-bazel.html#_extension_and_plugin_api_jar_files).
diff --git a/tools/bzl/BUILD b/tools/bzl/BUILD
deleted file mode 100644
index c5ed0b7..0000000
--- a/tools/bzl/BUILD
+++ /dev/null
@@ -1 +0,0 @@
-# Empty file required by Bazel
diff --git a/tools/bzl/classpath.bzl b/tools/bzl/classpath.bzl
deleted file mode 100644
index d5764f7..0000000
--- a/tools/bzl/classpath.bzl
+++ /dev/null
@@ -1,4 +0,0 @@
-load(
-    "@com_googlesource_gerrit_bazlets//tools:classpath.bzl",
-    "classpath_collector",
-)
diff --git a/tools/bzl/maven_jar.bzl b/tools/bzl/maven_jar.bzl
deleted file mode 100644
index 21fb670..0000000
--- a/tools/bzl/maven_jar.bzl
+++ /dev/null
@@ -1 +0,0 @@
-load("@com_googlesource_gerrit_bazlets//tools:maven_jar.bzl", "GERRIT", "MAVEN_CENTRAL", "MAVEN_LOCAL", "maven_jar")
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
deleted file mode 100644
index c157125..0000000
--- a/tools/bzl/plugin.bzl
+++ /dev/null
@@ -1,5 +0,0 @@
-load(
-    "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl",
-    "PLUGIN_DEPS",
-    "gerrit_plugin",
-)
diff --git a/tools/eclipse/BUILD b/tools/eclipse/BUILD
deleted file mode 100644
index 8ee09e9..0000000
--- a/tools/eclipse/BUILD
+++ /dev/null
@@ -1,10 +0,0 @@
-load("//tools/bzl:classpath.bzl", "classpath_collector")
-load("//tools/bzl:plugin.bzl", "PLUGIN_DEPS")
-
-classpath_collector(
-    name = "main_classpath_collect",
-    testonly = 1,
-    deps = PLUGIN_DEPS + [
-        "//:gitiles__classpath_deps",
-    ],
-)
diff --git a/tools/eclipse/project.sh b/tools/eclipse/project.sh
deleted file mode 100755
index 3d339ec..0000000
--- a/tools/eclipse/project.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-#Copyright (C) 2017 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.
-
-`bazel query @com_googlesource_gerrit_bazlets//tools/eclipse:project --output location | sed s/BUILD:.*//`project.py -n gitiles-plugin -r .
-
-
diff --git a/tools/workspace-status.sh b/tools/workspace-status.sh
deleted file mode 100755
index c9e9129..0000000
--- a/tools/workspace-status.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/bash
-
-#This script will be run by bazel when the build process starts to
-# generate key-value information that represents the status of the
-# workspace. The output should be like
-#
-# KEY1 VALUE1
-# KEY2 VALUE2
-#
-# If the script exits with non-zero code, it's considered as a failure
-# and the output will be discarded.
-
-function rev() {
-  cd $1 && git describe --always --match "v[0-9].*" --dirty
-}
-
-echo STABLE_BUILD_GITILES_LABEL "$(rev .)"