Merge "Bazel: Build core plugins"

* submodules:
* Update plugins/commit-message-length-validator from branch 'master'
  - Implement Bazel build
    
    Change-Id: I246cdd00923d36c11a678b250ef6a91a5e433943
    * Update plugins/replication from branch 'master'
  - Implement Bazel build
    
    Change-Id: Ia6dc6ba50faeddd300d94aabdbef97b07cdb741d
    * Update plugins/singleusergroup from branch 'master'
  - Implement Bazel build
    
    Change-Id: Ia0d8fa1b91ea4db94e0da951604aac02ffde8662
    * Update plugins/hooks from branch 'master'
  - Implement Bazel build
    
    Change-Id: I7b6f05032b7329b992d8aefe0bbff63f357b0df5
    * Update plugins/download-commands from branch 'master'
  - Implement Bazel build
    
    Change-Id: I74da3f186e166aae5070b7458ade3f12714d8548
    * Update plugins/reviewnotes from branch 'master'
  - Implement Bazel build
    
    Change-Id: I8cc93cc87284340f48735925313d602a11dba716
    
diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt
index 1fcdd6c..15409c6 100644
--- a/Documentation/dev-bazel.txt
+++ b/Documentation/dev-bazel.txt
@@ -6,7 +6,6 @@
 * Documentation index
 * License tracking
 * Version stamping
-* Core plugins
 * Custom plugins
 * Eclipse project generation.
 * Publishing to maven.
diff --git a/WORKSPACE b/WORKSPACE
index e9c4087..94552f6 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -784,3 +784,9 @@
   artifact = 'org.webjars:google-diff-match-patch:20121119-1',
   sha1 = '0cf1782dbcb8359d95070da9176059a5a9d37709',
 )
+
+maven_jar(
+  name = 'commons_io',
+  artifact = 'commons-io:commons-io:1.4',
+  sha1 = 'a8762d07e76cfde2395257a5da47ba7c1dbd3dce',
+)
diff --git a/gerrit-plugin-api/BUILD b/gerrit-plugin-api/BUILD
index 9404acc..e2d8372 100644
--- a/gerrit-plugin-api/BUILD
+++ b/gerrit-plugin-api/BUILD
@@ -11,6 +11,45 @@
   '//gerrit-sshd:sshd',
 ]
 
+EXPORTS = [
+  '//gerrit-antlr:query_exception',
+  '//gerrit-antlr:query_parser',
+  '//gerrit-common:annotations',
+  '//gerrit-common:server',
+  '//gerrit-extension-api:api',
+  '//gerrit-gwtexpui:server',
+  '//gerrit-reviewdb:server',
+  '//lib/commons:lang',
+  '//lib/dropwizard:dropwizard-core',
+  '//lib/guice:guice',
+  '//lib/guice:guice-assistedinject',
+  '//lib/guice:guice-servlet',
+  '//lib/guice:javax-inject',
+  '//lib/guice:multibindings',
+  '//lib/jgit/org.eclipse.jgit.http.server:jgit-servlet',
+  '//lib/jgit/org.eclipse.jgit:jgit',
+  '//lib/joda:joda-time',
+  '//lib/log:api',
+  '//lib/log:log4j',
+  '//lib/mina:sshd',
+  '//lib/ow2:ow2-asm',
+  '//lib/ow2:ow2-asm-analysis',
+  '//lib/ow2:ow2-asm-commons',
+  '//lib/ow2:ow2-asm-util',
+  '//lib:args4j',
+  '//lib:blame-cache',
+  '//lib:guava',
+  '//lib:gson',
+  '//lib:gwtorm',
+  '//lib:icu4j',
+  '//lib:jsch',
+  '//lib:mime-util',
+  '//lib:protobuf',
+  '//lib:servlet-api-3_1',
+  '//lib:soy',
+  '//lib:velocity',
+]
+
 java_binary(
   name = 'plugin-api',
   main_class = 'Dummy',
@@ -20,42 +59,14 @@
 
 java_library(
   name = 'lib',
-  exports = PLUGIN_API + [
-    '//gerrit-antlr:query_exception',
-    '//gerrit-antlr:query_parser',
-    '//gerrit-common:annotations',
-    '//gerrit-common:server',
-    '//gerrit-extension-api:api',
-    '//gerrit-gwtexpui:server',
-    '//gerrit-reviewdb:server',
-    '//lib/commons:lang',
-    '//lib/dropwizard:dropwizard-core',
-    '//lib/guice:guice',
-    '//lib/guice:guice-assistedinject',
-    '//lib/guice:guice-servlet',
-    '//lib/guice:javax-inject',
-    '//lib/guice:multibindings',
-    '//lib/jgit/org.eclipse.jgit.http.server:jgit-servlet',
-    '//lib/jgit/org.eclipse.jgit:jgit',
-    '//lib/joda:joda-time',
-    '//lib/log:api',
-    '//lib/mina:sshd',
-    '//lib/ow2:ow2-asm',
-    '//lib/ow2:ow2-asm-analysis',
-    '//lib/ow2:ow2-asm-commons',
-    '//lib/ow2:ow2-asm-util',
-    '//lib:args4j',
-    '//lib:blame-cache',
-    '//lib:guava',
-    '//lib:gwtorm',
-    '//lib:icu4j',
-    '//lib:jsch',
-    '//lib:mime-util',
-    '//lib:protobuf',
-    '//lib:servlet-api-3_1',
-    '//lib:soy',
-    '//lib:velocity',
-  ],
+  exports = PLUGIN_API + EXPORTS,
+  visibility = ['//visibility:public'],
+)
+
+java_library(
+  name = 'lib-neverlink',
+  neverlink = 1,
+  exports = PLUGIN_API + EXPORTS,
   visibility = ['//visibility:public'],
 )
 
diff --git a/lib/BUILD b/lib/BUILD
index 20fa126..4bd5ad7 100644
--- a/lib/BUILD
+++ b/lib/BUILD
@@ -243,3 +243,9 @@
   exports = ['@postgresql//jar'],
   visibility = ['//visibility:public'],
 )
