summaryrefslogtreecommitdiff
path: root/android-lint/src
diff options
context:
space:
mode:
authorAmr Afifiy <amrmahmoud@google.com>2021-11-01 16:31:00 +0000
committerAmr Afifiy <amrmahmoud@google.com>2021-11-03 16:59:32 +0000
commit57b318537ac72170e89857e01fe6cb658c14d4a3 (patch)
treeacb1aca4b01e60b530a3dec7a63469d09d5d78ff /android-lint/src
parentaa393db1b9224cbe57e47f021613254e2bb71052 (diff)
downloadidea-57b318537ac72170e89857e01fe6cb658c14d4a3.tar.gz
Add a testFixturesSourceProviders to LintModelVariant
Bug: 139438142 Test: LintModelSnapshotComparisonTest Change-Id: I647a4d55cfccc6e93abe6096d5e066dd1d484293
Diffstat (limited to 'android-lint/src')
-rw-r--r--android-lint/src/com/android/tools/idea/lint/model/LintModelDumper.kt6
-rw-r--r--android-lint/src/com/android/tools/idea/lint/model/LintModelFactory.kt86
2 files changed, 67 insertions, 25 deletions
diff --git a/android-lint/src/com/android/tools/idea/lint/model/LintModelDumper.kt b/android-lint/src/com/android/tools/idea/lint/model/LintModelDumper.kt
index 415d88bd40c..d0be67b1e30 100644
--- a/android-lint/src/com/android/tools/idea/lint/model/LintModelDumper.kt
+++ b/android-lint/src/com/android/tools/idea/lint/model/LintModelDumper.kt
@@ -181,6 +181,12 @@ private fun ProjectDumper.dump(lintModelVariant: LintModelVariant) {
testSourceProviders.forEach { dump(it) }
}
}
+ if (testFixturesSourceProviders.isNotEmpty()) {
+ head("TestFixturesSourceProviders")
+ nest {
+ testFixturesSourceProviders.forEach { dump(it) }
+ }
+ }
prop("Debuggable") { debuggable.takeIf { it }?.toString() }
prop("Shrinkable") { shrinkable.takeIf { it }?.toString() }
diff --git a/android-lint/src/com/android/tools/idea/lint/model/LintModelFactory.kt b/android-lint/src/com/android/tools/idea/lint/model/LintModelFactory.kt
index ae41bb7d9c8..90cf4d9d41b 100644
--- a/android-lint/src/com/android/tools/idea/lint/model/LintModelFactory.kt
+++ b/android-lint/src/com/android/tools/idea/lint/model/LintModelFactory.kt
@@ -344,6 +344,7 @@ class LintModelFactory : LintModelModuleLoader {
consumerProguardFiles = variant.consumerProguardFiles,
sourceProviders = computeSourceProviders(project, variant),
testSourceProviders = computeTestSourceProviders(project, variant),
+ testFixturesSourceProviders = computeTestFixturesSourceProviders(project, variant),
debuggable = buildType.isDebuggable,
shrinkable = buildType.isMinifyEnabled,
buildFeatures = getBuildFeatures(project, module.gradleVersion),
@@ -415,6 +416,10 @@ class LintModelFactory : LintModelModuleLoader {
return isUnitTest() || isInstrumentationTest()
}
+ private fun IdeSourceProviderContainer.isTestFixtures(): Boolean {
+ return AndroidProject.ARTIFACT_TEST_FIXTURES == artifactName
+ }
+
private fun IdeSourceProviderContainer.isUnitTest(): Boolean {
return AndroidProject.ARTIFACT_UNIT_TEST == artifactName
}
@@ -423,6 +428,39 @@ class LintModelFactory : LintModelModuleLoader {
return AndroidProject.ARTIFACT_ANDROID_TEST == artifactName
}
+ private fun computeExtraSourceProviders(
+ project: IdeAndroidProject,
+ variant: IdeVariant,
+ filter: (IdeSourceProviderContainer) -> Boolean
+ ): List<LintModelSourceProvider> {
+ val providers = mutableListOf<LintModelSourceProvider>()
+
+ project.defaultConfig.extraSourceProviders.filter { filter(it) }.forEach { extra ->
+ getSourceProvider(extra)?.let { providers.add(it) }
+ }
+
+ for (flavorContainer in project.productFlavors) {
+ if (variant.productFlavors.contains(flavorContainer.productFlavor.name)) {
+ flavorContainer.extraSourceProviders.filter { filter(it) }.forEach { extra ->
+ getSourceProvider(extra)?.let { providers.add(it) }
+ }
+ }
+ }
+
+ for (buildTypeContainer in project.buildTypes) {
+ if (variant.buildType == buildTypeContainer.buildType.name) {
+ buildTypeContainer.extraSourceProviders.filter { filter(it) }.forEach { extra ->
+ getSourceProvider(
+ providerContainer = extra,
+ debugOnly = buildTypeContainer.buildType.isDebuggable
+ )?.let { providers.add(it) }
+ }
+ }
+ }
+
+ return providers
+ }
+
/**
* TODO: This is not correct; this method simultaneously returns both the
* unit test and instrumentation test folders. These two are not normally
@@ -440,37 +478,28 @@ class LintModelFactory : LintModelModuleLoader {
project: IdeAndroidProject,
variant: IdeVariant
): List<LintModelSourceProvider> {
+ return computeExtraSourceProviders(project, variant) { it.isTest() }
+ }
+
+ private fun computeTestFixturesSourceProviders(
+ project: IdeAndroidProject,
+ variant: IdeVariant
+ ): List<LintModelSourceProvider> {
val providers = mutableListOf<LintModelSourceProvider>()
- for (extra in project.defaultConfig.extraSourceProviders) {
- if (extra.isTest()) {
- getSourceProvider(extra)?.let { providers.add(it) }
- }
- }
+ providers.addAll(computeExtraSourceProviders(project, variant) { it.isTestFixtures() })
- for (flavorContainer in project.productFlavors) {
- if (variant.productFlavors.contains(flavorContainer.productFlavor.name)) {
- for (extra in flavorContainer.extraSourceProviders) {
- if (extra.isTest()) {
- getSourceProvider(extra)?.let { providers.add(it) }
- }
- }
+ variant.testFixturesArtifact?.let { artifact ->
+ artifact.variantSourceProvider?.let {
+ providers.add(getSourceProvider(it))
}
- }
-
- for (buildTypeContainer in project.buildTypes) {
- if (variant.buildType == buildTypeContainer.buildType.name) {
- for (extra in buildTypeContainer.extraSourceProviders) {
- if (extra.isTest()) {
- getSourceProvider(
- providerContainer = extra,
- debugOnly = buildTypeContainer.buildType.isDebuggable
- )?.let { providers.add(it) }
- }
- }
+ artifact.multiFlavorSourceProvider?.let {
+ providers.add(getSourceProvider(
+ it,
+ debugOnly = project.buildTypes.first { it.buildType.name == variant.buildType }.buildType.isDebuggable
+ ))
}
}
-
return providers
}
@@ -751,6 +780,13 @@ class LintModelFactory : LintModelModuleLoader {
variant
).also { _testSourceProviders = it }
+ private var _testFixturesSourceProviders: List<LintModelSourceProvider>? = null
+ override val testFixturesSourceProviders: List<LintModelSourceProvider>
+ get() = _testFixturesSourceProviders ?: computeTestFixturesSourceProviders(
+ project,
+ variant
+ ).also { _testFixturesSourceProviders = it }
+
private var _resValues: Map<String, LintModelResourceField>? = null
override val resValues: Map<String, LintModelResourceField>
get() = _resValues