Fix: lintPublish should package lint.jar with AAR

Fixes: 124471103
Bug: 123377555
Test: regression test added
Change-Id: I434c835b237343cfc25e9f7262d84a75e2a85e02
(cherry picked from commit b4cf7008fb275896fe181b6463da8eb119e1715a)
diff --git a/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/BundleAar.kt b/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/BundleAar.kt
index 8689dec..2849c65 100644
--- a/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/BundleAar.kt
+++ b/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/BundleAar.kt
@@ -143,7 +143,7 @@
                 prependToCopyPath(SdkConstants.FD_JNI)
             )
             task.from(variantScope.globalScope.artifacts
-                .getFinalArtifactFiles(InternalArtifactType.LINT_JAR))
+                .getFinalArtifactFiles(InternalArtifactType.LINT_PUBLISH_JAR))
             if (artifacts.hasArtifact(InternalArtifactType.ANNOTATIONS_ZIP)) {
                 task.from(artifacts.getFinalArtifactFiles(InternalArtifactType.ANNOTATIONS_ZIP))
             }
diff --git a/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/lint/LintCustomLocalAndPublishTest.java b/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/lint/LintCustomLocalAndPublishTest.java
index f73be15..2c08910 100644
--- a/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/lint/LintCustomLocalAndPublishTest.java
+++ b/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/lint/LintCustomLocalAndPublishTest.java
@@ -16,9 +16,13 @@
 
 package com.android.build.gradle.integration.lint;
 
+import static com.android.SdkConstants.FN_LINT_JAR;
 import static com.android.testutils.truth.FileSubject.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import com.android.build.gradle.integration.common.fixture.GradleTestProject;
+import com.android.testutils.apk.Aar;
 import java.io.File;
 import org.junit.Rule;
 import org.junit.Test;
@@ -84,4 +88,21 @@
         assertThat(applintfile).contentWithUnixLineSeparatorsIsExactly(appexpected);
         assertThat(liblintfile).contentWithUnixLineSeparatorsIsExactly(libexpected);
     }
+
+    @Test
+    public void checkAarHasLintJar() throws Exception {
+        project.executor().run("clean");
+        project.executor().run(":library:assembleDebug");
+        project.executor().run(":library-publish-only:assembleDebug");
+        project.executor().run(":library-local-only:assembleDebug");
+
+        Aar localAndPublish = project.getSubproject("library").getAar("debug");
+        assertNotNull(localAndPublish.getEntry(FN_LINT_JAR));
+
+        Aar publishOnly = project.getSubproject("library-publish-only").getAar("debug");
+        assertNotNull(publishOnly.getEntry(FN_LINT_JAR));
+
+        Aar localOnly = project.getSubproject("library-local-only").getAar("debug");
+        assertNull(localOnly.getEntry(FN_LINT_JAR));
+    }
 }
diff --git a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/build.gradle b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/build.gradle
new file mode 100644
index 0000000..3238250
--- /dev/null
+++ b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'com.android.library'
+
+android {
+    compileSdkVersion rootProject.latestCompileSdk
+    buildToolsVersion = rootProject.buildToolsVersion
+
+    defaultConfig {
+        minSdkVersion 16
+        targetSdkVersion 24
+
+    }
+
+    lintOptions {
+        textReport true
+        textOutput file("library-lint-results.txt")
+        check 'UnitTestLintCheck'
+        check 'UnitTestLintCheck2'
+        absolutePaths false
+    }
+}
+
+dependencies {
+    lintChecks project(':lint')
+}
+
diff --git a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/src/main/AndroidManifest.xml b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..e832e27
--- /dev/null
+++ b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/src/main/AndroidManifest.xml
@@ -0,0 +1,4 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.example.library">
+    <application/>
+</manifest>
diff --git a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/src/main/java/com/example/app/MyClass.java b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/src/main/java/com/example/app/MyClass.java
new file mode 100644
index 0000000..15d3c77
--- /dev/null
+++ b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-local-only/src/main/java/com/example/app/MyClass.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * 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.example.app;
+
+public abstract class MyClass implements java.util.List {}
diff --git a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/build.gradle b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/build.gradle
new file mode 100644
index 0000000..b9f2f22
--- /dev/null
+++ b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'com.android.library'
+
+android {
+    compileSdkVersion rootProject.latestCompileSdk
+    buildToolsVersion = rootProject.buildToolsVersion
+
+    defaultConfig {
+        minSdkVersion 16
+        targetSdkVersion 24
+
+    }
+
+    lintOptions {
+        textReport true
+        textOutput file("library-lint-results.txt")
+        check 'UnitTestLintCheck'
+        check 'UnitTestLintCheck2'
+        absolutePaths false
+    }
+}
+
+dependencies {
+    lintPublish project(':lintpublish')
+}
+
diff --git a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/src/main/AndroidManifest.xml b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..e832e27
--- /dev/null
+++ b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/src/main/AndroidManifest.xml
@@ -0,0 +1,4 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.example.library">
+    <application/>
+</manifest>
diff --git a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/src/main/java/com/example/app/MyClass.java b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/src/main/java/com/example/app/MyClass.java
new file mode 100644
index 0000000..15d3c77
--- /dev/null
+++ b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/library-publish-only/src/main/java/com/example/app/MyClass.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * 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.example.app;
+
+public abstract class MyClass implements java.util.List {}
diff --git a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/settings.gradle b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/settings.gradle
index 11033ef..d71a5ac 100644
--- a/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/settings.gradle
+++ b/build-system/integration-test/test-projects/lintCustomLocalAndPublishRules/settings.gradle
@@ -1 +1 @@
-include ':app', ':library', ':lint', ':lintpublish'
+include ':app', ':library', ':library-publish-only', 'library-local-only', ':lint', ':lintpublish'