+
+java_library(
+  name = 'commons-io',
+  exports = ['@commons_io//jar'],
+  visibility = ['//visibility:public'],
+)
diff --git a/plugins/commit-message-length-validator b/plugins/commit-message-length-validator
index 9b163e1..474e06c 160000
--- a/plugins/commit-message-length-validator
+++ b/plugins/commit-message-length-validator
@@ -1 +1 @@
-Subproject commit 9b163e113de9f3a49219a02d388f7f46ea2559d3
+Subproject commit 474e06cccb1a6a821e19f70b8e03aa1f816ff219
diff --git a/plugins/download-commands b/plugins/download-commands
index 3fb4fb6..e5f1a9b 160000
--- a/plugins/download-commands
+++ b/plugins/download-commands
@@ -1 +1 @@
-Subproject commit 3fb4fb63317b6004761d1fea98a8f4d288d95409
+Subproject commit e5f1a9ba057e9b287a7dd2b7e0136eaef183aa6c
diff --git a/plugins/hooks b/plugins/hooks
index c1705a7..c474972 160000
--- a/plugins/hooks
+++ b/plugins/hooks
@@ -1 +1 @@
-Subproject commit c1705a739f117b9123e1d63aebf07d043afb0867
+Subproject commit c47497201b4b641ccd1786300297a8ac2848fc07
diff --git a/plugins/replication b/plugins/replication
index 6f69a7e..bb5e2e0 160000
--- a/plugins/replication
+++ b/plugins/replication
@@ -1 +1 @@
-Subproject commit 6f69a7e338824ae927233673811ccf8d52d3ad5e
+Subproject commit bb5e2e02f4a1a932dc985642e7c028d9285ab0cd
diff --git a/plugins/reviewnotes b/plugins/reviewnotes
index 85069a4..eddd8bc 160000
--- a/plugins/reviewnotes
+++ b/plugins/reviewnotes
@@ -1 +1 @@
-Subproject commit 85069a4bd88b9a18c9df89c86229daf2a07cf345
+Subproject commit eddd8bc74b180cf80e7ebae2c3f73157a1e7118e
diff --git a/plugins/singleusergroup b/plugins/singleusergroup
index 3ca1167..5f240eb 160000
--- a/plugins/singleusergroup
+++ b/plugins/singleusergroup
@@ -1 +1 @@
-Subproject commit 3ca1167edda713f4bfdcecd9c0e2626797d7027f
+Subproject commit 5f240eba762f7447ad12994ce6988ee976bb5c3b
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
new file mode 100644
index 0000000..bdd1794
--- /dev/null
+++ b/tools/bzl/plugin.bzl
@@ -0,0 +1,34 @@
+
+def gerrit_plugin(
+    name,
+    deps = [],
+    srcs = [],
+    resources = [],
+    manifest_entries = []):
+  # TODO(davido): Fix stamping: run git describe in plugin directory
+  # https://github.com/bazelbuild/bazel/issues/1758
+  manifest_lines = [
+    "Gerrit-ApiType: plugin",
+    "Implementation-Version: 1.0",
+    "Implementation-Vendor: Gerrit Code Review",
+  ]
+  for line in manifest_entries:
+    manifest_lines.append(line.replace('$', '\$'))
+
+  native.java_library(
+    name = name + '__plugin',
+    srcs = srcs,
+    resources = resources,
+    deps = deps + ['//gerrit-plugin-api:lib-neverlink'],
+    visibility = ['//visibility:public'],
+  )
+
+  native.java_binary(
+    name = name,
+    deploy_manifest_lines = manifest_lines,
+    main_class = 'Dummy',
+    runtime_deps = [
+      ':%s__plugin' % name,
+    ],
+    visibility = ['//visibility:public'],
+  )