Gitiles: Implement Buck driven build

Until extension system is released by Buck team [1], factor out
existing Buck building blocks as Bucklets in standalone git
repository and reuse it as Git submodule to implement Buck driven
build [2].

To build gitiles `gitiles` target is used:

  buck build gitiles

To build servlet, sources and javadoc in addition, `all` target is used:

  buck build all

that produces:

  buck-out/gen/gitiles.war
  buck-out/gen/servlet.jar
  buck-out/gen/src.jar
  buck-out/gen/javadoc.jar

To execute the tests:

  buck test --all

To generate eclipse project:

  bucklets/tools/eclipse.py

To fetch sources for all dependent libraries too:

  bucklets/tools/eclipse.py --src

To install gitiles-servlet into local Maven repository:

  buck build mvn_install

To deploy gitiles-servlet into remote Maven repository:

  buck build mvn_deploy

[1] http://stackoverflow.com/questions/16681527/buck-vs-gradle-pros-and-cons-for-android-build-systems
[2] https://gerrit.googlesource.com/bucklets

Change-Id: Ib824dac6423d69c298f9c30ed7a0c05b4d6447c0
diff --git a/gitiles-servlet/BUCK b/gitiles-servlet/BUCK
new file mode 100644
index 0000000..a660aac
--- /dev/null
+++ b/gitiles-servlet/BUCK
@@ -0,0 +1,78 @@
+include_defs('//bucklets/java_library2.bucklet')
+include_defs('//bucklets/java_sources.bucklet')
+include_defs('//bucklets/java_doc.bucklet')
+
+SRCS = glob(['src/main/java/**/*.java'])
+RSRC = glob(['src/main/resources/**/*'])
+DEPS = [
+  '//lib:guava',
+  '//lib:soy',
+  '//lib:joda-time',
+  '//lib:gson',
+  '//lib:commons-lang',
+  '//lib/jgit:jgit',
+  '//lib/jgit:jgit-servlet',
+  '//lib/slf4j:slf4j-api',
+]
+
+DEPS_ALL = DEPS + [
+  '//lib/jgit:jgit-archive',
+  '//lib/guice:guice',
+]
+
+java_library2(
+  name = 'servlet',
+  srcs = SRCS,
+  resources = RSRC,
+  deps = DEPS_ALL,
+  compile_deps = ['//lib:servlet-api_2_5'],
+  visibility = ['PUBLIC'],
+)
+
+java_test(
+  name = 'servlet_tests',
+  srcs = glob(['src/test/java/**/*.java']),
+  deps = DEPS_ALL + [
+    '//lib/jgit:junit',
+    '//lib:junit',
+    # Gitiles is designed to compile against the Servlet API v2.5.
+    '//lib:servlet-api_2_5',
+    ':servlet',
+  ],
+  visibility = ['//:classpath'],
+)
+
+genrule(
+  name = 'static-resources',
+  cmd = 'mkdir $TMP/+static'
+    + ';cd $TMP/+static'
+    + ';cp -r $SRCDIR/src/main/resources/com/google/gitiles/static/* .'
+    + ';cd $TMP'
+    + ';zip -qr $OUT *',
+  srcs = glob(['src/main/resources/com/google/gitiles/static/**/*']),
+  out = 'static-resources.zip',
+  visibility = ['PUBLIC'],
+)
+
+java_sources(
+  name = 'src',
+  srcs = SRCS + RSRC,
+  visibility = ['PUBLIC'],
+)
+
+java_doc(
+  name = 'javadoc',
+  title = 'Gitiles API Documentation',
+  pkg = 'com.google.gitiles',
+  paths = ['gitiles-servlet/src/main/java'],
+  srcs = glob([n + '**/*.java' for n in SRCS]),
+  deps = DEPS + [
+    '//lib/guice:guice_library',
+    '//lib/guice:guice-assistedinject',
+    '//lib/guice:javax-inject',
+    '//lib/guice:jsr305',
+    '//lib/jgit:jgit-archive_library',
+    '//lib:servlet-api_2_5',
+  ],
+  visibility = ['PUBLIC'],
+)