Make it easier to use protos in Bazel out of the box.
java_xxx_proto_library rules now look for toolchains in the external repo @com_google_protobuf_xxx//:xxx_toolchain

This still requires getting protobuf's GitHub repository to build with Bazel.

--
MOS_MIGRATED_REVID=140420903
diff --git a/WORKSPACE b/WORKSPACE
index 2cd2e14..666b8df 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -59,3 +59,8 @@
 bind(name = "protobuf/java_runtime", actual = "//third_party/protobuf:protobuf")
 bind(name = "protobuf/javalite_runtime", actual = "//third_party/protobuf:protobuf-lite")
 bind(name = "proto/toolchains/java", actual = "//third_party/protobuf:java_toolchain")
+new_local_repository(
+    name = "com_google_protobuf_java",
+    path = "./third_party/protobuf/3.0.0/",
+    build_file = "./third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD",
+)
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java
index ac5e751..f628e39 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java
@@ -19,7 +19,11 @@
 
 /** An Aspect which BazelJavaLiteProtoLibrary injects to build Java Lite protos. */
 public class BazelJavaLiteProtoAspect extends JavaLiteProtoAspect {
+
+  public static final String DEFAULT_PROTO_TOOLCHAIN_LABEL =
+      "@com_google_protobuf_javalite//:javalite_toolchain";
+
   public BazelJavaLiteProtoAspect() {
-    super(BazelJavaSemantics.INSTANCE, null /* jacocoLabel */);
+    super(BazelJavaSemantics.INSTANCE, null /* jacocoLabel */, DEFAULT_PROTO_TOOLCHAIN_LABEL);
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java
index 739de4b..a608d63 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java
@@ -14,12 +14,13 @@
 
 package com.google.devtools.build.lib.bazel.rules.java.proto;
 
+import static com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaLiteProtoAspect.DEFAULT_PROTO_TOOLCHAIN_LABEL;
 import static com.google.devtools.build.lib.packages.Aspect.INJECTING_RULE_KIND_PARAMETER_KEY;
 import static com.google.devtools.build.lib.packages.Attribute.attr;
 import static com.google.devtools.build.lib.packages.BuildType.LABEL;
 import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 import static com.google.devtools.build.lib.rules.java.proto.JavaLiteProtoAspect.PROTO_TOOLCHAIN_ATTR;
-import static com.google.devtools.build.lib.rules.java.proto.JavaLiteProtoAspect.PROTO_TOOLCHAIN_LABEL;
+import static com.google.devtools.build.lib.rules.java.proto.JavaLiteProtoAspect.getProtoToolchainLabel;
 import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.common.base.Function;
@@ -81,7 +82,7 @@
                 .mandatoryNativeProviders(
                     ImmutableList.<Class<? extends TransitiveInfoProvider>>of(
                         ProtoLangToolchainProvider.class))
-                .value(PROTO_TOOLCHAIN_LABEL))
+                .value(getProtoToolchainLabel(DEFAULT_PROTO_TOOLCHAIN_LABEL)))
         .build();
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java
index 8dd2ae2..e1f15c0 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java
@@ -37,7 +37,8 @@
     super(
         BazelJavaSemantics.INSTANCE,
         null, /* jacocoAttr */
-        new NoopRpcSupport());
+        new NoopRpcSupport(),
+        "@com_google_protobuf_java//:java_toolchain");
   }
 
   private static class NoopRpcSupport
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
index 7ae7cad..e8fa346 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
@@ -66,22 +66,29 @@
 
   public static final String PROTO_TOOLCHAIN_ATTR = ":aspect_proto_toolchain_for_javalite";
 
-  public static final Attribute.LateBoundLabel<BuildConfiguration> PROTO_TOOLCHAIN_LABEL =
-      new Attribute.LateBoundLabel<BuildConfiguration>(
-          "//tools/proto/toolchains:javalite", ProtoConfiguration.class) {
-        @Override
-        public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
-          return configuration.getFragment(ProtoConfiguration.class).protoToolchainForJavaLite();
-        }
-      };
+  public static Attribute.LateBoundLabel<BuildConfiguration> getProtoToolchainLabel(
+      String defaultValue) {
+    return new Attribute.LateBoundLabel<BuildConfiguration>(
+        defaultValue, ProtoConfiguration.class) {
+      @Override
+      public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
+        return configuration.getFragment(ProtoConfiguration.class).protoToolchainForJavaLite();
+      }
+    };
+  }
 
   private final JavaSemantics javaSemantics;
 
   @Nullable private final String jacocoLabel;
+  private final String defaultProtoToolchainLabel;
 
