Add standalone buck build

Change-Id: Ic6e61e93b88f404cf3a15f96dded1235bc26342e
diff --git a/.buckconfig b/.buckconfig
new file mode 100644
index 0000000..59fd2b4
--- /dev/null
+++ b/.buckconfig
@@ -0,0 +1,16 @@
+[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 ebbbd5f..de9afe0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,9 @@
+/.buckd
+/.buckversion
 /.classpath
 /.project
 /.settings
+/.watchmanconfig
+/buck-out
+/bucklets
+/eclipse-out
diff --git a/BUCK b/BUCK
index fd12a32..6645404 100644
--- a/BUCK
+++ b/BUCK
@@ -1,3 +1,14 @@
+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']),
@@ -7,3 +18,21 @@
     '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/lib/gerrit/BUCK b/lib/gerrit/BUCK
new file mode 100644
index 0000000..cd12b01
--- /dev/null
+++ b/lib/gerrit/BUCK
@@ -0,0 +1,22 @@
+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/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 5f96205..3babed2 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -2,21 +2,105 @@
 =====
 
 This plugin is built with Buck.
-Clone or link this plugin to the plugins directory of Gerrit tree
-and issue the command:
+
+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.
+
+Build standalone
+----------------
+
+Clone bucklets library:
 
 ```
-  buck build plugins/messageoftheday
-```
-
-The output is created in
+  git clone https://gerrit.googlesource.com/bucklets
 
 ```
-  buck-out/gen/plugins/messageoftheday/messageoftheday.jar
+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
+```
+
+To build the plugin, issue the following command:
+
+```
+  buck build plugin
+```
+
+The output is created in:
+
+```
+  buck-out/gen/@PLUGIN@.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
+```
+
+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/@PLUGIN@
+```
+
+The output is created in:
+
+```
+  buck-out/gen/plugins/@PLUGIN@/@PLUGIN@.jar
 ```
 
 This project can be imported into the Eclipse IDE:
 
 ```
   ./tools/eclipse/project.py
-```
\ No newline at end of file
+```
+
+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).
+
+[Back to @PLUGIN@ documentation index][index]
+
+[index]: index.html