Bazel: Generate eclipse project

servlet_api_2_5 can be exculded from the generated .classpath to avoid
classpath collisions between Servlet API 2.5 and Servlet API 3.0. To do
that, pass -x parameter to project.py invocation in project.sh:

  ... -n gitiles -r . -x servlet_api_2_5

TEST PLAN:

  $ tools/eclipse/project.sh

Open the project in Eclipse IDE and verify that it can be compiled and
the tests can be run.

Change-Id: If318321fb1a94888a9adea635458afee2b463682
diff --git a/WORKSPACE b/WORKSPACE
index d55fd5c..24eb0f0 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,6 +1,9 @@
 workspace(name = "gitiles")
 load("//tools:bazlets.bzl", "load_bazlets")
-load_bazlets(commit = "3afbeab55ece585dbfc7a980bf7214b24ddbbe86")
+load_bazlets(
+    commit = "e10ae3f85781aa15054be802b2a9f9465b1bf1e0",
+#    local_path = "/home/<user>/projects/bazlets"
+)
 load("@com_googlesource_gerrit_bazlets//tools:maven_jar.bzl",
      "maven_jar",
      "GERRIT")
diff --git a/gitiles-dev/BUILD b/gitiles-dev/BUILD
index 3a062c7..bbb6de2 100644
--- a/gitiles-dev/BUILD
+++ b/gitiles-dev/BUILD
@@ -13,6 +13,7 @@
         "//lib/slf4j:slf4j-simple",
         "//lib/soy",
     ],
+    visibility = ["//visibility:public"],
 )
 
 java_binary(
diff --git a/gitiles-servlet/BUILD b/gitiles-servlet/BUILD
index 803f62e..d3a7ff3 100644
--- a/gitiles-servlet/BUILD
+++ b/gitiles-servlet/BUILD
@@ -56,14 +56,13 @@
 load("@com_googlesource_gerrit_bazlets//tools:junit.bzl", "junit_tests")
 
 junit_tests(
-    name = "ServletTests",
+    name = "servlet_tests",
     srcs = glob(
         [
             "src/test/java/**/*Test.java",
         ],
         exclude = ["**/ServletTest.java"],
     ),
-    visibility = ["//visibility:public"],
     runtime_deps = ["//lib/junit:hamcrest-core"],
     deps = DEPS + [
         ":servlet",
@@ -73,6 +72,7 @@
         "//lib/jgit:junit",
         "//lib/junit",
     ],
+    visibility = ["//visibility:public"],
 )
 
 load("@com_googlesource_gerrit_bazlets//tools:javadoc.bzl", "java_doc")
diff --git a/tools/eclipse/BUILD b/tools/eclipse/BUILD
new file mode 100644
index 0000000..45ad493
--- /dev/null
+++ b/tools/eclipse/BUILD
@@ -0,0 +1,31 @@
+load("@com_googlesource_gerrit_bazlets//tools:classpath.bzl", "classpath_collector")
+load("@com_googlesource_gerrit_bazlets//tools:py_binary_path.bzl", "py_binary_path")
+
+DEPS = [
+    "//gitiles-servlet:servlet",
+    "//gitiles-dev:lib",
+]
+
+java_library(
+    name = "classpath",
+    runtime_deps = DEPS,
+)
+
+classpath_collector(
+    name = "main_classpath_collect",
+    testonly = 1,
+    deps = DEPS + [
+        "//gitiles-servlet:servlet_tests",
+    ],
+)
+
+# TODO(davido): This is a hack:
+# https://github.com/bazelbuild/bazel/issues/2452
+# We know the py_binary rule,  but for *reasons* we cannot
+# use `buck run <rule>. Unfortunately, a query to retrieve
+# the path was removed in Bazel. So we are forced to do this
+# hack to access python script outside of the Bazel.
+py_binary_path(
+    name = "project.py",
+    py_binary_label = "@com_googlesource_gerrit_bazlets//tools/eclipse:project",
+)
diff --git a/tools/eclipse/project.sh b/tools/eclipse/project.sh
new file mode 100755
index 0000000..e11daa0
--- /dev/null
+++ b/tools/eclipse/project.sh
@@ -0,0 +1,17 @@
+#!/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 build tools/eclipse:project.py
+`bazel info output_base`/`cat bazel-bin/tools/eclipse/project.py.txt` -n gitiles -r .