Replace buck with bazel

Change week year from YYYY to yyyy as errorprone reports as bugpattern.

Change-Id: I9fda2e743f6048ad66343b7125be88d2d73312a0
diff --git a/.buckconfig b/.buckconfig
deleted file mode 100644
index 59fd2b4..0000000
--- a/.buckconfig
+++ /dev/null
@@ -1,16 +0,0 @@
-[alias]
-  messageoftheday = //:messageoftheday
-  plugin = //:messageoftheday
-  src = //:messageoftheday-sources
-
-[java]
-  jar_spool_mode = direct_to_jar
-  src_roots = java, resources
-
-[project]
-  ignore = .git, eclipse-out/
-  parallel_parsing = true
-
-[cache]
-  mode = dir
-  dir = buck-out/cache
diff --git a/.gitignore b/.gitignore
index de9afe0..e9d6de1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,7 @@
-/.buckd
-/.buckversion
 /.classpath
+/.primary_build_tool
 /.project
 /.settings
-/.watchmanconfig
-/buck-out
-/bucklets
+/bazel-*
+/bin/
 /eclipse-out
diff --git a/BUCK b/BUCK
deleted file mode 100644
index 6645404..0000000
--- a/BUCK
+++ /dev/null
@@ -1,38 +0,0 @@
-include_defs('//bucklets/gerrit_plugin.bucklet')
-include_defs('//bucklets/java_sources.bucklet')
-include_defs('//bucklets/maven_jar.bucklet')
-
-SOURCES = glob(['src/main/java/**/*.java'])
-RESOURCES = glob(['src/main/resources/**/*'])
-
-TEST_DEPS = GERRIT_PLUGIN_API + GERRIT_TESTS + [
-  ':messageoftheday__plugin',
-]
-
-gerrit_plugin(
-  name = 'messageoftheday',
-  srcs = glob(['src/main/java/**/*.java']),
-  resources = glob(['src/main/resources/**/*']),
-  manifest_entries = [
-    'Gerrit-PluginName: messageoftheday',
-    'Gerrit-Module: com.googlesource.gerrit.plugins.messageoftheday.Module',
-  ]
-)
-
-java_sources(
-  name = 'messageoftheday-sources',
-  srcs = SOURCES + RESOURCES,
-)
-
-java_library(
-  name = 'classpath',
-  deps = TEST_DEPS,
-)
-
-java_test(
-  name = 'messageoftheday_tests',
-  srcs = glob(['src/test/java/**/*.java']),
-  resources = glob(['src/test/resources/**/']),
-  labels = ['messageoftheday'],
-  deps = TEST_DEPS,
-)
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..ca6a1cd
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,13 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+    name = "messageoftheday",
+    srcs = glob(["src/main/java/**/*.java"]),
+    manifest_entries = [
+        "Gerrit-PluginName: messageoftheday",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.messageoftheday.Module",
+        "Implementation-Title: Plugin messageoftheday",
+        "Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/messageoftheday",
+    ],
+    resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..9adb6a2
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,24 @@
+workspace(name = "messageoftheday")
+
+load("//:bazlets.bzl", "load_bazlets")
+
+load_bazlets(
+    commit = "e15ad03897f040435d6c5e808b697b1125b964c1",
+    #    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()
diff --git a/bazlets.bzl b/bazlets.bzl
new file mode 100644
index 0000000..5188304
--- /dev/null
+++ b/bazlets.bzl
@@ -0,0 +1,16 @@
+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/gerrit/BUCK b/lib/gerrit/BUCK
deleted file mode 100644
index cd12b01..0000000
--- a/lib/gerrit/BUCK
+++ /dev/null
@@ -1,22 +0,0 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
-VER = '2.12.7'
-REPO = MAVEN_CENTRAL
-
-maven_jar(
-  name = 'acceptance-framework',
-  id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER,
-  sha1 = 'ab59662eef6c10ed7f909fe4af298f4bbf34b9ac',
-  license = 'Apache2.0',
-  attach_source = False,
-  repository = REPO,
-)
-
-maven_jar(
-  name = 'plugin-api',
-  id = 'com.google.gerrit:gerrit-plugin-api:' + VER,
-  sha1 = '6069b0061a6c7a9e1ce470e738669e71ef594410',
-  license = 'Apache2.0',
-  attach_source = False,
-  repository = REPO,
-)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayImpl.java b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayImpl.java
index 14a8c01..c69565d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayImpl.java
@@ -94,6 +94,6 @@
   }
 
   private static String now() {
-    return new SimpleDateFormat("YYYYMMdd:HHmm").format(new Date());
+    return new SimpleDateFormat("yyyyMMdd:HHmm").format(new Date());
   }
 }
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 3babed2..9154ae7 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -1,73 +1,43 @@
 Build
 =====
 
