Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make paparazzi aware or unit test dependencies #1468

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.DynamicFeatureAndroidComponentsExtension
import com.android.build.api.variant.HasUnitTest
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.api.variant.UnitTest
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactType
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.artifacts.type.ArtifactTypeDefinition
import org.gradle.api.artifacts.type.ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE
Expand Down Expand Up @@ -115,27 +117,32 @@ public class PaparazziPlugin : Plugin<Project> {

// https://android.googlesource.com/platform/tools/base/+/96015063acd3455a76cdf1cc71b23b0828c0907f/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/MergeResources.kt#875

val moduleResourceDirs = variant.runtimeConfiguration
val runtimeConfiguration: Configuration = variant
.nestedComponents
.filterIsInstance<UnitTest>()
.firstOrNull()?.runtimeConfiguration ?: variant.runtimeConfiguration
alyssoncs marked this conversation as resolved.
Show resolved Hide resolved

val moduleResourceDirs = runtimeConfiguration
.artifactsFor(ArtifactType.ANDROID_RES.type) { it is ProjectComponentIdentifier }
.artifactFiles

val aarExplodedDirs = variant.runtimeConfiguration
val aarExplodedDirs = runtimeConfiguration
.artifactsFor(ArtifactType.ANDROID_RES.type) { it !is ProjectComponentIdentifier }
.artifactFiles

val localAssetDirs = variant.sources.assets?.all ?: project.provider { emptyList() }

// https://android.googlesource.com/platform/tools/base/+/96015063acd3455a76cdf1cc71b23b0828c0907f/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/MergeResources.kt#875

val moduleAssetDirs = variant.runtimeConfiguration
val moduleAssetDirs = runtimeConfiguration
.artifactsFor(ArtifactType.ASSETS.type) { it is ProjectComponentIdentifier }
.artifactFiles

val aarAssetDirs = variant.runtimeConfiguration
val aarAssetDirs = runtimeConfiguration
.artifactsFor(ArtifactType.ASSETS.type) { it !is ProjectComponentIdentifier }
.artifactFiles

val packageAwareArtifactFiles = variant.runtimeConfiguration
val packageAwareArtifactFiles = runtimeConfiguration
.artifactsFor(ArtifactType.SYMBOL_LIST_WITH_PACKAGE_NAME.type)
.artifactFiles

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public abstract class PrepareResourcesTask : DefaultTask() {

val mainPackage = packageName.get()
val resourcePackageNames = if (nonTransitiveRClassEnabled.get()) {
buildList {
buildSet {
alyssoncs marked this conversation as resolved.
Show resolved Hide resolved
add(mainPackage)
artifactFiles.files.forEach { file ->
add(file.useLines { lines -> lines.first() })
}
}
}.toList()
alyssoncs marked this conversation as resolved.
Show resolved Hide resolved
} else {
listOf(mainPackage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ class PaparazziPluginTest {
"build/generated/res/extra"
)
assertThat(config.moduleResourceDirs).containsExactly(
"build/intermediates/packaged_res/debug/packageDebugResources",
"../module1/build/intermediates/packaged_res/debug/packageDebugResources",
"../module2/build/intermediates/packaged_res/debug/packageDebugResources"
)
Expand Down Expand Up @@ -846,6 +847,7 @@ class PaparazziPluginTest {
"build/generated/res/extra"
)
assertThat(config.moduleResourceDirs).containsExactly(
"build/intermediates/packaged_res/debug/packageDebugResources",
"../module1/build/intermediates/packaged_res/debug/packageDebugResources",
"../module2/build/intermediates/packaged_res/debug/packageDebugResources"
)
Expand Down Expand Up @@ -952,7 +954,10 @@ class PaparazziPluginTest {
val resourcesFile = File(consumerModuleRoot, "build/intermediates/paparazzi/debug/resources.json")

var config = resourcesFile.loadConfig()
assertThat(config.moduleResourceDirs).containsExactly("../producer/build/intermediates/packaged_res/debug/packageDebugResources")
assertThat(config.moduleResourceDirs).containsExactly(
"build/intermediates/packaged_res/debug/packageDebugResources",
"../producer/build/intermediates/packaged_res/debug/packageDebugResources"
)

buildDir.deleteRecursively()

Expand All @@ -974,7 +979,10 @@ class PaparazziPluginTest {
}

config = resourcesFile.loadConfig()
assertThat(config.moduleResourceDirs).containsExactly("../producer/build/intermediates/packaged_res/debug/packageDebugResources")
assertThat(config.moduleResourceDirs).containsExactly(
"build/intermediates/packaged_res/debug/packageDebugResources",
"../producer/build/intermediates/packaged_res/debug/packageDebugResources"
)
}

@Test
Expand Down Expand Up @@ -1064,7 +1072,11 @@ class PaparazziPluginTest {
val resourcesFile = File(fixtureRoot, "build/intermediates/paparazzi/debug/resources.json")

var config = resourcesFile.loadConfig()
assertThat(config.projectAssetDirs).containsExactly("src/main/assets", "src/debug/assets")
assertThat(config.projectAssetDirs).containsExactly(
"src/main/assets",
"src/debug/assets",
"build/intermediates/library_assets/debug/packageDebugAssets/out"
)

buildDir.deleteRecursively()

Expand All @@ -1087,7 +1099,11 @@ class PaparazziPluginTest {
}

config = resourcesFile.loadConfig()
assertThat(config.projectAssetDirs).containsExactly("src/main/assets", "src/debug/assets")
assertThat(config.projectAssetDirs).containsExactly(
"src/main/assets",
"src/debug/assets",
"build/intermediates/library_assets/debug/packageDebugAssets/out"
)
}

@Test
Expand Down Expand Up @@ -1128,6 +1144,7 @@ class PaparazziPluginTest {
assertThat(config.projectAssetDirs).containsExactly(
"src/main/assets",
"src/debug/assets",
"build/intermediates/library_assets/debug/packageDebugAssets/out",
"../producer/build/intermediates/library_assets/debug/packageDebugAssets/out"
)

Expand Down Expand Up @@ -1155,6 +1172,7 @@ class PaparazziPluginTest {
assertThat(config.projectAssetDirs).containsExactly(
"src/main/assets",
"src/debug/assets",
"build/intermediates/library_assets/debug/packageDebugAssets/out",
"../producer/build/intermediates/library_assets/debug/packageDebugAssets/out"
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
kotlin.mpp.androidSourceSetLayoutVersion1.nowarn=true
android.useAndroidX=true
alyssoncs marked this conversation as resolved.
Show resolved Hide resolved