Implement Bazel build
This change implements both in gerrit tree and standalone Bazel build.
Change-Id: I0f339d4e4e50e863559b04cbb232a82631be79aa
diff --git a/.gitignore b/.gitignore
index defad4b..2eb7929 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,9 @@
/.settings
/hooks-its/.settings/org.maven.ide.eclipse.prefs
/hooks-its/.settings/org.eclipse.m2e.core.prefs
-
+/bazel-bin
+/bazel-genfiles
+/bazel-its-base
+/bazel-out
+/bazel-reviewers
+/bazel-testlogs
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..13cece2
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,37 @@
+load("//tools/bzl:junit.bzl", "junit_tests")
+load(
+ "//tools/bzl:plugin.bzl",
+ "gerrit_plugin",
+ "PLUGIN_DEPS",
+ "PLUGIN_TEST_DEPS",
+)
+
+gerrit_plugin(
+ name = "its-base",
+ srcs = glob(["src/main/java/**/*.java"]),
+ resources = glob(["src/main/resources/**/*"]),
+)
+
+TEST_UTIL_SRC = glob(['src/test/java/com/googlesource/gerrit/plugins/its/base/testutil/**/*.java'])
+
+java_library(
+ name = 'its-base_tests-utils',
+ srcs = TEST_UTIL_SRC,
+ deps = PLUGIN_DEPS + PLUGIN_TEST_DEPS,
+ testonly = 1,
+ visibility = ['//visibility:public'],
+)
+
+junit_tests(
+ name = "its_base_tests",
+ srcs = glob(
+ ["src/test/java/**/*.java"],
+ exclude = TEST_UTIL_SRC
+ ),
+ tags = ["its-base"],
+ deps = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
+ ":its-base__plugin",
+ ":its-base_tests-utils",
+ ],
+ testonly = 1,
+)
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..0c6a6ad
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,43 @@
+workspace(name = "its_base")
+
+load("//:bazlets.bzl", "load_bazlets")
+
+load_bazlets(
+ commit = "8a4cbdc993f41fcfe7290e7d1007cfedf8d87c18",
+ # local_path = "/home/<user>/projects/bazlets",
+)
+
+# Snapshot Plugin API
+load(
+ "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
+ "gerrit_api_maven_local",
+)
+
+# Release Plugin API
+#load(
+# "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
+# "gerrit_api",
+#)
+load(
+ "@com_googlesource_gerrit_bazlets//:gerrit_gwt.bzl",
+ "gerrit_gwt",
+)
+
+# Load release Plugin API
+#gerrit_api()
+
+# Load snapshot Plugin API
+gerrit_api_maven_local()
+
+gerrit_gwt()
+
+load(
+ "@com_googlesource_gerrit_bazlets//tools:maven_jar.bzl",
+ "maven_jar",
+)
+
+maven_jar(
+ name = "commons_dbcp",
+ artifact = "commons-dbcp:commons-dbcp:1.4",
+ sha1 = "30be73c965cc990b153a100aaaaafcf239f82d39",
+)
diff --git a/bazlets.bzl b/bazlets.bzl
new file mode 100644
index 0000000..e14e488
--- /dev/null
+++ b/bazlets.bzl
@@ -0,0 +1,17 @@
+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/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 3606c87..d6531e0 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -1,20 +1,40 @@
Build
=====
-This base library for ITS-based plugins is built with Buck.
+This base library for ITS-based plugins is built with Bazel.
-Clone or link this plugin to the plugins directory of Gerrit's source
-tree, and issue the command:
+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
```
- buck build plugins/its-base
+ bazel build its-base
```
The output is created in
```
- buck-out/gen/plugins/its-base/its-base.jar
- buck-out/gen/plugins/its-base/lib__its-base__plugin__output/its-base__plugin.jar
+ bazel-genfiles/its-base.jar
+```
+
+To execute the tests run:
+
+```
+ bazel test :its_base_tests
+```
+
+### Build in Gerrit tree
+
+```
+ bazel build plugins/its-base
+```
+
+The output is created in
+
+```
+ bazel-genfiles/plugins/its-base/its-base.jar
```
This project can be imported into the Eclipse IDE:
@@ -26,7 +46,7 @@
To execute the tests run:
```
- buck test --all --include its-base
+ bazel test plugins/its-base:its_base_tests
```
Note that the ITS-based plugins require `its-base__plugin` library:
@@ -44,4 +64,4 @@
[Back to @PLUGIN@ documentation index][index]
-[index]: index.html
\ No newline at end of file
+[index]: index.html
diff --git a/tools/bazel.rc b/tools/bazel.rc
new file mode 100644
index 0000000..4ed16cf
--- /dev/null
+++ b/tools/bazel.rc
@@ -0,0 +1,2 @@
+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..8b13789
--- /dev/null
+++ b/tools/bzl/BUILD
@@ -0,0 +1 @@
+
diff --git a/tools/bzl/junit.bzl b/tools/bzl/junit.bzl
new file mode 100644
index 0000000..3af7e58
--- /dev/null
+++ b/tools/bzl/junit.bzl
@@ -0,0 +1,4 @@
+load(
+ "@com_googlesource_gerrit_bazlets//tools:junit.bzl",
+ "junit_tests",
+)
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
new file mode 100644
index 0000000..a2e438f
--- /dev/null
+++ b/tools/bzl/plugin.bzl
@@ -0,0 +1,6 @@
+load(
+ "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl",
+ "gerrit_plugin",
+ "PLUGIN_DEPS",
+ "PLUGIN_TEST_DEPS",
+)
diff --git a/tools/workspace-status.sh b/tools/workspace-status.sh
new file mode 100755
index 0000000..57797fb
--- /dev/null
+++ b/tools/workspace-status.sh
@@ -0,0 +1,17 @@
+#!/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_ITS-BASE_LABEL" $(rev .)