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/.buckconfig b/.buckconfig
new file mode 100644
index 0000000..78b3922
--- /dev/null
+++ b/.buckconfig
@@ -0,0 +1,15 @@
+[alias]
+  gitiles = //:gitiles
+  all = //:all
+  in = //:install
+  mvn_install = //:install
+  mvn_deploy = //:deploy
+
+[buildfile]
+  includes = //bucklets/java7.bucklet
+
+[java]
+  src_roots = java, resources
+
+[project]
+  ignore = .git
diff --git a/.buckversion b/.buckversion
new file mode 100644
index 0000000..ff1c137
--- /dev/null
+++ b/.buckversion
@@ -0,0 +1 @@
+2b80cf780ae31bee6609ebc1bbab9ce6fd004dbe
diff --git a/.gitignore b/.gitignore
index 461cc3a..5c784fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,5 @@
-.classpath
-.project
-.settings
-*/.classpath
-*/.project
-*/.settings
-*/target
-gitiles.config
+/.classpath
+/.project
+/.settings
+/buck-out
+/gitiles.config
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..f5537df
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "bucklets"]
+	path = bucklets
+	url = ../bucklets
diff --git a/BUCK b/BUCK
new file mode 100644
index 0000000..e9083fc
--- /dev/null
+++ b/BUCK
@@ -0,0 +1,50 @@
+include_defs('//VERSION')
+include_defs('//bucklets/maven_package.bucklet')
+TYPE = 'snapshot' if GITILES_VERSION.endswith('-SNAPSHOT') else 'release'
+
+DEPS = [
+  '//gitiles-servlet:servlet',
+  '//gitiles-servlet:src',
+  '//gitiles-servlet:javadoc',
+  '//gitiles-war:gitiles',
+]
+
+java_library(
+  name = 'classpath',
+  deps = [
+    '//gitiles-servlet:servlet',
+    '//gitiles-servlet:servlet_tests',
+    '//gitiles-dev:dev',
+  ]
+)
+
+maven_package(
+  repository = 'gerrit-api-repository',
+  url = 'gs://gerrit-api/%s' % TYPE,
+  version = GITILES_VERSION,
+  jar = {'gitiles-servlet': '//gitiles-servlet:servlet'},
+  src = {'gitiles-servlet': '//gitiles-servlet:src'},
+  doc = {'gitiles-servlet': '//gitiles-servlet:javadoc'},
+)
+
+def b():
+  a = set()
+  for d in DEPS:
+    n,t = d.split(':')
+    a.add(t)
+    out = "%s.%s" % (t, 'war' if 'war' in n else 'jar')
+    genrule(
+      name = t,
+      cmd = 'ln -s $(location %s) $OUT' % d,
+      deps = [d],
+      out = out,
+    )
+
+  genrule(
+    name = 'all',
+    cmd = 'echo done >$OUT',
+    deps = [':' + e for e in a],
+    out = '__fake.gitiles__',
+  )
+
+b()
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..1302b48
--- /dev/null
+++ b/VERSION
@@ -0,0 +1,6 @@
+# Maven style API version (e.g. '2.x-SNAPSHOT').
+# Used by :imaven_install when talking to the
+# destination repository.
+#
+GITILES_VERSION = '1.0'
+
diff --git a/bucklets b/bucklets
new file mode 160000
index 0000000..29d9255
--- /dev/null
+++ b/bucklets
@@ -0,0 +1 @@
+Subproject commit 29d9255f668b8da42fc4fcd40b2a5e716b9b7a53
diff --git a/fake_pom_deploy.xml b/fake_pom_deploy.xml
new file mode 100644
index 0000000..c4695c6
--- /dev/null
+++ b/fake_pom_deploy.xml
@@ -0,0 +1,29 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.google.gitiles</groupId>
+  <artifactId>Gitiles-Simple-Git-Repository-Browser</artifactId>
+  <version>1</version>
+  <distributionManagement>
+    <repository>
+      <id>gerrit-api-repository</id>
+      <name>Gerrit API Repository</name>
+      <url>gs://gerrit-api</url>
+      <uniqueVersion>true</uniqueVersion>
+    </repository>
+  </distributionManagement>
+  <build>
+    <extensions>
+      <extension>
+        <groupId>com.googlesource.gerrit</groupId>
+        <artifactId>gs-maven-wagon</artifactId>
+        <version>3.3</version>
+      </extension>
+    </extensions>
+  </build>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>gerrit-maven-repository</id>
+      <url>https://gerrit-maven.storage.googleapis.com/</url>
+    </pluginRepository>
+  </pluginRepositories>
+</project>
diff --git a/fake_pom_install.xml b/fake_pom_install.xml
new file mode 100644
index 0000000..b3ed002
--- /dev/null
+++ b/fake_pom_install.xml
@@ -0,0 +1,6 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.google.gitiles</groupId>
+  <artifactId>Gitiles-Simple-Git-Repository-Browser</artifactId>
+  <version>1</version>
+</project>
diff --git a/gitiles-dev/BUCK b/gitiles-dev/BUCK
new file mode 100644
index 0000000..b50f58b
--- /dev/null
+++ b/gitiles-dev/BUCK
@@ -0,0 +1,17 @@
+java_library(
+  name = 'dev',
+  srcs = glob(['src/main/java/**/*.java']),
+  deps = [
+    '//gitiles-servlet:servlet',
+    '//lib:guava',
+    '//lib/jgit:jgit',
+    '//lib/jgit:jgit-servlet',
+    '//lib/jetty:server',
+    '//lib/jetty:servlet',
+    '//lib/slf4j:slf4j-api',
+    '//lib/slf4j:slf4j-simple',
+    '//lib:servlet-api_3_0',
+    '//lib:soy',
+  ],
+  visibility = ['PUBLIC'],
+)
diff --git a/gitiles-dev/pom.xml b/gitiles-dev/pom.xml
deleted file mode 100644
index e89732a..0000000
--- a/gitiles-dev/pom.xml
+++ /dev/null
@@ -1,111 +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-dev</artifactId>
-  <packaging>jar</packaging>
-  <name>Gitiles - Development</name>
-
-  <description>
-    Gitiles running with an embedded Jetty server.
-  </description>
-
-  <properties>
-    <jettyVersion>8.1.7.v20120910</jettyVersion>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <groupId>com.google.gitiles</groupId>
-      <artifactId>gitiles-servlet</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jetty.orbit</groupId>
-      <artifactId>javax.servlet</artifactId>
-      <!-- The bulk of Gitiles is designed to compile and run against Servlet API
-        2.5, but the embedded Jetty 8 in this module only requires Servlet API
-        3.0. -->
-      <version>3.0.0.v201112011016</version>
-      <scope>compile</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-servlet</artifactId>
-      <version>${jettyVersion}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-server</artifactId>
-      <version>${jettyVersion}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-simple</artifactId>
-      <version>${slf4jVersion}</version>
-      <scope>runtime</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-shade-plugin</artifactId>
-        <version>1.7.1</version>
-        <configuration>
-          <transformers>
-            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-              <mainClass>com.google.gitiles.dev.Main</mainClass>
-            </transformer>
-          </transformers>
-          <createDependencyReducedPom>false</createDependencyReducedPom>
-          <filters>
-            <filter>
-              <artifact>*:*</artifact>
-              <excludes>
-                <exclude>META-INF/*.SF</exclude>
-                <exclude>META-INF/*.DSA</exclude>
-                <exclude>META-INF/*.RSA</exclude>
-              </excludes>
-            </filter>
-          </filters>
-        </configuration>
-        <executions>
-          <execution>
-            <phase>package</phase>
-            <goals>
-              <goal>shade</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-</project>
diff --git a/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java b/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java
index 273873d..c32cd8e 100644
--- a/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java
+++ b/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java
@@ -110,9 +110,9 @@
       throw badSourceRoot(targetUri);
     }
     String targetPath = targetUri.getPath();
-    // targetPath is an arbitrary path under gitiles-dev/target in the standard
-    // Maven package layout.
-    int targetIndex = targetPath.lastIndexOf("gitiles-dev/target/");
+    // targetPath is an arbitrary path under buck-out/ in our Buck package
+    // layout.
+    int targetIndex = targetPath.lastIndexOf("buck-out/");
     if (targetIndex < 0) {
       throw badSourceRoot(targetUri);
     }
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>
diff --git a/gitiles-war/BUCK b/gitiles-war/BUCK
new file mode 100644
index 0000000..7b5dd36
--- /dev/null
+++ b/gitiles-war/BUCK
@@ -0,0 +1,21 @@
+include_defs('//bucklets/war.bucklet')
+
+war(
+  name = 'gitiles',
+  libs = ['//gitiles-servlet:servlet'],
+  context = [
+    '//gitiles-servlet:static-resources.zip',
+    ':web_xml.zip',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+genrule(
+  name = 'web_xml',
+  cmd = 'mkdir -p $TMP/WEB-INF'
+    + ';cp -r $SRCDIR/src/main/webapp/WEB-INF/web.xml $TMP/WEB-INF'
+    + ';cd $TMP'
+    + ';zip -qr $OUT *',
+  srcs = ['src/main/webapp/WEB-INF/web.xml'],
+  out = 'web_xml.zip',
+)
diff --git a/gitiles-war/pom.xml b/gitiles-war/pom.xml
deleted file mode 100644
index b5369ce..0000000
--- a/gitiles-war/pom.xml
+++ /dev/null
@@ -1,60 +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-war</artifactId>
-  <packaging>war</packaging>
-  <name>Gitiles - WAR</name>
-
-  <description>
-    Gitiles packaged as a standard web application archive
-  </description>
-
-  <dependencies>
-    <dependency>
-      <groupId>com.google.gitiles</groupId>
-      <artifactId>gitiles-servlet</artifactId>
-      <version>${project.version}</version>
-      <scope>runtime</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-war-plugin</artifactId>
-        <configuration>
-          <webResources>
-            <resource>
-              <directory>../gitiles-servlet/src/main/resources/com/google/gitiles/static</directory>
-              <targetPath>+static</targetPath>
-            </resource>
-          </webResources>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-</project>
diff --git a/lib/BUCK b/lib/BUCK
new file mode 100644
index 0000000..45011ed
--- /dev/null
+++ b/lib/BUCK
@@ -0,0 +1,61 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+maven_jar(
+  name = 'guava',
+  id = 'com.google.guava:guava:16.0',
+  sha1 = 'aca09d2e5e8416bf91550e72281958e35460be52',
+)
+
+maven_jar(
+  name = 'soy',
+  id = 'com.google.template:soy:2011-22-12',
+  sha1 = '018c567dd937176a3c4f81623b899cea3fe61458',
+)
+
+maven_jar(
+  name = 'servlet-api_2_5',
+  id = 'org.eclipse.jetty.orbit:javax.servlet:2.5.0.v201103041518',
+  sha1 = '9c16011c06bc6fe5e9dba080fcb40ddb4b75dc85',
+)
+
+maven_jar(
+  name = 'servlet-api_3_0',
+  id = 'org.eclipse.jetty.orbit:javax.servlet:3.0.0.v201112011016',
+  sha1 = '0aaaa85845fb5c59da00193f06b8e5278d8bf3f8',
+)
+
+maven_jar(
+  name = 'joda-time',
+  id = 'joda-time:joda-time:2.3',
+  sha1 = '56498efd17752898cfcc3868c1b6211a07b12b8f',
+  exclude = [
+    'META-INF/LICENSE.txt',
+    'META-INF/NOTICE.txt',
+  ],
+)
+
+maven_jar(
+  name = 'gson',
+  id = 'com.google.code.gson:gson:2.1',
+  sha1 = '2e66da15851f9f5b5079228f856c2f090ba98c38',
+)
+
+maven_jar(
+  name = 'commons-lang',
+  id = 'org.apache.commons:commons-lang3:3.1',
+  sha1 = '905075e6c80f206bbe6cf1e809d2caa69f420c76',
+)
+
+maven_jar(
+  name = 'junit',
+  id = 'junit:junit:4.11',
+  sha1 = '4e031bb61df09069aeb2bffb4019e7a5034a4ee0',
+  deps = [':hamcrest-core'],
+)
+
+maven_jar(
+  name = 'hamcrest-core',
+  id = 'org.hamcrest:hamcrest-core:1.3',
+  sha1 = '42a25dc3219429f0e5d060061f71acb49bf010a0',
+  visibility = ['//lib:junit'],
+)
diff --git a/lib/guice/BUCK b/lib/guice/BUCK
new file mode 100644
index 0000000..1643150
--- /dev/null
+++ b/lib/guice/BUCK
@@ -0,0 +1,74 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERSION = '4.0-beta'
+EXCLUDE = [
+  'META-INF/DEPENDENCIES',
+  'META-INF/LICENSE',
+  'META-INF/NOTICE',
+]
+
+java_library(
+  name = 'guice',
+  exported_deps = [
+    ':guice_library',
+    ':guice-assistedinject',
+    ':multibindings',
+    ':javax-inject',
+    ':aopalliance',
+    ':jsr305',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'multibindings',
+  id = 'com.google.inject.extensions:guice-multibindings:' + VERSION,
+  exclude_java_sources = True,
+  exclude = EXCLUDE + [
+    'META-INF/maven/com.google.guava/guava/pom.properties',
+    'META-INF/maven/com.google.guava/guava/pom.xml',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'guice_library',
+  id = 'com.google.inject:guice:' + VERSION,
+  sha1 = 'a82be989679df08b66d48b42659a3ca2daaf1d5b',
+  deps = [':aopalliance'],
+  exclude_java_sources = True,
+  exclude = EXCLUDE + [
+    'META-INF/maven/com.google.guava/guava/pom.properties',
+    'META-INF/maven/com.google.guava/guava/pom.xml',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'guice-assistedinject',
+  id = 'com.google.inject.extensions:guice-assistedinject:' + VERSION,
+  sha1 = 'abd6511011a9e4b64e2ebb60caac2e1cd6cd19a1',
+  exclude = EXCLUDE,
+)
+
+maven_jar(
+  name = 'aopalliance',
+  id = 'aopalliance:aopalliance:1.0',
+  sha1 = '0235ba8b489512805ac13a8f9ea77a1ca5ebe3e8',
+  visibility = ['//lib/guice:guice'],
+)
+
+maven_jar(
+  name = 'javax-inject',
+  id = 'javax.inject:javax.inject:1',
+  sha1 = '6975da39a7040257bd51d21a231b76c915872d38',
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'jsr305',
+  id = 'com.google.code.findbugs:jsr305:1.3.9',
+  sha1 = '40719ea6961c0cb6afaeb6a921eaa1f6afd4cfdf',
+  attach_source = False,
+)
+
diff --git a/lib/jetty/BUCK b/lib/jetty/BUCK
new file mode 100644
index 0000000..525f94c
--- /dev/null
+++ b/lib/jetty/BUCK
@@ -0,0 +1,67 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERS = '8.1.7.v20120910'
+EXCLUDE = ['about.html']
+
+maven_jar(
+  name = 'servlet',
+  id = 'org.eclipse.jetty:jetty-servlet:' + VERS,
+  sha1 = '93da01e3ea26e70449e9a1a0affa5c31436be5a0',
+  deps = [
+    ':security',
+    '//lib:servlet-api_3_0',  # Different from the rest of gitlies-server.
+  ],
+  exclude = EXCLUDE,
+)
+
+maven_jar(
+  name = 'security',
+  id = 'org.eclipse.jetty:jetty-security:' + VERS,
+  sha1 = '8d78beb7a07f4cccee05a3f16a264f1025946258',
+  deps = [':server'],
+  exclude = EXCLUDE,
+  visibility = [],
+)
+
+maven_jar(
+  name = 'server',
+  id = 'org.eclipse.jetty:jetty-server:' + VERS,
+  sha1 = '6c81f733f28713919e99c2f8952e6ca5178033cd',
+  exported_deps = [
+    ':continuation',
+    ':http',
+  ],
+  exclude = EXCLUDE,
+)
+
+maven_jar(
+  name = 'continuation',
+  id = 'org.eclipse.jetty:jetty-continuation:' + VERS,
+  sha1 = 'f60cfe6267038000b459508529c88737601081e4',
+  exclude = EXCLUDE,
+)
+
+maven_jar(
+  name = 'http',
+  id = 'org.eclipse.jetty:jetty-http:' + VERS,
+  sha1 = '10126433876cd74534695f7f99c4362596555493',
+  exported_deps = [':io'],
+  exclude = EXCLUDE,
+)
+
+maven_jar(
+  name = 'io',
+  id = 'org.eclipse.jetty:jetty-io:' + VERS,
+  sha1 = 'a81f746ae1b10c37e1bb0a01d1374c202c0bd549',
+  exported_deps = [':util'],
+  exclude = EXCLUDE,
+  visibility = [],
+)
+
+maven_jar(
+  name = 'util',
+  id = 'org.eclipse.jetty:jetty-util:' + VERS,
+  sha1 = '7eb2004ab2c22fd3b00095bd9ba0f32a9e88f6a5',
+  exclude = EXCLUDE,
+  visibility = [],
+)
diff --git a/lib/jgit/BUCK b/lib/jgit/BUCK
new file mode 100644
index 0000000..904c2ce
--- /dev/null
+++ b/lib/jgit/BUCK
@@ -0,0 +1,81 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERS = '3.1.0.201310021548-r'
+
+maven_jar(
+  name = 'jgit',
+  id = 'org.eclipse.jgit:org.eclipse.jgit:' + VERS,
+  bin_sha1 = 'df1410e5d1deaacfb70a2441b4766b61f2795bc3',
+  src_sha1 = 'b4e3d9c9c3da39b72acf72bd913ce9dbee88a9d4',
+  unsign = True,
+  deps = [':ewah'],
+  exclude = [
+    'META-INF/eclipse.inf',
+    'about.html',
+    'plugin.properties',
+  ],
+)
+
+maven_jar(
+  name = 'jgit-servlet',
+  id = 'org.eclipse.jgit:org.eclipse.jgit.http.server:' + VERS,
+  sha1 = 'bcac91120afac59c195230537bde07175578fe79',
+  deps = [':jgit'],
+  unsign = True,
+  exclude = [
+    'about.html',
+    'plugin.properties',
+  ],
+)
+
+java_library(
+  name = 'jgit-archive',
+  exported_deps = [
+    ':jgit-archive_library',
+    ':commons-compress',
+    ':tukaani-xz',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'jgit-archive_library',
+  id = 'org.eclipse.jgit:org.eclipse.jgit.archive:' + VERS,
+  sha1 = '1b34da51d8d46cd04b09454ee84b11f1d117e801',
+  deps = [':jgit'],
+  unsign = True,
+  exclude = [
+    'about.html',
+    'plugin.properties',
+  ],
+)
+
+maven_jar(
+  name = 'junit',
+  id = 'org.eclipse.jgit:org.eclipse.jgit.junit:' + VERS,
+  sha1 = 'a8b47bb41cec25b1d128f7d267badbc7dcf6d9aa',
+  unsign = True,
+  deps = [':jgit'],
+)
+
+maven_jar(
+  name = 'ewah',
+  id = 'com.googlecode.javaewah:JavaEWAH:0.7.9',
+  sha1 = 'eceaf316a8faf0e794296ebe158ae110c7d72a5a',
+)
+
+maven_jar(
+  name = 'commons-compress',
+  id = 'org.apache.commons:commons-compress:1.7',
+  sha1 = 'ab365c96ee9bc88adcc6fa40d185c8e15a31410d',
+  exclude = ['META-INF/LICENSE.txt', 'META-INF/NOTICE.txt'],
+  visibility = ['//lib/jgit:jgit-archive'],
+)
+
+maven_jar(
+  name = 'tukaani-xz',
+  id = 'org.tukaani:xz:1.4',
+  sha1 = '18a9a2ce6abf32ea1b5fd31dae5210ad93f4e5e3',
+  attach_source = False,
+  visibility = ['//lib/jgit:jgit-archive'],
+)
diff --git a/lib/slf4j/BUCK b/lib/slf4j/BUCK
new file mode 100644
index 0000000..b04b670
--- /dev/null
+++ b/lib/slf4j/BUCK
@@ -0,0 +1,19 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERS = '1.6.1'
+
+maven_jar(
+  name = 'slf4j-api',
+  id = 'org.slf4j:slf4j-api:' + VERS,
+  sha1 = '6f3b8a24bf970f17289b234284c94f43eb42f0e4',
+  visibility = ['PUBLIC'],
+)
+
+
+maven_jar(
+  name = 'slf4j-simple',
+  id = 'org.slf4j:slf4j-simple:' + VERS,
+  sha1 = '58e59bfb3e247097b8122243b3bfe0049c8cfae8',
+  deps = [':slf4j-api'],
+  visibility = ['PUBLIC'],
+)
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 2d8e8a6..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,205 +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>
-
-  <groupId>com.google.gitiles</groupId>
-  <artifactId>gitiles-parent</artifactId>
-  <packaging>pom</packaging>
-  <version>1.0-SNAPSHOT</version>
-
-  <name>Gitiles - Parent</name>
-  <url>https://gerrit.googlesource.com/gitiles</url>
-
-  <description>
-    Gitiles - Simple Git Repository Browser
-  </description>
-
-  <properties>
-    <!-- Should track Gerrit's versions fairly closely. -->
-    <jgitVersion>3.1.0.201310021548-r</jgitVersion>
-    <slf4jVersion>1.6.1</slf4jVersion>
-  </properties>
-
-  <modules>
-    <module>gitiles-dev</module>
-    <module>gitiles-servlet</module>
-    <module>gitiles-war</module>
-  </modules>
-
-  <dependencyManagement>
-    <dependencies>
-      <dependency>
-        <groupId>com.google.guava</groupId>
-        <artifactId>guava</artifactId>
-        <version>14.0</version>
-      </dependency>
-
-      <dependency>
-        <groupId>com.google.template</groupId>
-        <artifactId>soy</artifactId>
-        <version>2011-22-12</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.eclipse.jgit</groupId>
-        <artifactId>org.eclipse.jgit</artifactId>
-        <version>${jgitVersion}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.eclipse.jgit</groupId>
-        <artifactId>org.eclipse.jgit.http.server</artifactId>
-        <version>${jgitVersion}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.eclipse.jgit</groupId>
-        <artifactId>org.eclipse.jgit.archive</artifactId>
-        <version>${jgitVersion}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.eclipse.jgit</groupId>
-        <artifactId>org.eclipse.jgit.junit</artifactId>
-        <version>${jgitVersion}</version>
-        <exclusions>
-          <exclusion>
-            <groupId>org.eclipse.jgit</groupId>
-            <artifactId>org.eclipse.jgit</artifactId>
-          </exclusion>
-        </exclusions>
-      </dependency>
-
-      <dependency>
-        <groupId>junit</groupId>
-        <artifactId>junit</artifactId>
-        <version>4.11</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>slf4j-api</artifactId>
-        <version>${slf4jVersion}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>joda-time</groupId>
-        <artifactId>joda-time</artifactId>
-        <version>2.1</version>
-      </dependency>
-
-      <dependency>
-        <groupId>com.google.code.gson</groupId>
-        <artifactId>gson</artifactId>
-        <version>2.1</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.apache.commons</groupId>
-        <artifactId>commons-lang3</artifactId>
-        <version>3.1</version>
-      </dependency>
-    </dependencies>
-  </dependencyManagement>
-
-  <build>
-    <pluginManagement>
-      <plugins>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-compiler-plugin</artifactId>
-          <version>2.3.2</version>
-          <configuration>
-            <source>1.7</source>
-            <target>1.7</target>
-            <encoding>UTF-8</encoding>
-          </configuration>
-        </plugin>
-
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-jar-plugin</artifactId>
-          <configuration>
-            <archive>
-              <manifestEntries>
-                <Implementation-Title>Gitiles - ${project.artifactId}</Implementation-Title>
-                <Implementation-Version>${project.version}</Implementation-Version>
-                <Implementation-Vendor>Gitiles</Implementation-Vendor>
-                <Implementation-Vendor-Id>com.google.gitiles</Implementation-Vendor-Id>
-                <Implementation-Vendor-URL>https://gerrit.googlesource.com/gitiles/</Implementation-Vendor-URL>
-              </manifestEntries>
-            </archive>
-          </configuration>
-        </plugin>
-
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-war-plugin</artifactId>
-          <version>2.1.1</version>
-        </plugin>
-
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-source-plugin</artifactId>
-          <version>2.1.2</version>
-        </plugin>
-      </plugins>
-    </pluginManagement>
-
-    <extensions>
-      <!-- Uncomment to deploy with mvn:deploy. -->
-      <!--
-      <extension>
-        <groupId>com.googlesource.gerrit</groupId>
-        <artifactId>gs-maven-wagon</artifactId>
-        <version>3.3</version>
-      </extension>
-      -->
-    </extensions>
-  </build>
-
-  <repositories>
-    <!-- For JGit and Soy snapshots. -->
-    <repository>
-      <id>gerrit-maven</id>
-      <url>https://gerrit-maven.commondatastorage.googleapis.com</url>
-    </repository>
-
-    <repository>
-      <id>jgit-repository</id>
-      <url>https://repo.eclipse.org/content/groups/releases</url>
-    </repository>
-
-    <repository>
-      <id>java.net-repository</id>
-      <url>http://download.java.net/maven/2/</url>
-    </repository>
-  </repositories>
-
-  <!-- Uncomment to deploy with mvn:deploy. -->
-  <!--
-  <distributionManagement>
-    <repository>
-      <id>gerrit-maven-repository</id>
-      <url>gs://gerrit-maven</url>
-      <uniqueVersion>true</uniqueVersion>
-    </repository>
-  </distributionManagement>
-  -->
-</project>
diff --git a/tools/gitiles-dev.launch b/tools/gitiles-dev.launch
deleted file mode 100644
index 5f07540..0000000
--- a/tools/gitiles-dev.launch
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
-<stringAttribute key="bad_container_name" value="tools/gitiles-dev.launch"/>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/gitiles-dev/src/main/java/com/google/gitiles/dev/Main.java"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="1"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
-<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
-<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
-</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.gitiles.dev.Main"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gitiles-dev"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:gitiles-parent}/../gitiles_test_site"/>
-</launchConfiguration>