Buck: Create javadoc from source archive

javadoc accepts source archive and we need to create one anyway. So
instead of trying to use the sources in the tree and guess the root
project directory, just use the source archive. We extact the archive
in temporary directory to make javadoc work.

Change-Id: Ib605f6cdab4742a23789da8fbc9c963c83e5b6d9
diff --git a/tools/java_doc.defs b/tools/java_doc.defs
index 65865bb..b8778bb 100644
--- a/tools/java_doc.defs
+++ b/tools/java_doc.defs
@@ -2,20 +2,18 @@
     name,
     title,
     pkgs,
-    paths,
+    source_jar,
     srcs = [],
     deps = [],
     visibility = [],
-    do_it_wrong = False,
   ):
-  if do_it_wrong:
-    sourcepath = paths
-  else:
-    sourcepath = ['$SRCDIR/' + n for n in paths]
+  # TODO(davido): Actually we shouldn't need to extract the source
+  # archive, javadoc should just work with provided archive.
   genrule(
     name = name,
     cmd = ' '.join([
-      'while ! test -f .buckconfig; do cd ..; done;',
+      'mkdir $TMP/sourcepath &&',
+      'unzip $(location %s) -d $TMP/sourcepath &&' % source_jar,
       'javadoc',
       '-quiet',
       '-protected',
@@ -26,8 +24,7 @@
       '-link http://docs.oracle.com/javase/7/docs/api',
       '-subpackages ',
       ':'.join(pkgs),
-      '-sourcepath ',
-      ':'.join(sourcepath),
+      '-sourcepath $TMP/sourcepath',
       ' -classpath ',
       ':'.join(['$(classpath %s)' % n for n in deps]),
       '-d $TMP',
@@ -35,4 +32,4 @@
     srcs = srcs,
     out = name + '.jar',
     visibility = visibility,
-)
+  )