-  public JavaLiteProtoAspect(JavaSemantics javaSemantics, @Nullable String jacocoLabel) {
+  public JavaLiteProtoAspect(
+      JavaSemantics javaSemantics,
+      @Nullable String jacocoLabel,
+      String defaultProtoToolchainLabel) {
     this.javaSemantics = javaSemantics;
     this.jacocoLabel = jacocoLabel;
+    this.defaultProtoToolchainLabel = defaultProtoToolchainLabel;
   }
 
   @Override
@@ -112,7 +119,7 @@
                     .mandatoryNativeProviders(
                         ImmutableList.<Class<? extends TransitiveInfoProvider>>of(
                             ProtoLangToolchainProvider.class))
-                    .value(PROTO_TOOLCHAIN_LABEL))
+                    .value(getProtoToolchainLabel(defaultProtoToolchainLabel)))
             .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK))
             .add(
                 attr(":java_toolchain", LABEL)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
index 9de5625..5c0b292 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
@@ -97,27 +97,32 @@
         }
       };
 
-  private static final Attribute.LateBoundLabel<BuildConfiguration> SPEED_PROTO_TOOLCHAIN_LABEL =
-      new Attribute.LateBoundLabel<BuildConfiguration>(
-          "//tools/proto/toolchains:java", ProtoConfiguration.class) {
-        @Override
-        public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
-          return configuration.getFragment(ProtoConfiguration.class).protoToolchainForJava();
-        }
-      };
+  private static Attribute.LateBoundLabel<BuildConfiguration> getSpeedProtoToolchainLabel(
+      String defaultValue) {
+    return new Attribute.LateBoundLabel<BuildConfiguration>(
+        defaultValue, ProtoConfiguration.class) {
+      @Override
+      public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
+        return configuration.getFragment(ProtoConfiguration.class).protoToolchainForJava();
+      }
+    };
+  }
 
   private final JavaSemantics javaSemantics;
 
   @Nullable private final String jacocoLabel;
   private final RpcSupport rpcSupport;
+  private final String defaultSpeedProtoToolchainLabel;
 
   protected JavaProtoAspect(
       JavaSemantics javaSemantics,
       @Nullable String jacocoLabel,
-      RpcSupport rpcSupport) {
+      RpcSupport rpcSupport,
+      String defaultSpeedProtoToolchainLabel) {
     this.javaSemantics = javaSemantics;
     this.jacocoLabel = jacocoLabel;
     this.rpcSupport = rpcSupport;
+    this.defaultSpeedProtoToolchainLabel = defaultSpeedProtoToolchainLabel;
   }
 
   @Override
@@ -170,7 +175,7 @@
                     // TODO(carmi): reinstate mandatoryNativeProviders(ProtoLangToolchainProvider)
                     // once it's in a Bazel release.
                     .legacyAllowAnyFileType()
-                    .value(SPEED_PROTO_TOOLCHAIN_LABEL))
+                    .value(getSpeedProtoToolchainLabel(defaultSpeedProtoToolchainLabel)))
             .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK))
             .add(
                 attr(":java_toolchain", LABEL)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
index 39be830..ed10c4a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
@@ -115,7 +115,7 @@
 
     @Option(
       name = "proto_toolchain_for_javalite",
-      defaultValue = "//tools/proto/toolchains:javalite",
+      defaultValue = "@com_google_protobuf_javalite//:javalite_toolchain",
       category = "flags",
       converter = BuildConfiguration.EmptyToNullLabelConverter.class,
       help = "Label of proto_lang_toolchain() which describes how to compile JavaLite protos"
@@ -124,7 +124,7 @@
 
     @Option(
       name = "proto_toolchain_for_java",
-      defaultValue = "//tools/proto/toolchains:java",
+      defaultValue = "@com_google_protobuf_java//:java_toolchain",
       category = "flags",
       converter = BuildConfiguration.EmptyToNullLabelConverter.class,
       help = "Label of proto_lang_toolchain() which describes how to compile Java protos"
diff --git a/third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD b/third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD
new file mode 100644
index 0000000..ce43ac8
--- /dev/null
+++ b/third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD
@@ -0,0 +1,13 @@
+load(":proto_lang_toolchain_if_exists.bzl", "proto_lang_toolchain")
+
+java_import(
+    name = "protobuf",
+    jars = ["protobuf-java-3.0.0.jar"],
+)
+
+proto_lang_toolchain(
+    name = "java_toolchain",
+    command_line = "--java_out=shared,immutable:$(OUT)",
+    runtime = ":protobuf",
+    visibility = ["//visibility:public"],
+)