Add standalone bazel build

Change-Id: I3d94eede0da5d2e45354fdfc0d60833a7548bcfe
diff --git a/.gitignore b/.gitignore
index 1c634f0..696ab76 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,8 @@
 /.buckd
 /.watchmanconfig
 /buck-out
+/bazel-bin
+/bazel-genfiles
+/bazel-out
+/bazel-lfs
+/bazel-testlogs
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..48c5d1c
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,18 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+    name = "lfs",
+    srcs = glob(["src/main/java/**/*.java"]),
+    manifest_entries = [
+        "Gerrit-PluginName: lfs",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.lfs.Module",
+        "Gerrit-HttpModule: com.googlesource.gerrit.plugins.lfs.HttpModule",
+        "Gerrit-SshModule: com.googlesource.gerrit.plugins.lfs.SshModule",
+    ],
+    resources = glob(["src/main/resources/**/*"]),
+    deps = [
+        "//lib/jgit:jgit-http-apache",
+        "//lib/jgit:jgit-lfs",
+        "//lib/jgit:jgit-lfs-server",
+    ],
+)
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..c707607
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,51 @@
+workspace(name = "lfs")
+
+load("//:bazlets.bzl", "load_bazlets")
+
+load_bazlets(
+    commit = "8a4cbdc993f41fcfe7290e7d1007cfedf8d87c18",
+    #    local_path = "/home/<user>/projects/bazlets",
+)
+
+load("@com_googlesource_gerrit_bazlets//tools:maven_jar.bzl",
+     "maven_jar",
+     "GERRIT")
+
+JGIT_VERS = "4.6.0.201612231935-r.30-gd3148f300"
+
+maven_jar(
+    name = "jgit_http_apache",
+    artifact = "org.eclipse.jgit:org.eclipse.jgit.http.apache:" + JGIT_VERS,
+    sha1 = "b9806f94d6b548c85a9ef96ef647b0f15b64927a",
+    repository = GERRIT,
+)
+
+maven_jar(
+    name = "jgit_lfs",
+    artifact = "org.eclipse.jgit:org.eclipse.jgit.lfs:" + JGIT_VERS,
+    sha1 = "55cf48dd41732ded00d66f2f833e3b7346eb5e37",
+    repository = GERRIT,
+)
+
+maven_jar(
+    name = "jgit_lfs_server",
+    artifact = "org.eclipse.jgit:org.eclipse.jgit.lfs.server:" + JGIT_VERS,
+    sha1 = "4d917afafe7888bba07607bfa7fcb06bb60fe7f1",
+    repository = GERRIT,
+)
+
+# Release Plugin API
+#load("@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
+#     "gerrit_api")
+
+# Snapshot Plugin API
+load(
+    "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
+    "gerrit_api_maven_local",
+)
+
+# Load release Plugin API
+#gerrit_api()
+
+# Load snapshot Plugin API
+gerrit_api_maven_local()
diff --git a/bazlets.bzl b/bazlets.bzl
new file mode 100644
index 0000000..b7ce55a
--- /dev/null
+++ b/bazlets.bzl
@@ -0,0 +1,18 @@
+NAME = "com_googlesource_gerrit_bazlets"
+
+def load_bazlets(
+    commit,
+    local_path = None
+  ):
+  if not local_path:
+      native.git_repository(
+          name = NAME,
+          remote = "https://gerrit.googlesource.com/bazlets",
+          commit = commit,
+      )
+  else:
+      native.local_repository(
+          name = NAME,
+          path = local_path,
+      )
+
diff --git a/lib/jgit/BUILD b/lib/jgit/BUILD
new file mode 100644
index 0000000..44c1e3b
--- /dev/null
+++ b/lib/jgit/BUILD
@@ -0,0 +1,18 @@
+package(
+    default_visibility = ["//visibility:public"],
+)
+
+java_library(
+    name = "jgit-http-apache",
+    exports = ["@jgit_http_apache//jar"],
+)
+
+java_library(
+    name = "jgit-lfs",
+    exports = ["@jgit_lfs//jar"],
+)
+
+java_library(
+    name = "jgit-lfs-server",
+    exports = ["@jgit_lfs_server//jar"],
+)
diff --git a/tools/bazel.rc b/tools/bazel.rc
new file mode 100644
index 0000000..2c1da56
--- /dev/null
+++ b/tools/bazel.rc
@@ -0,0 +1,3 @@
+build --workspace_status_command=./tools/workspace-status.sh
+test --build_tests_only
+
diff --git a/tools/bzl/BUILD b/tools/bzl/BUILD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/bzl/BUILD
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
new file mode 100644
index 0000000..9cc3569
--- /dev/null
+++ b/tools/bzl/plugin.bzl
@@ -0,0 +1,5 @@
+load(
+    "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl",
+    "gerrit_plugin",
+)
+
diff --git a/tools/workspace-status.sh b/tools/workspace-status.sh
new file mode 100755
index 0000000..dcb6031
--- /dev/null
+++ b/tools/workspace-status.sh
@@ -0,0 +1,18 @@
+#!/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_LFS_LABEL $(rev .)
+