Skip to content

Commit e218b3e

Browse files
authored
Added property variantName to KoverReport interface
Property variantName will help to filter Kover tasks by selecting those that relate to specific variant. Resolves #587 PR #595
1 parent 2e6efc8 commit e218b3e

File tree

24 files changed

+344
-10
lines changed

24 files changed

+344
-10
lines changed

kover-gradle-plugin/api/kover-gradle-plugin.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverLogRe
311311
}
312312

313313
public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverReport : org/gradle/api/Task {
314+
public abstract fun getVariantName ()Ljava/lang/String;
314315
}
315316

316317
public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverVerifyReport : kotlinx/kover/gradle/plugin/dsl/tasks/KoverReport {

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/TaskInterfacesTests.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
*/
44
package kotlinx.kover.gradle.plugin.test.functional.cases
55

6+
import kotlinx.kover.gradle.plugin.test.functional.framework.checker.CheckerContext
67
import kotlinx.kover.gradle.plugin.test.functional.framework.runner.generateBuild
78
import kotlinx.kover.gradle.plugin.test.functional.framework.runner.runWithParams
9+
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.TemplateTest
810
import org.junit.jupiter.api.Test
11+
import kotlin.test.assertEquals
912
import kotlin.test.assertTrue
1013

1114
internal class TaskInterfacesTests {
@@ -79,4 +82,35 @@ internal class TaskInterfacesTests {
7982
val result = build.runWithParams("checkDir")
8083
assertTrue(result.isSuccessful)
8184
}
85+
86+
@TemplateTest("android-test-tasks-filtering", [":app:findAllTasks"])
87+
fun CheckerContext.testTasksSearch() {
88+
taskOutput(":app:findTotalTasks") {
89+
assertEquals(
90+
"""
91+
XML=koverXmlReport
92+
HTML=koverHtmlReport
93+
Verify=koverVerify
94+
Log=koverLog
95+
Binary=koverBinaryReport
96+
97+
""".trimIndent()
98+
, this
99+
)
100+
}
101+
102+
taskOutput(":app:findDebugTasks") {
103+
assertEquals(
104+
"""
105+
XML=koverXmlReportDebug
106+
HTML=koverHtmlReportDebug
107+
Verify=koverVerifyDebug
108+
Log=koverLogDebug
109+
Binary=koverBinaryReportDebug
110+
111+
""".trimIndent(),
112+
this
113+
)
114+
}
115+
}
82116
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import kotlinx.kover.gradle.plugin.dsl.tasks.*
2+
3+
plugins {
4+
id ("org.jetbrains.kotlinx.kover")
5+
id ("com.android.application")
6+
id ("org.jetbrains.kotlin.android")
7+
}
8+
9+
android {
10+
namespace = "kotlinx.kover.test.android"
11+
compileSdk = 32
12+
13+
defaultConfig {
14+
applicationId = "kotlinx.kover.test.android"
15+
minSdk = 21
16+
targetSdk = 31
17+
versionCode = 1
18+
versionName = "1.0"
19+
20+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
21+
}
22+
23+
buildTypes {
24+
release {
25+
isMinifyEnabled = true
26+
}
27+
}
28+
compileOptions {
29+
sourceCompatibility = JavaVersion.VERSION_1_8
30+
targetCompatibility = JavaVersion.VERSION_1_8
31+
}
32+
kotlinOptions {
33+
jvmTarget = "1.8"
34+
}
35+
buildFeatures {
36+
viewBinding = true
37+
}
38+
}
39+
40+
dependencies {
41+
implementation("androidx.core:core-ktx:1.8.0")
42+
implementation("androidx.appcompat:appcompat:1.5.0")
43+
implementation("com.google.android.material:material:1.6.1")
44+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
45+
testImplementation("junit:junit:4.13.2")
46+
}
47+
48+
tasks.register("findAllTasks") {
49+
dependsOn("findTotalTasks")
50+
dependsOn("findDebugTasks")
51+
}
52+
53+
tasks.register("findDebugTasks") {
54+
doLast {
55+
val xmlName = tasks.withType<KoverXmlReport>().matching {
56+
it.variantName == "debug"
57+
}.single().name
58+
59+
val htmlName = tasks.withType<KoverHtmlReport>().matching {
60+
it.variantName == "debug"
61+
}.single().name
62+
63+
val verifyName = tasks.withType<KoverVerifyReport>().matching {
64+
it.variantName == "debug"
65+
}.single().name
66+
67+
val logName = tasks.withType<KoverLogReport>().matching {
68+
it.variantName == "debug"
69+
}.single().name
70+
71+
val binaryName = tasks.withType<KoverBinaryReport>().matching {
72+
it.variantName == "debug"
73+
}.single().name
74+
75+
println("XML=$xmlName")
76+
println("HTML=$htmlName")
77+
println("Verify=$verifyName")
78+
println("Log=$logName")
79+
println("Binary=$binaryName")
80+
}
81+
}
82+
83+
tasks.register("findTotalTasks") {
84+
doLast {
85+
val xmlName = tasks.withType<KoverXmlReport>().matching {
86+
it.variantName == ""
87+
}.single().name
88+
89+
val htmlName = tasks.withType<KoverHtmlReport>().matching {
90+
it.variantName == ""
91+
}.single().name
92+
93+
val verifyName = tasks.withType<KoverVerifyReport>().matching {
94+
it.variantName == ""
95+
}.single().name
96+
97+
val logName = tasks.withType<KoverLogReport>().matching {
98+
it.variantName == ""
99+
}.single().name
100+
101+
val binaryName = tasks.withType<KoverBinaryReport>().matching {
102+
it.variantName == ""
103+
}.single().name
104+
105+
println("XML=$xmlName")
106+
println("HTML=$htmlName")
107+
println("Verify=$verifyName")
108+
println("Log=$logName")
109+
println("Binary=$binaryName")
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application android:label="@string/app_name">
5+
<uses-library android:name="com.google.android.things" android:required="false" />
6+
7+
<activity android:name=".MainActivity"
8+
android:exported="true">
9+
<intent-filter>
10+
<action android:name="android.intent.action.MAIN" />
11+
12+
<category android:name="android.intent.category.LAUNCHER" />
13+
</intent-filter>
14+
<!-- Make this the first activity that is displayed when the device boots. -->
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.HOME" />
19+
<category android:name="android.intent.category.DEFAULT" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package kotlinx.kover.test.android
2+
3+
object DebugUtil {
4+
fun log(message: String) {
5+
println("DEBUG: $message")
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.kover.test.android
2+
3+
import android.os.Bundle
4+
import android.app.Activity
5+
6+
class MainActivity : Activity() {
7+
8+
override fun onCreate(savedInstanceState: Bundle?) {
9+
super.onCreate(savedInstanceState)
10+
setContentView(R.layout.activity_main)
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.kover.test.android
2+
3+
object Maths {
4+
fun sum(a: Int, b: Int): Int {
5+
DebugUtil.log("invoked sum")
6+
return a + b
7+
}
8+
9+
fun sub(a: Int, b: Int): Int {
10+
DebugUtil.log("invoked sub")
11+
return a - b
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".MainActivity">
8+
9+
<TextView
10+
android:id="@+id/main_label"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:layout_marginStart="104dp"
14+
android:layout_marginTop="28dp"
15+
android:text="SERIALIZATION TEST"
16+
android:textSize="20sp"
17+
android:textStyle="bold"
18+
app:layout_constraintStart_toStartOf="parent"
19+
app:layout_constraintTop_toTopOf="parent" />
20+
21+
<EditText
22+
android:id="@+id/encoded_text"
23+
android:layout_width="373dp"
24+
android:layout_height="411dp"
25+
android:layout_marginStart="16dp"
26+
android:layout_marginTop="16dp"
27+
android:editable="false"
28+
android:ems="10"
29+
android:gravity="start|top"
30+
android:inputType="textMultiLine"
31+
android:textAlignment="viewStart"
32+
android:textSize="12sp"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintTop_toBottomOf="@+id/main_label" />
35+
36+
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="purple_200">#FFBB86FC</color>
4+
<color name="purple_500">#FF6200EE</color>
5+
<color name="purple_700">#FF3700B3</color>
6+
<color name="teal_200">#FF03DAC5</color>
7+
<color name="teal_700">#FF018786</color>
8+
<color name="black">#FF000000</color>
9+
<color name="white">#FFFFFFFF</color>
10+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Android Test</string>
3+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
3+
<style name="Theme.App" parent="android:Theme.Material.Light.DarkActionBar" />
4+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.kover.test.android
2+
3+
import org.junit.Test
4+
5+
import org.junit.Assert.*
6+
7+
8+
class LocalTests {
9+
@Test
10+
fun testDebugUtils() {
11+
assertEquals(3, Maths.sum(1, 2))
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
plugins {
2+
id("com.android.application") version "7.4.0" apply false
3+
id("com.android.library") version "7.4.0" apply false
4+
id("org.jetbrains.kotlin.android") version "1.8.20" apply false
5+
id("org.jetbrains.kotlinx.kover") version "0.7.1" apply false
6+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Project-wide Gradle settings.
2+
# IDE (e.g. Android Studio) users:
3+
# Gradle settings configured through the IDE *will override*
4+
# any settings specified in this file.
5+
# For more details on how to configure your build environment visit
6+
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
# Specifies the JVM arguments used for the daemon process.
8+
# The setting is particularly useful for tweaking memory settings.
9+
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10+
# When configured, Gradle will run in incubating parallel mode.
11+
# This option should only be used with decoupled projects. More details, visit
12+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13+
# org.gradle.parallel=true
14+
# AndroidX package structure to make it clearer which packages are bundled with the
15+
# Android operating system, and which are packaged with your app's APK
16+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
17+
android.useAndroidX=true
18+
# Kotlin code style for this project: "official" or "obsolete":
19+
kotlin.code.style=official
20+
# Enables namespacing of each library's R class so that its R class includes only the
21+
# resources declared in the library itself and none from the library's dependencies,
22+
# thereby reducing the size of the R class for that library
23+
android.nonTransitiveRClass=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pluginManagement {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
gradlePluginPortal()
6+
}
7+
}
8+
9+
dependencyResolutionManagement {
10+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11+
repositories {
12+
google()
13+
mavenCentral()
14+
gradlePluginPortal()
15+
}
16+
}
17+
18+
rootProject.name = "android_tasks_filtering"
19+
include(":app")

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/tasks/VariantReportsSet.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal class VariantReportsSet(
5656
verifyCachedTaskName(variantName),
5757
"Task to validate coverage bounding rules for ${variantSuffix()}"
5858
)
59-
val verifyTask = project.tasks.register<KoverVerifyTask>(verifyTaskName(variantName))
59+
val verifyTask = project.tasks.register<KoverVerifyTask>(verifyTaskName(variantName), variantName)
6060

6161
logTask = project.tasks.createReportTask<KoverFormatCoverageTask>(
6262
logTaskName(variantName),
@@ -176,7 +176,7 @@ internal class VariantReportsSet(
176176
name: String,
177177
taskDescription: String
178178
): TaskProvider<T> {
179-
val task = register<T>(name)
179+
val task = register<T>(name, variantName)
180180
// extract property to variable so as not to create a closure to `this`
181181
val koverDisabledProvider = koverDisabled
182182
task.configure {

0 commit comments

Comments
 (0)