-This plugin is built with Buck.
+This plugin can be built with Bazel, and two build modes are supported:
 
-Two build modes are supported: Standalone and in Gerrit tree. Standalone
-build mode is recommended, as this mode doesn't require local Gerrit
-tree to exist.
+* Standalone
+* In Gerrit tree
 
-Build standalone
-----------------
+Standalone build mode is recommended, as this mode doesn't require local Gerrit tree to exist. Moreover, there are some limitations and additional manual steps required when building in Gerrit tree mode (see corresponding sections).
 
-Clone bucklets library:
-
-```
-  git clone https://gerrit.googlesource.com/bucklets
-
-```
-and link it to @PLUGIN@ directory:
-
-```
-  cd @PLUGIN@ && ln -s ../bucklets .
-```
-
-Add link to the .buckversion file:
-
-```
-  cd @PLUGIN@ && ln -s bucklets/buckversion .buckversion
-```
-
-Add link to the .watchmanconfig file:
-
-```
-  cd @PLUGIN@ && ln -s bucklets/watchmanconfig .watchmanconfig
-```
+## Build standalone
 
 To build the plugin, issue the following command:
 
 ```
-  buck build plugin
+  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:
 
 ```
-  buck-out/gen/@PLUGIN@.jar
+  bazel-bin/lib@PLUGIN@__plugin-src.jar
 ```
 
 This project can be imported into the Eclipse IDE:
 
 ```
-  ./bucklets/tools/eclipse.py
-```
-
-To execute the tests run:
-
-```
-  buck test
-```
-
-To build plugin sources run:
-
-```
-  buck build src
-```
-
-The output is created in:
-
-```
-  buck-out/gen/@PLUGIN@-sources.jar
+  ./tools/eclipse/project.sh
 ```
 
 Build in Gerrit tree
@@ -77,29 +47,25 @@
 tree, and issue the command:
 
 ```
-  buck build plugins/@PLUGIN@
+  bazel build plugins/@PLUGIN@
 ```
 
 The output is created in:
 
 ```
-  buck-out/gen/plugins/@PLUGIN@/@PLUGIN@.jar
+  bazel-genfiles/plugins/@PLUGIN@/@PLUGIN@.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
 ```
 
-To execute the tests run:
-
-```
-  buck test --include @PLUGIN@
-```
-
 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).
 
 [Back to @PLUGIN@ documentation index][index]
 
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index ea23057..908ed3a 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -22,7 +22,7 @@
 	displayed up to and including that date:time. The message will not be displayed
 	any more after that date:time. This field is required. If not set, the message
 	will not be displayed.
-	The format of this field is `YYYYMMdd:HHmm`.
+	The format of this field is `yyyyMMdd:HHmm`.
 
 ## Message content and location
 
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..e69de29
--- /dev/null
+++ b/tools/bzl/BUILD
diff --git a/tools/bzl/classpath.bzl b/tools/bzl/classpath.bzl
new file mode 100644
index 0000000..dfcbe9c
--- /dev/null
+++ b/tools/bzl/classpath.bzl
@@ -0,0 +1,2 @@
+load("@com_googlesource_gerrit_bazlets//tools:classpath.bzl",
+     "classpath_collector")
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
new file mode 100644
index 0000000..956dd59
--- /dev/null
+++ b/tools/bzl/plugin.bzl
@@ -0,0 +1,5 @@
+load(
+    "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl",
+    "gerrit_plugin",
+    "PLUGIN_DEPS",
+)
diff --git a/tools/eclipse/BUILD b/tools/eclipse/BUILD
new file mode 100644
index 0000000..e698d95
--- /dev/null
+++ b/tools/eclipse/BUILD
@@ -0,0 +1,9 @@
+load("//tools/bzl:plugin.bzl", "PLUGIN_DEPS")
+load("//tools/bzl:classpath.bzl", "classpath_collector")
+
+classpath_collector(
+    name = "main_classpath_collect",
+    deps = PLUGIN_DEPS + [
+        "//:messageoftheday__plugin",
+    ],
+)
diff --git a/tools/eclipse/project.sh b/tools/eclipse/project.sh
new file mode 100755
index 0000000..417ea38
--- /dev/null
+++ b/tools/eclipse/project.sh
@@ -0,0 +1,15 @@
+#!/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 messageoftheday -r .
diff --git a/tools/workspace-status.sh b/tools/workspace-status.sh
new file mode 100755
index 0000000..948ad64
--- /dev/null
+++ b/tools/workspace-status.sh
@@ -0,0 +1,14 @@
+#!/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_MESSAGEOFTHEDAY_LABEL $(rev .)