Supply temporary directory to genrule() invoked java_binary()

JVMs on UNIX systems typically hardcode to use /tmp as the default
temporary area, unless system property java.io.tmpdir is set on
the command line. Pass the genrule's TMP location to the binary
as a system property so it can be used automatically.
diff --git a/src/com/facebook/buck/java/JavaBinaryRule.java b/src/com/facebook/buck/java/JavaBinaryRule.java
index 2f3fef4..0d8c8bc 100644
--- a/src/com/facebook/buck/java/JavaBinaryRule.java
+++ b/src/com/facebook/buck/java/JavaBinaryRule.java
@@ -43,6 +43,7 @@
 import com.google.common.collect.Iterables;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
 
 import javax.annotation.Nullable;
@@ -173,15 +174,23 @@
 
   @Override
   public String getExecutableCommand() {
+    return getExecutableCommand(Collections.<String>emptyList());
+  }
+
+  public String getExecutableCommand(List<String> jvmArgs) {
     Preconditions.checkState(mainClass != null,
         "Must specify a main class for %s in order to to run it.",
         getBuildTarget().getFullyQualifiedName());
-
-    return String.format("java -classpath %s %s",
+    StringBuilder cmd = new StringBuilder();
+    cmd.append("java");
+    if (!jvmArgs.isEmpty()) {
+      cmd.append(' ').append(Joiner.on(' ').join(jvmArgs));
+    }
+    return cmd.append(String.format(" -classpath %s %s",
         Joiner.on(':').join(Iterables.transform(
             getTransitiveClasspathEntries().values(),
             Functions.RELATIVE_TO_ABSOLUTE_PATH)),
-        mainClass);
+        mainClass)).toString();
   }
 
   public static class Builder extends AbstractBuildRuleBuilder<JavaBinaryRule> {
diff --git a/src/com/facebook/buck/shell/Genrule.java b/src/com/facebook/buck/shell/Genrule.java
index f6d6c8d..4f0984e 100644
--- a/src/com/facebook/buck/shell/Genrule.java
+++ b/src/com/facebook/buck/shell/Genrule.java
@@ -16,6 +16,7 @@
 
 package com.facebook.buck.shell;
 
+import com.facebook.buck.java.JavaBinaryRule;
 import com.facebook.buck.model.BuildTarget;
 import com.facebook.buck.rules.AbstractBuildRuleBuilder;
 import com.facebook.buck.rules.AbstractBuildRuleBuilderParams;
@@ -413,7 +414,14 @@
       String cmd,
       BuildRule matchingRule) {
     if (matchingRule instanceof BinaryBuildRule) {
-      return ((BinaryBuildRule) matchingRule).getExecutableCommand();
+      BinaryBuildRule binaryBuildRule = (BinaryBuildRule) matchingRule;
+      if (binaryBuildRule instanceof JavaBinaryRule) {
+        List<String> jvmArgs = Lists.newArrayListWithCapacity(4);
+        jvmArgs.add(String.format("-Djava.io.tmpdir=%s", pathToTmpDirectory));
+        return ((JavaBinaryRule) binaryBuildRule).getExecutableCommand(jvmArgs);
+      } else {
+        return binaryBuildRule.getExecutableCommand();
+      }
     }
 
     File output = filesystem.getFileForRelativePath(matchingRule.getPathToOutputFile());