Add ability to specify lint test modes during lint check
This is a workaround for issues regarding partial analysis (b/188814760, b/201086161#comment4).
Also changes the following:
- Adds note regarding searching for Kotlin's deprecated @Experimental annotation
- Un-ignores `Test cross-module Experimental usage via Gradle model` by specifying TestMode.DEFAULT
- Separate out usages of experimental annotations
Bug: 201564937
Test: BanInappropriateExperimentalUsageTest
Test: presubmit
Change-Id: Ia54e557f2c70f60bbeb2bccf1475d1d60c7ed1c1
diff --git a/lint-checks/integration-tests/src/main/java/androidx/sample/consumer/OutsideGroupExperimentalAnnotatedClass.kt b/lint-checks/integration-tests/src/main/java/androidx/sample/consumer/OutsideGroupExperimentalAnnotatedClass.kt
index ded25ef..5b4f582 100644
--- a/lint-checks/integration-tests/src/main/java/androidx/sample/consumer/OutsideGroupExperimentalAnnotatedClass.kt
+++ b/lint-checks/integration-tests/src/main/java/androidx/sample/consumer/OutsideGroupExperimentalAnnotatedClass.kt
@@ -18,12 +18,17 @@
package androidx.sample.consumer
-import sample.annotation.provider.ExperimentalSampleAnnotation
import sample.annotation.provider.ExperimentalSampleAnnotationJava
class OutsideGroupExperimentalAnnotatedClass {
+
+ // b/201564937 (comments 3, 5-7) - temporarily commenting out due to import issue
+// @ExperimentalSampleAnnotation
+// fun invalidAnnotatedFunction() {
+// // Nothing to see here.
+// }
+
@ExperimentalSampleAnnotationJava
- @ExperimentalSampleAnnotation
fun invalidAnnotatedMethod() {
// Nothing to see here.
}
diff --git a/lint-checks/src/main/java/androidx/build/lint/BanInappropriateExperimentalUsage.kt b/lint-checks/src/main/java/androidx/build/lint/BanInappropriateExperimentalUsage.kt
index 4ee07b7..c5ac47b 100644
--- a/lint-checks/src/main/java/androidx/build/lint/BanInappropriateExperimentalUsage.kt
+++ b/lint-checks/src/main/java/androidx/build/lint/BanInappropriateExperimentalUsage.kt
@@ -104,7 +104,12 @@
companion object {
private const val DEBUG = false
+ /**
+ * Even though Kotlin's [Experimental] annotation is deprecated in favor of [RequiresOptIn],
+ * we still want to check for its use in Lint.
+ */
private const val KOTLIN_EXPERIMENTAL_ANNOTATION = "kotlin.Experimental"
+
private const val KOTLIN_REQUIRES_OPT_IN_ANNOTATION = "kotlin.RequiresOptIn"
private const val JAVA_EXPERIMENTAL_ANNOTATION =
"androidx.annotation.experimental.Experimental"
diff --git a/lint-checks/src/test/java/androidx/build/lint/AbstractLintDetectorTest.kt b/lint-checks/src/test/java/androidx/build/lint/AbstractLintDetectorTest.kt
index 8bcfd3e..da45139 100644
--- a/lint-checks/src/test/java/androidx/build/lint/AbstractLintDetectorTest.kt
+++ b/lint-checks/src/test/java/androidx/build/lint/AbstractLintDetectorTest.kt
@@ -40,8 +40,15 @@
override fun getIssues(): List<Issue> = useIssues
+ /**
+ * Runs lint checks for the given [projects] using (optionally) specified [testModes].
+ *
+ * Test mode modification is available to work around issues regarding partial analysis
+ * (b/188814760, b/201086161#comment4).
+ */
fun check(
- vararg projects: ProjectDescription
+ vararg projects: ProjectDescription,
+ testModes: List<TestMode> = listOf(TestMode.DEFAULT, TestMode.PARTIAL)
): TestLintResult {
// If we have stubs, push those into a virtual project and pass them through the call to
// projects(), since attempting to call files() would overwrite the call to projects().
@@ -52,7 +59,8 @@
}
return lint()
- .projects(*projectsWithStubs).testModes(TestMode.DEFAULT, TestMode.PARTIAL)
+ .projects(*projectsWithStubs)
+ .testModes(testModes)
.run()
}
diff --git a/lint-checks/src/test/java/androidx/build/lint/BanInappropriateExperimentalUsageTest.kt b/lint-checks/src/test/java/androidx/build/lint/BanInappropriateExperimentalUsageTest.kt
index 64e10d8..63f43ed 100644
--- a/lint-checks/src/test/java/androidx/build/lint/BanInappropriateExperimentalUsageTest.kt
+++ b/lint-checks/src/test/java/androidx/build/lint/BanInappropriateExperimentalUsageTest.kt
@@ -19,7 +19,7 @@
package androidx.build.lint
import com.android.tools.lint.checks.infrastructure.ProjectDescription
-import org.junit.Ignore
+import com.android.tools.lint.checks.infrastructure.TestMode
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -55,7 +55,6 @@
check(provider).expect(expected)
}
- @Ignore("b/188814760")
@Test
fun `Test cross-module Experimental usage via Gradle model`() {
val provider = project()
@@ -89,13 +88,14 @@
/* ktlint-disable max-line-length */
val expected = """
-../consumer/src/main/kotlin/androidx/sample/consumer/OutsideGroupExperimentalAnnotatedClass.kt:25: Error: Experimental and RequiresOptIn APIs may only be used within the same-version group where they were defined. [IllegalExperimentalApiUsage]
+../consumer/src/main/kotlin/androidx/sample/consumer/OutsideGroupExperimentalAnnotatedClass.kt:31: Error: Experimental and RequiresOptIn APIs may only be used within the same-version group where they were defined. [IllegalExperimentalApiUsage]
@ExperimentalSampleAnnotationJava
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 errors, 0 warnings
""".trimIndent()
/* ktlint-enable max-line-length */
- check(provider, consumer).expect(expected)
+ // TODO: Using TestMode.DEFAULT due to b/188814760; remove testModes once bug is resolved
+ check(provider, consumer, testModes = listOf(TestMode.DEFAULT)).expect(expected)
}
}