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'],
+)
diff --git a/gitiles-servlet/pom.xml b/gitiles-servlet/pom.xml
deleted file mode 100644
index 4a41bb5..0000000
--- a/gitiles-servlet/pom.xml
+++ /dev/null
@@ -1,123 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Copyright 2012 Google Inc. All Rights Reserved.
-
-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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-
-  <parent>
-    <groupId>com.google.gitiles</groupId>
-    <artifactId>gitiles-parent</artifactId>
-    <version>1.0-SNAPSHOT</version>
-  </parent>
-
-  <artifactId>gitiles-servlet</artifactId>
-  <name>Gitiles - Servlet</name>
-
-  <description>
-    Gitiles servlet implementation
-  </description>
-
-  <dependencies>
-    <dependency>
-      <groupId>com.google.guava</groupId>
-      <artifactId>guava</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>com.google.template</groupId>
-      <artifactId>soy</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jgit</groupId>
-      <artifactId>org.eclipse.jgit</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jgit</groupId>
-      <artifactId>org.eclipse.jgit.http.server</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jgit</groupId>
-      <artifactId>org.eclipse.jgit.archive</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jgit</groupId>
-      <artifactId>org.eclipse.jgit.junit</artifactId>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>org.eclipse.jgit</groupId>
-          <artifactId>org.eclipse.jgit</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jetty.orbit</groupId>
-      <artifactId>javax.servlet</artifactId>
-      <!-- Gitiles is designed to compile and run against Servlet API 2.5 as
-        well as 3.0; default to the earlier version. -->
-      <version>2.5.0.v201103041518</version>
-      <scope>provided</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>joda-time</groupId>
-      <artifactId>joda-time</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>com.google.code.gson</groupId>
-      <artifactId>gson</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-source-plugin</artifactId>
-        <executions>
-          <execution>
-            <goals>
-              <goal>jar</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-</project>