Adds the JackAspect for Jack support for Java dependencies.

This creates a JackAspect which is calculated for Java dependencies of
Android libraries and binaries and their Java dependencies.

Note that this only applies to java_library and java_import at this time
because they are the only ones exporting the necessary provider.

--
MOS_MIGRATED_REVID=95844097
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
index e1ebaec..92eae73 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
@@ -25,6 +25,7 @@
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
 import com.google.devtools.build.lib.rules.java.JavaImportBaseRule;
+import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider;
 
 /**
  * Rule definition for the java_import rule.
@@ -43,6 +44,7 @@
                 "java_library", "java_import", "cc_library", "cc_binary"))
             .allowedFileTypes()  // none allowed
             .validityPredicate(ANY_EDGE))
+        .advertiseProvider(JavaSourceInfoProvider.class)
         .build();
 
   }
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
index eef56df..acc9173 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
@@ -25,6 +25,7 @@
 import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses.JavaRule;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
+import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider;
 
 /**
  * Common attributes for Java rules.
@@ -142,6 +143,7 @@
         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
         .add(attr("exported_plugins", LABEL_LIST).cfg(HOST).allowedRuleClasses("java_plugin")
             .legacyAllowAnyFileType())
+        .advertiseProvider(JavaSourceInfoProvider.class)
         .build();
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java
index 3de4a15..5a9d5e4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java
@@ -42,122 +42,136 @@
     return builder
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(srcs) -->
          The list of source files that are processed to create the target.
-        ${SYNOPSIS}
-        <p><code>srcs</code> files of type <code>.java</code> are compiled.
-        <em>For readability's sake</em>, it is not good to put the name of a
-        generated <code>.java</code> source file into the <code>srcs</code>.
-        Instead, put the depended-on rule name in the <code>srcs</code>, as
-        described below.
-        </p>
-        <p><code>srcs</code> files of type <code>.srcjar</code> are unpacked and
-        compiled. (This is useful if you need to generate a set of .java files with
-        a genrule or build extension.)
-        </p>
-        <p>This rule currently forces source and class compatibility with Java 7,
-        although try with resources is not supported.
-        </p>
-        <p><code>srcs</code> files of type <code>.jar</code> are linked in.
-        (This is useful if you have third-party <code>.jar</code> files
-        with no source.)
-        </p>
-        <p>If <code>srcs</code> is omitted, then any dependency specified in
-        <code>deps</code> is exported from this rule (see
-        <a href="#java_library.exports">java_library's exports</a> for more
-        information about exporting dependencies). However, this behavior will be
-        deprecated soon; try not to rely on it.
-        </p>
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-        .add(attr("srcs", LABEL_LIST)
-            .direct_compile_time_input()
-            .allowedFileTypes(JavaSemantics.JAVA_SOURCE, JavaSemantics.JAR,
-                JavaSemantics.SOURCE_JAR))
+         ${SYNOPSIS}
+         <p><code>srcs</code> files of type <code>.java</code> are compiled.
+         <em>For readability's sake</em>, it is not good to put the name of a
+         generated <code>.java</code> source file into the <code>srcs</code>.
+         Instead, put the depended-on rule name in the <code>srcs</code>, as
+         described below.
+         </p>
+         <p><code>srcs</code> files of type <code>.srcjar</code> are unpacked and
+         compiled. (This is useful if you need to generate a set of .java files with
+         a genrule or build extension.)
+         </p>
+         <p>This rule currently forces source and class compatibility with Java 7,
+         although try with resources is not supported.
+         </p>
+         <p><code>srcs</code> files of type <code>.jar</code> are linked in.
+         (This is useful if you have third-party <code>.jar</code> files
+         with no source.)
+         </p>
+         <p>If <code>srcs</code> is omitted, then any dependency specified in
+         <code>deps</code> is exported from this rule (see
+         <a href="#java_library.exports">java_library's exports</a> for more
+         information about exporting dependencies). However, this behavior will be
+         deprecated soon; try not to rely on it.
+         </p>
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+        .add(
+            attr("srcs", LABEL_LIST)
+                .direct_compile_time_input()
+                .allowedFileTypes(
+                    JavaSemantics.JAVA_SOURCE, JavaSemantics.JAR, JavaSemantics.SOURCE_JAR))
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(deps) -->
-        The list of other libraries to link against.
-        ${SYNOPSIS}
-        Permitted library types are: <code>android_library</code>,
-        <code>java_library</code> with <code>android</code> constraint and
-        <code>cc_library</code> wrapping or producing <code>.so</code> native libraries
-        for the Android target platform.
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-        .override(builder.copy("deps")
-            .allowedRuleClasses(AndroidRuleClasses.ALLOWED_DEPENDENCIES)
-            .allowedFileTypes())
+         The list of other libraries to link against.
+         ${SYNOPSIS}
+         Permitted library types are: <code>android_library</code>,
+         <code>java_library</code> with <code>android</code> constraint and
+         <code>cc_library</code> wrapping or producing <code>.so</code> native libraries
+         for the Android target platform.
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+        .override(
+            builder
+                .copy("deps")
+                .allowedRuleClasses(AndroidRuleClasses.ALLOWED_DEPENDENCIES)
+                .allowedFileTypes()
+                .aspect(AndroidNeverlinkAspect.class)
+                .aspect(JackAspect.class))
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(resources) -->
-        The <code>android_resources</code> target assigned to this library.
-        ${SYNOPSIS}
-        If specified, the resources will be added to any <code>android_binary</code>
-        depending on this library.
-        <p>Only an <code>android_resource</code> rule with the attribute
-        <code>inline_constants</code> set to 0 can be used in this case.</p>
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-        .add(attr("resources", LABEL)
-            .allowedFileTypes()
-            .allowedRuleClasses("android_resources"))
+         The <code>android_resources</code> target assigned to this library.
+         ${SYNOPSIS}
+         If specified, the resources will be added to any <code>android_binary</code>
+         depending on this library.
+         <p>Only an <code>android_resource</code> rule with the attribute
+         <code>inline_constants</code> set to 0 can be used in this case.</p>
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+        .add(attr("resources", LABEL).allowedFileTypes().allowedRuleClasses("android_resources"))
         .add(attr("alwayslink", BOOLEAN).undocumented("purely informational for now"))
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(neverlink) -->
-        Only use this library for compilation and not at runtime.
-        ${SYNOPSIS}
-        The outputs of a rule marked as <code>neverlink</code> will not be used in
-        <code>.apk</code> creation. Useful if the library will be provided by the
-        runtime environment during execution.
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+         Only use this library for compilation and not at runtime.
+         ${SYNOPSIS}
+         The outputs of a rule marked as <code>neverlink</code> will not be used in
+         <code>.apk</code> creation. Useful if the library will be provided by the
+         runtime environment during execution.
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
         .add(attr("neverlink", BOOLEAN).value(false))
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(idl_import_root) -->
-        Package-relative path to the root of the java package tree containing idl
-        sources included in this library.
-        ${SYNOPSIS}
-        This path will be used as the import root when processing idl sources that
-        depend on this library. (See
-        <a href="#android_library_examples.idl_import_root">examples</a>.)
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+         Package-relative path to the root of the java package tree containing idl
+         sources included in this library.
+         ${SYNOPSIS}
+         This path will be used as the import root when processing idl sources that
+         depend on this library. (See
+         <a href="#android_library_examples.idl_import_root">examples</a>.)
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
         .add(attr("idl_import_root", STRING))
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(idl_srcs) -->
-        List of Android IDL definitions to translate to Java interfaces.
-        ${SYNOPSIS}
-        After the Java interfaces are generated, they will be compiled together
-        with the contents of <code>srcs</code>.
-        <p>These files will be made available as imports for any
-        <code>android_library</code> target that depends on this library, directly
-        or via its transitive closure.</p>
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-        .add(attr("idl_srcs", LABEL_LIST).direct_compile_time_input()
-            .allowedFileTypes(AndroidRuleClasses.ANDROID_IDL))
+         List of Android IDL definitions to translate to Java interfaces.
+         ${SYNOPSIS}
+         After the Java interfaces are generated, they will be compiled together
+         with the contents of <code>srcs</code>.
+         <p>These files will be made available as imports for any
+         <code>android_library</code> target that depends on this library, directly
+         or via its transitive closure.</p>
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+        .add(
+            attr("idl_srcs", LABEL_LIST)
+                .direct_compile_time_input()
+                .allowedFileTypes(AndroidRuleClasses.ANDROID_IDL))
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(idl_parcelables) -->
-        List of Android IDL definitions to supply as imports.
-        ${SYNOPSIS}
-        These files will be made available as imports for any
-        <code>android_library</code> target that depends on this library, directly
-        or via its transitive closure, but will not be translated to Java
-        or compiled.
-        <p>Only <code>.aidl</code> files that correspond directly to
-        <code>.java</code> sources in this library should be included (e.g., custom
-        implementations of Parcelable), otherwise <code>idl_srcs</code> should be
-        used.</p>
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-        .add(attr("idl_parcelables", LABEL_LIST).direct_compile_time_input()
-            .allowedFileTypes(AndroidRuleClasses.ANDROID_IDL))
+         List of Android IDL definitions to supply as imports.
+         ${SYNOPSIS}
+         These files will be made available as imports for any
+         <code>android_library</code> target that depends on this library, directly
+         or via its transitive closure, but will not be translated to Java
+         or compiled.
+         <p>Only <code>.aidl</code> files that correspond directly to
+         <code>.java</code> sources in this library should be included (e.g., custom
+         implementations of Parcelable), otherwise <code>idl_srcs</code> should be
+         used.</p>
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+        .add(
+            attr("idl_parcelables", LABEL_LIST)
+                .direct_compile_time_input()
+                .allowedFileTypes(AndroidRuleClasses.ANDROID_IDL))
         /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(proguard_specs) -->
-        Files to be used as Proguard specification.
-        ${SYNOPSIS}
-        These will describe the set of specifications to be used by Proguard. If specified,
-        they will be added to any <code>android_binary</code> target depending on this library.
+         Files to be used as Proguard specification.
+         ${SYNOPSIS}
+         These will describe the set of specifications to be used by Proguard. If specified,
+         they will be added to any <code>android_binary</code> target depending on this library.
 
-        The files included here must only have idempotent rules, namely -dontnote, -dontwarn,
-        assumenosideeffects, and rules that start with -keep. Other options can only appear in
-        <code>android_binary</code>'s proguard_specs, to ensure non-tautological merges.
-        <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+         The files included here must only have idempotent rules, namely -dontnote, -dontwarn,
+         assumenosideeffects, and rules that start with -keep. Other options can only appear in
+         <code>android_binary</code>'s proguard_specs, to ensure non-tautological merges.
+         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
         .add(attr("proguard_specs", LABEL_LIST).legacyAllowAnyFileType())
-        .add(attr("$proguard_whitelister", LABEL).cfg(HOST).exec().value(
-            new Attribute.ComputedDefault() {
-            @Override
-            public Object getDefault(AttributeMap rule) {
-              return rule.isAttributeValueExplicitlySpecified("proguard_specs")
-                  ? env.getLabel("//tools/android:proguard_whitelister")
-                  : null;
-            }
-        }))
-        .add(attr("$android_manifest_merge_tool", LABEL).cfg(HOST).exec().value(env.getLabel(
-            AndroidRuleClasses.MANIFEST_MERGE_TOOL_LABEL)))
+        .add(
+            attr("$proguard_whitelister", LABEL)
+                .cfg(HOST)
+                .exec()
+                .value(
+                    new Attribute.ComputedDefault() {
+                      @Override
+                      public Object getDefault(AttributeMap rule) {
+                        return rule.isAttributeValueExplicitlySpecified("proguard_specs")
+                            ? env.getLabel("//tools/android:proguard_whitelister")
+                            : null;
+                      }
+                    }))
+        .add(
+            attr("$android_manifest_merge_tool", LABEL)
+                .cfg(HOST)
+                .exec()
+                .value(env.getLabel(AndroidRuleClasses.MANIFEST_MERGE_TOOL_LABEL)))
         .advertiseProvider(JavaCompilationArgsProvider.class)
         .build();
   }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
index 3c5077b..7c564ea 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
@@ -570,152 +570,184 @@
     public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) {
       return builder
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(srcs) -->
-          The list of source files that are processed to create the target.
-          ${SYNOPSIS}
-          <p><code>srcs</code> files of type <code>.java</code> are compiled.
-          <em>For readability's sake</em>, it is not good to put the name of a
-          generated <code>.java</code> source file into the <code>srcs</code>.
-          Instead, put the depended-on rule name in the <code>srcs</code>, as
-          described below.
-          </p>
-          <p><code>srcs</code> files of type <code>.srcjar</code> are unpacked and
-          compiled. (This is useful if you need to generate a set of .java files with
-          a genrule or build extension.)
-          </p>
-          <p>This rule currently forces source and class compatibility with Java 6.
-          </p>
-          <p><code>srcs</code> files of type <code>.jar</code> are linked in.
-          (This is useful if you have third-party <code>.jar</code> files
-          with no source.)
-          </p>
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-          .add(attr("srcs", LABEL_LIST)
-              .direct_compile_time_input()
-              .allowedFileTypes(JavaSemantics.JAVA_SOURCE, JavaSemantics.JAR,
-                  JavaSemantics.SOURCE_JAR))
+           The list of source files that are processed to create the target.
+           ${SYNOPSIS}
+           <p><code>srcs</code> files of type <code>.java</code> are compiled.
+           <em>For readability's sake</em>, it is not good to put the name of a
+           generated <code>.java</code> source file into the <code>srcs</code>.
+           Instead, put the depended-on rule name in the <code>srcs</code>, as
+           described below.
+           </p>
+           <p><code>srcs</code> files of type <code>.srcjar</code> are unpacked and
+           compiled. (This is useful if you need to generate a set of .java files with
+           a genrule or build extension.)
+           </p>
+           <p>This rule currently forces source and class compatibility with Java 6.
+           </p>
+           <p><code>srcs</code> files of type <code>.jar</code> are linked in.
+           (This is useful if you have third-party <code>.jar</code> files
+           with no source.)
+           </p>
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+          .add(
+              attr("srcs", LABEL_LIST)
+                  .direct_compile_time_input()
+                  .allowedFileTypes(
+                      JavaSemantics.JAVA_SOURCE, JavaSemantics.JAR, JavaSemantics.SOURCE_JAR))
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(deps) -->
-          The list of other libraries to be linked in to the binary target.
-          ${SYNOPSIS}
-          Permitted library types are: <code>android_library</code>,
-          <code>java_library</code> with <code>android</code> constraint and
-          <code>cc_library</code> wrapping or producing <code>.so</code> native libraries for the
-          Android target platform.
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-          .override(builder.copy("deps")
-              .cfg(ANDROID_SPLIT_TRANSITION)
-              .allowedRuleClasses(ALLOWED_DEPENDENCIES)
-              .allowedFileTypes()
-              .aspect(AndroidNeverlinkAspect.class))
+           The list of other libraries to be linked in to the binary target.
+           ${SYNOPSIS}
+           Permitted library types are: <code>android_library</code>,
+           <code>java_library</code> with <code>android</code> constraint and
+           <code>cc_library</code> wrapping or producing <code>.so</code> native libraries for the
+           Android target platform.
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+          .override(
+              builder
+                  .copy("deps")
+                  .cfg(ANDROID_SPLIT_TRANSITION)
+                  .allowedRuleClasses(ALLOWED_DEPENDENCIES)
+                  .allowedFileTypes()
+                  .aspect(AndroidNeverlinkAspect.class)
+                  .aspect(JackAspect.class))
           // Proguard rule specifying master list of classes to keep during legacy multidexing.
-          .add(attr("$build_incremental_dexmanifest", LABEL).cfg(HOST).exec()
-              .value(env.getLabel(AndroidRuleClasses.BUILD_INCREMENTAL_DEXMANIFEST_LABEL)))
-          .add(attr("$stubify_manifest", LABEL).cfg(HOST).exec()
-              .value(env.getLabel(AndroidRuleClasses.STUBIFY_MANIFEST_LABEL)))
-          .add(attr("$shuffle_jars", LABEL).cfg(HOST).exec()
-              .value(env.getLabel("//tools/android:shuffle_jars")))
-          .add(attr("$merge_dexzips", LABEL).cfg(HOST).exec()
-              .value(env.getLabel("//tools/android:merge_dexzips")))
-          .add(attr("$incremental_install", LABEL).cfg(HOST).exec()
-              .value(env.getLabel(INCREMENTAL_INSTALL_LABEL)))
-          .add(attr("$build_split_manifest", LABEL).cfg(HOST).exec()
-              .value(env.getLabel(BUILD_SPLIT_MANIFEST_LABEL)))
-          .add(attr("$strip_resources", LABEL).cfg(HOST).exec()
-              .value(env.getLabel(AndroidRuleClasses.STRIP_RESOURCES_LABEL)))
-          .add(attr(":incremental_stub_application", LABEL)
-              .value(AndroidRuleClasses.INCREMENTAL_STUB_APPLICATION))
-          .add(attr(":incremental_split_stub_application", LABEL)
-              .value(AndroidRuleClasses.INCREMENTAL_SPLIT_STUB_APPLICATION))
+          .add(
+              attr("$build_incremental_dexmanifest", LABEL)
+                  .cfg(HOST)
+                  .exec()
+                  .value(env.getLabel(AndroidRuleClasses.BUILD_INCREMENTAL_DEXMANIFEST_LABEL)))
+          .add(
+              attr("$stubify_manifest", LABEL)
+                  .cfg(HOST)
+                  .exec()
+                  .value(env.getLabel(AndroidRuleClasses.STUBIFY_MANIFEST_LABEL)))
+          .add(
+              attr("$shuffle_jars", LABEL)
+                  .cfg(HOST)
+                  .exec()
+                  .value(env.getLabel("//tools/android:shuffle_jars")))
+          .add(
+              attr("$merge_dexzips", LABEL)
+                  .cfg(HOST)
+                  .exec()
+                  .value(env.getLabel("//tools/android:merge_dexzips")))
+          .add(
+              attr("$incremental_install", LABEL)
+                  .cfg(HOST)
+                  .exec()
+                  .value(env.getLabel(INCREMENTAL_INSTALL_LABEL)))
+          .add(
+              attr("$build_split_manifest", LABEL)
+                  .cfg(HOST)
+                  .exec()
+                  .value(env.getLabel(BUILD_SPLIT_MANIFEST_LABEL)))
+          .add(
+              attr("$strip_resources", LABEL)
+                  .cfg(HOST)
+                  .exec()
+                  .value(env.getLabel(AndroidRuleClasses.STRIP_RESOURCES_LABEL)))
+          .add(
+              attr(":incremental_stub_application", LABEL)
+                  .value(AndroidRuleClasses.INCREMENTAL_STUB_APPLICATION))
+          .add(
+              attr(":incremental_split_stub_application", LABEL)
+                  .value(AndroidRuleClasses.INCREMENTAL_SPLIT_STUB_APPLICATION))
 
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(debug_key) -->
-          File containing debug keystore to be used to sign debug apk.
-          ${SYNOPSIS}
-          Points to a location of debug keystore file that is different than default
-          debug key. Usually you do not want to use key other than default key, so
-          this attribute should be omitted.
-          <p><em class="harmful">WARNING: Do not use your production keys, they should be
-          strictly safeguarded and not kept in your source tree</em>.</p>
-          <p>This keystore must contain a single key named "AndroidDebugKey", and
-          have a keystore password of "android".
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-          .add(attr("debug_key", LABEL).cfg(HOST).legacyAllowAnyFileType()
-              .value(env.getLabel("//tools/android:debug_keystore")))
+           File containing debug keystore to be used to sign debug apk.
+           ${SYNOPSIS}
+           Points to a location of debug keystore file that is different than default
+           debug key. Usually you do not want to use key other than default key, so
+           this attribute should be omitted.
+           <p><em class="harmful">WARNING: Do not use your production keys, they should be
+           strictly safeguarded and not kept in your source tree</em>.</p>
+           <p>This keystore must contain a single key named "AndroidDebugKey", and
+           have a keystore password of "android".
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+          .add(
+              attr("debug_key", LABEL)
+                  .cfg(HOST)
+                  .legacyAllowAnyFileType()
+                  .value(env.getLabel("//tools/android:debug_keystore")))
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(dexopts) -->
-          Additional command-line flags for the dx tool when generating classes.dex.
-          ${SYNOPSIS}
-          Subject to <a href="#make_variables">"Make variable"</a> substitution and
-          <a href="#sh-tokenization">Bourne shell tokenization</a>.
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+           Additional command-line flags for the dx tool when generating classes.dex.
+           ${SYNOPSIS}
+           Subject to <a href="#make_variables">"Make variable"</a> substitution and
+           <a href="#sh-tokenization">Bourne shell tokenization</a>.
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
           .add(attr("dexopts", STRING_LIST))
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(dex_shards) -->
-          Number of shards dexing should be decomposed into.
-          ${SYNOPSIS}
-          This is makes dexing much faster at the expense of app installation and startup time. The
-          larger the binary, the more shards should be used. 25 is a good value to start
-          experimenting with.
-          <p>
-          Note that each shard will result in at least one dex in the final app. For this reason,
-          setting this to more than 1 is not recommended for release binaries.
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+           Number of shards dexing should be decomposed into.
+           ${SYNOPSIS}
+           This is makes dexing much faster at the expense of app installation and startup time. The
+           larger the binary, the more shards should be used. 25 is a good value to start
+           experimenting with.
+           <p>
+           Note that each shard will result in at least one dex in the final app. For this reason,
+           setting this to more than 1 is not recommended for release binaries.
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
           .add(attr("dex_shards", INTEGER).value(1))
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(main_dex_list_opts) -->
-          Command line options to pass to the main dex list builder.
-          ${SYNOPSIS}
-          Use this option to affect the classes included in the main dex list.
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+           Command line options to pass to the main dex list builder.
+           ${SYNOPSIS}
+           Use this option to affect the classes included in the main dex list.
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
           .add(attr("main_dex_list_opts", STRING_LIST))
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(main_dex_list) -->
 
-          A text file contains a list of class file names. Classes defined by those class files are
-          put in the primary classes.dex. e.g.:<pre class="code">
-android/support/multidex/MultiDex$V19.class
-android/support/multidex/MultiDex.class
-android/support/multidex/MultiDexApplication.class
-com/google/common/base/Objects.class
-          </pre>
-          ${SYNOPSIS}
-          Must be used with <code>multidex="manual_main_dex"</code>.
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+           A text file contains a list of class file names. Classes defined by those class files are
+           put in the primary classes.dex. e.g.:<pre class="code">
+           android/support/multidex/MultiDex$V19.class
+           android/support/multidex/MultiDex.class
+           android/support/multidex/MultiDexApplication.class
+           com/google/common/base/Objects.class
+           </pre>
+           ${SYNOPSIS}
+           Must be used with <code>multidex="manual_main_dex"</code>.
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
           .add(attr("main_dex_list", LABEL).legacyAllowAnyFileType())
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(proguard_specs) -->
-          Files to be used as Proguard specification.
-          ${SYNOPSIS}
-          This file will describe the set of specifications to be used by Proguard.
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+           Files to be used as Proguard specification.
+           ${SYNOPSIS}
+           This file will describe the set of specifications to be used by Proguard.
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
           .add(attr("proguard_specs", LABEL_LIST).legacyAllowAnyFileType())
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(proguard_generate_mapping) -->
-          Whether to generate Proguard mapping file.
-          ${SYNOPSIS}
-          The mapping file will be generated only if <code>proguard_specs</code> is
-          specified. This file will list the mapping between the original and
-          obfuscated class, method, and field names.
-          <p><em class="harmful">WARNING: If you use this attribute, your Proguard specification
-          should contain neither <code>-dontobfuscate</code> nor <code>-printmapping</code>.
-          </em>.</p>
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-          .add(attr("proguard_generate_mapping", BOOLEAN).value(false)
-              .nonconfigurable("value is referenced in an ImplicitOutputsFunction"))
+           Whether to generate Proguard mapping file.
+           ${SYNOPSIS}
+           The mapping file will be generated only if <code>proguard_specs</code> is
+           specified. This file will list the mapping between the original and
+           obfuscated class, method, and field names.
+           <p><em class="harmful">WARNING: If you use this attribute, your Proguard specification
+           should contain neither <code>-dontobfuscate</code> nor <code>-printmapping</code>.
+           </em>.</p>
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+          .add(
+              attr("proguard_generate_mapping", BOOLEAN)
+                  .value(false)
+                  .nonconfigurable("value is referenced in an ImplicitOutputsFunction"))
           /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(legacy_native_support) -->
-          Enables legacy native support, where pre-compiled native libraries are copied
-          directly into the APK.
-          ${SYNOPSIS}
-          Possible values:
-          <ul>
-              <li><code>legacy_native_support = 1</code>: Pre-built .so files found in the
-                dependencies of cc_libraries in the transitive closure will be copied into
-                the APK without being modified in any way. All cc_libraries in the transitive
-                closure of this rule must wrap .so files. (<em class="harmful">deprecated</em> -
-                legacy_native_support = 0 will become the default and this attribute will be
-                removed in a future Blaze release.)</li>
-              <li><code>legacy_native_support = 0</code>: Native dependencies in the transitive
-                closure will be linked together into a single lib[ruleName].so
-                before being placed in the APK. This ensures that, e.g., only one copy of
-                //base will be loaded into memory. This lib[ruleName].so can be loaded
-                via System.loadLibrary as normal.</li>
-              <li><code>legacy_native_support = -1</code>: Linking is controlled by the
-                <a href="blaze-user-manual.html#flag--legacy_android_native_support">
-                --[no]legacy_android_native_support</a> Blaze flag.</li>
-            </ul>
-          <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+           Enables legacy native support, where pre-compiled native libraries are copied
+           directly into the APK.
+           ${SYNOPSIS}
+           Possible values:
+           <ul>
+           <li><code>legacy_native_support = 1</code>: Pre-built .so files found in the
+           dependencies of cc_libraries in the transitive closure will be copied into
+           the APK without being modified in any way. All cc_libraries in the transitive
+           closure of this rule must wrap .so files. (<em class="harmful">deprecated</em> -
+           legacy_native_support = 0 will become the default and this attribute will be
+           removed in a future Blaze release.)</li>
+           <li><code>legacy_native_support = 0</code>: Native dependencies in the transitive
+           closure will be linked together into a single lib[ruleName].so
+           before being placed in the APK. This ensures that, e.g., only one copy of
+           //base will be loaded into memory. This lib[ruleName].so can be loaded
+           via System.loadLibrary as normal.</li>
+           <li><code>legacy_native_support = -1</code>: Linking is controlled by the
+           <a href="blaze-user-manual.html#flag--legacy_android_native_support">
+           --[no]legacy_android_native_support</a> Blaze flag.</li>
+           </ul>
+           <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
           .add(attr("legacy_native_support", TRISTATE).value(TriState.AUTO))
           .advertiseProvider(JavaCompilationArgsProvider.class)
           .build();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java
new file mode 100644
index 0000000..236ce56
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java
@@ -0,0 +1,120 @@
+// Copyright 2015 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.
+
+package com.google.devtools.build.lib.rules.android;
+
+import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST;
+import static com.google.devtools.build.lib.packages.Attribute.attr;
+import static com.google.devtools.build.lib.packages.Type.LABEL;
+import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.Aspect;
+import com.google.devtools.build.lib.analysis.ConfiguredAspectFactory;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
+import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.packages.AspectDefinition;
+import com.google.devtools.build.lib.rules.java.JavaCommon;
+import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider;
+import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Label.SyntaxException;
+import com.google.devtools.build.lib.vfs.PathFragment;
+
+import java.util.List;
+
+/** Aspect to provide Jack support to rules which have java sources. */
+public final class JackAspect implements ConfiguredAspectFactory {
+  private Label getLabel(String path) {
+    try {
+      return Label.parseAbsolute(path);
+    } catch (SyntaxException ex) {
+      throw new IllegalArgumentException(ex);
+    }
+  }
+
+  @Override
+  public AspectDefinition getDefinition() {
+    return new AspectDefinition.Builder("JackAspect")
+        .requireProvider(JavaSourceInfoProvider.class)
+        .add(attr("$jack", LABEL).cfg(HOST).exec().value(getLabel("//tools/android/jack:jack")))
+        .add(attr("$jill", LABEL).cfg(HOST).exec().value(getLabel("//tools/android/jack:jill")))
+        .add(
+            attr("$resource_extractor", LABEL)
+                .cfg(HOST)
+                .exec()
+                .value(getLabel("//tools/android/jack:resource_extractor")))
+        .add(
+            attr("$java_jack", LABEL)
+                .cfg(HOST)
+                .value(getLabel("//tools/android/jack:android_jack")))
+        .attributeAspect("deps", JackAspect.class)
+        .attributeAspect("exports", JackAspect.class)
+        .attributeAspect("runtime_deps", JackAspect.class)
+        .build();
+  }
+
+  @Override
+  public Aspect create(ConfiguredTarget base, RuleContext ruleContext) {
+    JavaSourceInfoProvider sourceProvider = base.getProvider(JavaSourceInfoProvider.class);
+
+    PathFragment rulePath = ruleContext.getLabel().toPathFragment();
+
+    PathFragment jackLibraryPath = rulePath.replaceName("lib" + rulePath.getBaseName() + ".jack");
+
+    Artifact jackLibraryOutput =
+        ruleContext
+            .getAnalysisEnvironment()
+            .getDerivedArtifact(jackLibraryPath, ruleContext.getBinOrGenfilesDirectory());
+
+    JackCompilationHelper jackHelper =
+        new JackCompilationHelper.Builder()
+            // blaze infrastructure
+            .setRuleContext(ruleContext)
+            // configuration
+            .setOutputArtifact(jackLibraryOutput)
+            // tools
+            .setAndroidBaseLibraryForJack(ruleContext.getHostPrerequisiteArtifact("$java_jack"))
+            // sources
+            .addJavaSources(sourceProvider.getSourceFiles())
+            .addSourceJars(sourceProvider.getSourceJars())
+            .addCompiledJars(sourceProvider.getJarFiles())
+            .addResources(sourceProvider.getResources())
+            .addProcessorNames(sourceProvider.getProcessorNames())
+            .addProcessorClasspathJars(sourceProvider.getProcessorPath())
+            // dependencies
+            .addExports(getPotentialDependency(ruleContext, "exports"))
+            .addDeps(getPotentialDependency(ruleContext, "deps"))
+            .addRuntimeDeps(getPotentialDependency(ruleContext, "runtime_deps"))
+            .build();
+
+    JackLibraryProvider result =
+        JavaCommon.isNeverLink(ruleContext)
+            ? jackHelper.compileAsNeverlinkLibrary()
+            : jackHelper.compileAsLibrary();
+
+    return new Aspect.Builder().addProvider(JackLibraryProvider.class, result).build();
+  }
+
+  /** Gets a list of targets on the given LABEL_LIST attribute if it exists, else an empty list. */
+  private static List<? extends TransitiveInfoCollection> getPotentialDependency(
+      RuleContext context, String attribute) {
+    if (!context.getRule().getRuleClassObject().hasAttr(attribute, LABEL_LIST)) {
+      return ImmutableList.of();
+    }
+    return context.getPrerequisites(attribute, Mode.TARGET);
+  }
+}