From 8b199c134da306f10d7aa09b88af222a246daee9 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Tue, 1 Oct 2024 21:00:08 -0400 Subject: [PATCH 1/9] Update Jacoco.kt --- .../com/google/samples/apps/nowinandroid/Jacoco.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index 972d539c6..05ce75611 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -88,13 +88,11 @@ internal fun Project.configureJacoco( html.required = true } - // TODO: This is missing files in src/debug/, src/prod, src/demo, src/demoDebug... - sourceDirectories.setFrom( - files( - "$projectDir/src/main/java", - "$projectDir/src/main/kotlin", - ), - ) + // Collect all java and kotlin source directories from the variant's source sets + val sourceDirs = variant.sources + .map { it.java.srcDirs + it.kotlin.srcDirs } + .flatten() + sourceDirectories.setFrom(sourceDirs) executionData.setFrom( project.fileTree("$buildDir/outputs/unit_test_code_coverage/${variant.name}UnitTest") From c4cb8bc407fea46450a01886f146c291d766efb9 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Sun, 15 Dec 2024 20:11:12 -0500 Subject: [PATCH 2/9] fix: compiler error --- .../com/google/samples/apps/nowinandroid/Jacoco.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index 05ce75611..ee00da92f 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -89,10 +89,11 @@ internal fun Project.configureJacoco( } // Collect all java and kotlin source directories from the variant's source sets - val sourceDirs = variant.sources - .map { it.java.srcDirs + it.kotlin.srcDirs } - .flatten() - sourceDirectories.setFrom(sourceDirs) +// val sourceDirs = + sourceDirectories.setFrom( + variant.sources.kotlin?.all?.get(), + variant.sources.java?.all?.get() + ) executionData.setFrom( project.fileTree("$buildDir/outputs/unit_test_code_coverage/${variant.name}UnitTest") From f1bfe347860df419fa6f8c96c59d04ce65c319c1 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Sun, 15 Dec 2024 20:12:56 -0500 Subject: [PATCH 3/9] nullability --- .../kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index ee00da92f..8c9d43f51 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -89,10 +89,9 @@ internal fun Project.configureJacoco( } // Collect all java and kotlin source directories from the variant's source sets -// val sourceDirs = sourceDirectories.setFrom( - variant.sources.kotlin?.all?.get(), - variant.sources.java?.all?.get() + variant.sources.kotlin?.all?.get().orEmpty(), + variant.sources.java?.all?.get().orEmpty() ) executionData.setFrom( From 27f548fec5a1a9b98dbe205f3b0d3167e62973a5 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Sun, 15 Dec 2024 20:31:42 -0500 Subject: [PATCH 4/9] fix: lazy query for task --- .../google/samples/apps/nowinandroid/Jacoco.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index 8c9d43f51..3d674465c 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -89,9 +89,23 @@ internal fun Project.configureJacoco( } // Collect all java and kotlin source directories from the variant's source sets + val kotlin = variant + .sources + .kotlin + ?.all + ?.map { it.orEmpty() } + ?.map { it.map { it.asFile.path } } + val java = variant + .sources + .java + ?.all + ?.map { it.orEmpty() } + ?.map { it.map { it.asFile.path } } sourceDirectories.setFrom( - variant.sources.kotlin?.all?.get().orEmpty(), - variant.sources.java?.all?.get().orEmpty() + files( + kotlin, + java + ) ) executionData.setFrom( From ffcd7d95819ac8ac1d387f37954d0c14b8f8d491 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Mon, 16 Dec 2024 14:24:25 -0500 Subject: [PATCH 5/9] fix: code cleanup --- .../samples/apps/nowinandroid/Jacoco.kt | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index 3d674465c..1378a5db4 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -19,11 +19,14 @@ package com.google.samples.apps.nowinandroid import com.android.build.api.artifact.ScopedArtifact import com.android.build.api.variant.AndroidComponentsExtension import com.android.build.api.variant.ScopedArtifacts +import com.android.build.api.variant.SourceDirectories import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.RegularFile import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.Provider import org.gradle.api.tasks.testing.Test +import org.gradle.internal.impldep.io.opencensus.common.ExperimentalApi import org.gradle.kotlin.dsl.assign import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.register @@ -89,23 +92,11 @@ internal fun Project.configureJacoco( } // Collect all java and kotlin source directories from the variant's source sets - val kotlin = variant - .sources - .kotlin - ?.all - ?.map { it.orEmpty() } - ?.map { it.map { it.asFile.path } } - val java = variant - .sources - .java - ?.all - ?.map { it.orEmpty() } - ?.map { it.map { it.asFile.path } } + fun SourceDirectories.Flat.srcs(): Provider> = this + .all + .map { directories -> directories.map { it.asFile.path } } sourceDirectories.setFrom( - files( - kotlin, - java - ) + files(variant.sources.java?.srcs(), variant.sources.kotlin?.srcs()) ) executionData.setFrom( From 7d45a7c179cff82c155324e848aa358acb4d97e8 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Mon, 16 Dec 2024 14:28:04 -0500 Subject: [PATCH 6/9] fix: rename --- .../kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index 1378a5db4..561d3907f 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -26,7 +26,6 @@ import org.gradle.api.file.RegularFile import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Provider import org.gradle.api.tasks.testing.Test -import org.gradle.internal.impldep.io.opencensus.common.ExperimentalApi import org.gradle.kotlin.dsl.assign import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.register @@ -92,11 +91,11 @@ internal fun Project.configureJacoco( } // Collect all java and kotlin source directories from the variant's source sets - fun SourceDirectories.Flat.srcs(): Provider> = this + fun SourceDirectories.Flat.paths(): Provider> = this .all .map { directories -> directories.map { it.asFile.path } } sourceDirectories.setFrom( - files(variant.sources.java?.srcs(), variant.sources.kotlin?.srcs()) + files(variant.sources.java?.paths(), variant.sources.kotlin?.paths()) ) executionData.setFrom( From 192a3a6e8a7472a204f723452857b789867dd389 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Tue, 17 Dec 2024 07:59:12 -0500 Subject: [PATCH 7/9] rename fun --- .../kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index 561d3907f..639e3c482 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -91,11 +91,14 @@ internal fun Project.configureJacoco( } // Collect all java and kotlin source directories from the variant's source sets - fun SourceDirectories.Flat.paths(): Provider> = this + fun SourceDirectories.Flat.toFilePaths(): Provider> = this .all .map { directories -> directories.map { it.asFile.path } } sourceDirectories.setFrom( - files(variant.sources.java?.paths(), variant.sources.kotlin?.paths()) + files( + variant.sources.java?.toFilePaths(), + variant.sources.kotlin?.toFilePaths() + ) ) executionData.setFrom( From 32712085159b0d239ebff76e574f5862d24bb9d7 Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Tue, 17 Dec 2024 08:14:00 -0500 Subject: [PATCH 8/9] ergonomics --- .../google/samples/apps/nowinandroid/Jacoco.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index 639e3c482..f8d8d567c 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -90,15 +90,16 @@ internal fun Project.configureJacoco( html.required = true } - // Collect all java and kotlin source directories from the variant's source sets - fun SourceDirectories.Flat.toFilePaths(): Provider> = this - .all - .map { directories -> directories.map { it.asFile.path } } + fun SourceDirectories.Flat?.toFilePaths(): Provider> = this + ?.all + ?.map { directories -> directories.map { it.asFile.path } } + ?: provider { emptyList() } + operator fun Provider>.plus(other: Provider>) = + zip(other) { first, second -> first + second } sourceDirectories.setFrom( files( - variant.sources.java?.toFilePaths(), - variant.sources.kotlin?.toFilePaths() - ) + variant.sources.java.toFilePaths() + variant.sources.kotlin.toFilePaths() + ), ) executionData.setFrom( From f925bfc01c97e294986b5feba407abf7ce4459fe Mon Sep 17 00:00:00 2001 From: Alfayed Baksh Date: Tue, 17 Dec 2024 21:46:17 -0500 Subject: [PATCH 9/9] fix: remove operator fun for simplicity --- .../kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index f8d8d567c..ed1ea4254 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -94,11 +94,10 @@ internal fun Project.configureJacoco( ?.all ?.map { directories -> directories.map { it.asFile.path } } ?: provider { emptyList() } - operator fun Provider>.plus(other: Provider>) = - zip(other) { first, second -> first + second } sourceDirectories.setFrom( files( - variant.sources.java.toFilePaths() + variant.sources.kotlin.toFilePaths() + variant.sources.java.toFilePaths(), + variant.sources.kotlin.toFilePaths() ), )