diff --git a/plugin/src/main/kotlin/org/neotech/plugin/rootcoverage/JaCoCoConfiguration.kt b/plugin/src/main/kotlin/org/neotech/plugin/rootcoverage/JaCoCoConfiguration.kt index 7dc876c..b1a0a86 100644 --- a/plugin/src/main/kotlin/org/neotech/plugin/rootcoverage/JaCoCoConfiguration.kt +++ b/plugin/src/main/kotlin/org/neotech/plugin/rootcoverage/JaCoCoConfiguration.kt @@ -74,6 +74,8 @@ internal fun Project.getExecutionDataFileTree(includeUnitTestResults: Boolean, i // Gradle Managed Devices 8.3+ buildFolderPatterns.add("outputs/managed_device_code_coverage/*/*/coverage.ec") + // In case of flavors coverage is nested an additional 2 folder deeper + buildFolderPatterns.add("outputs/managed_device_code_coverage/*/flavors/*/*/coverage.ec") } return if(buildFolderPatterns.isEmpty()) { null diff --git a/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/IntegrationTest.kt b/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/IntegrationTest.kt index ea069a4..d3ac603 100644 --- a/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/IntegrationTest.kt +++ b/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/IntegrationTest.kt @@ -87,16 +87,16 @@ class IntegrationTest( }) }) - val executeAndroidTests = configuration.pluginConfiguration.getPropertyValue("executeAndroidTests", "true").toBoolean() + val executeAndroidTests = configuration.pluginConfiguration.getPropertyValue("executeAndroidTests", true) // Note: rootCodeCoverageReport is the old and deprecated name of the rootCoverageReport task, it is // used to check whether the old name properly aliases to the new task name. val gradleCommands = if (!executeAndroidTests) { - val runOnGradleManagedDevices = configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices") ?: "false" + val runOnGradleManagedDevices = configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices", false) // Execute Android tests completely separately (as if run on some external service, // after which the resulting files have been imported) - if (runOnGradleManagedDevices == "false") { + if (!runOnGradleManagedDevices) { executeGradleTasks(listOf("clean", "connectedDebugAndroidTest")) } else { executeGradleTasks(listOf("clean", "nexusoneapi30DebugAndroidTest")) @@ -129,7 +129,7 @@ class IntegrationTest( } private fun BuildResult.assertCorrectAndroidTestTasksAreExecuted() { - if (configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices", "false").toBoolean()) { + if (configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices", false)) { val device = configuration.pluginConfiguration.getPropertyValue("gradleManagedDeviceName", "allDevices") assertTaskSuccess(":app:${device}DebugAndroidTest") assertTaskSuccess(":library_android:${device}DebugAndroidTest") @@ -141,14 +141,15 @@ class IntegrationTest( } private fun BuildResult.assertCorrectAndroidTestTasksAreNotExecuted() { - if (configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices", "false").toBoolean()) { + if (configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices", false)) { val device = configuration.pluginConfiguration.getPropertyValue("gradleManagedDeviceName", "allDevices") assertTaskNotExecuted(":app:${device}DebugAndroidTest") assertTaskNotExecuted(":library_android:${device}DebugAndroidTest") - + assertTaskNotExecuted(":library_android_flavors:${device}DemoDebugAndroidTest") } else { assertTaskNotExecuted(":app:connectedDebugAndroidTest") assertTaskNotExecuted(":library_android:connectedDebugAndroidTest") + assertTaskNotExecuted(":library_android_flavors:connectedDemoDebugAndroidTest") } } @@ -162,6 +163,7 @@ class IntegrationTest( report.assertCoverage("org.neotech.library.android", "LibraryAndroidJava") report.assertCoverage("org.neotech.library.android", "LibraryAndroidKotlin") + report.assertCoverage("org.neotech.library.android.flavors", "LibraryAndroidFlavorsKotlin") report.assertCoverage("org.neotech.app", "AppJava") report.assertCoverage("org.neotech.app", "AppKotlin") report.assertCoverage("org.neotech.app", "RobolectricTestedActivity") @@ -253,12 +255,11 @@ class IntegrationTest( ) { data class PluginConfiguration(val properties: List = emptyList()) { - fun getPropertyValue(name: String, defaultValue: String): String = getPropertyValue(name) ?: defaultValue - - fun getPropertyValue(name: String): String? = properties.find { it.name == name }?.value + fun getPropertyValue(name: String, defaultValue: T): T = getPropertyValue(name) ?: defaultValue + fun getPropertyValue(name: String): T? = properties.find { it.name == name }?.value as T? - data class Property(val name: String, val value: String) + data class Property(val name: String, val value: Any) } data class ProjectConfiguration( diff --git a/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/util/ProjectGeneration.kt b/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/util/ProjectGeneration.kt index fd735f1..6922d03 100644 --- a/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/util/ProjectGeneration.kt +++ b/plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/util/ProjectGeneration.kt @@ -35,12 +35,15 @@ inline fun File.readYaml(): T { return mapper.readValue(this, T::class.java) } -internal fun List.toGroovyString(): String = map { - val stringValue = it.value - if (stringValue.toBooleanStrictOrNull() != null) { - "${it.name} ${it.value}" - } else { - "${it.name} \"${it.value}\"" +internal fun List.toGroovyString(): String = map { property -> + when(property.value) { + is Boolean -> "${property.name} ${property.value}" + is String -> "${property.name} \"${property.value}\"" + is Map<*, *> -> { + val values = property.value.map { "\"${it.key}\": \"${it.value}\"" }.joinToString(separator = ", ") + "${property.name} $values" + } + else -> error("Unknown value type: ${property.value}") } }.joinToString(separator = System.lineSeparator()) diff --git a/plugin/src/test/test-fixtures/multi-module/app/build.gradle.tmp b/plugin/src/test/test-fixtures/multi-module/app/build.gradle.tmp index af5e044..f717a9b 100644 --- a/plugin/src/test/test-fixtures/multi-module/app/build.gradle.tmp +++ b/plugin/src/test/test-fixtures/multi-module/app/build.gradle.tmp @@ -15,6 +15,7 @@ android { versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + missingDimensionStrategy 'version', 'demo', 'full' {{defaultConfig.clearPackageData}} @@ -29,8 +30,10 @@ android { debug { enableUnitTestCoverage true enableAndroidTestCoverage true + matchingFallbacks = ['demo'] } release { + matchingFallbacks = ['full'] minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } @@ -58,6 +61,7 @@ android { dependencies { implementation project(":library_android") + implementation project(":library_android_flavors") implementation libs.appCompat diff --git a/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-clear-package-data.yaml b/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-clear-package-data.yaml index 0edab61..74d71e6 100644 --- a/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-clear-package-data.yaml +++ b/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-clear-package-data.yaml @@ -23,6 +23,9 @@ pluginConfiguration: - name: buildVariant value: debug + - name: buildVariantOverrides + value: + ":library_android_flavors": "demoDebug" - name: executeUnitTests value: true diff --git a/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-dont-execute-android-tests.yaml b/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-dont-execute-android-tests.yaml index b0bcbe3..8337fca 100644 --- a/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-dont-execute-android-tests.yaml +++ b/plugin/src/test/test-fixtures/multi-module/configurations/connected-device-dont-execute-android-tests.yaml @@ -20,6 +20,9 @@ pluginConfiguration: - name: buildVariant value: debug + - name: buildVariantOverrides + value: + ":library_android_flavors": "demoDebug" - name: executeUnitTests value: true diff --git a/plugin/src/test/test-fixtures/multi-module/configurations/connected-device.yaml b/plugin/src/test/test-fixtures/multi-module/configurations/connected-device.yaml index 0611077..1403139 100644 --- a/plugin/src/test/test-fixtures/multi-module/configurations/connected-device.yaml +++ b/plugin/src/test/test-fixtures/multi-module/configurations/connected-device.yaml @@ -11,6 +11,9 @@ pluginConfiguration: - name: buildVariant value: debug + - name: buildVariantOverrides + value: + ":library_android_flavors": "demoDebug" - name: executeTests value: true diff --git a/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device-dont-execute-android-tests.yaml b/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device-dont-execute-android-tests.yaml index 3544551..f034656 100644 --- a/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device-dont-execute-android-tests.yaml +++ b/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device-dont-execute-android-tests.yaml @@ -11,6 +11,9 @@ pluginConfiguration: - name: buildVariant value: debug + - name: buildVariantOverrides + value: + ":library_android_flavors": "demoDebug" - name: executeUnitTests value: true diff --git a/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device.yaml b/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device.yaml index 8a43372..501b9de 100644 --- a/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device.yaml +++ b/plugin/src/test/test-fixtures/multi-module/configurations/gradle-managed-device.yaml @@ -11,6 +11,9 @@ pluginConfiguration: - name: buildVariant value: debug + - name: buildVariantOverrides + value: + ":library_android_flavors": "demoDebug" - name: executeTests value: true diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/.gitignore b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/.gitignore @@ -0,0 +1 @@ +/build diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/build.gradle b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/build.gradle new file mode 100644 index 0000000..3c4eeeb --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/build.gradle @@ -0,0 +1,72 @@ +plugins { + id "com.android.library" + alias(libs.plugins.kotlinAndroid) +} + +android { + + namespace "org.neotech.library.flavors" + compileSdkVersion libs.versions.androidCompileSdk.get().toInteger() + + defaultConfig { + minSdkVersion libs.versions.androidMinSdk.get().toInteger() + targetSdkVersion libs.versions.androidTargetSdk.get().toInteger() + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildFeatures { + buildConfig false + } + + buildTypes { + debug { + + testCoverageEnabled true + } + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + flavorDimensions = ["version"] + productFlavors { + demo { + dimension "version" + } + full { + dimension "version" + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + testOptions { + managedDevices { + devices { + nexusoneapi30 (com.android.build.api.dsl.ManagedVirtualDevice) { + device = "Nexus One" + apiLevel = 30 + systemImageSource = "aosp-atd" + } + } + } + } + + kotlinOptions { + jvmTarget = "17" + } +} + +dependencies { + implementation libs.appCompat + + testImplementation libs.bundles.androidTest + androidTestImplementation libs.bundles.androidInstrumentedTest +} diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/proguard-rules.pro b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/androidTest/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlinInstrumentedTest.kt b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/androidTest/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlinInstrumentedTest.kt new file mode 100644 index 0000000..eff666b --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/androidTest/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlinInstrumentedTest.kt @@ -0,0 +1,15 @@ +package org.neotech.library.android.flavors + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class LibraryAndroidFlavorsKotlinInstrumentedTest { + + @Test + fun touch() { + LibraryAndroidFlavorsKotlin.touchedByInstrumentedTest() + } +} \ No newline at end of file diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/AndroidManifest.xml b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/AndroidManifest.xml new file mode 100644 index 0000000..cc947c5 --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlin.kt b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlin.kt new file mode 100644 index 0000000..9c540be --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlin.kt @@ -0,0 +1,12 @@ +package org.neotech.library.android.flavors + +object LibraryAndroidFlavorsKotlin { + + fun touchedByUnitTest(): String { + return "touchedByUnitTest" + } + + fun touchedByInstrumentedTest(): String { + return "touchedByInstrumentedTest" + } +} diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/res/values/strings.xml b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/res/values/strings.xml new file mode 100644 index 0000000..ae87413 --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Library Android Flavors + diff --git a/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/test/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlinUnitTest.kt b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/test/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlinUnitTest.kt new file mode 100644 index 0000000..bc63fda --- /dev/null +++ b/plugin/src/test/test-fixtures/multi-module/library_android_flavors/src/test/java/org/neotech/library/android/flavors/LibraryAndroidFlavorsKotlinUnitTest.kt @@ -0,0 +1,12 @@ +package org.neotech.library.android.flavors + +import org.junit.Assert +import org.junit.Test + +class LibraryAndroidFlavorsKotlinUnitTest { + + @Test + fun touch() { + LibraryAndroidFlavorsKotlin.touchedByUnitTest() + } +} \ No newline at end of file diff --git a/plugin/src/test/test-fixtures/multi-module/settings.gradle b/plugin/src/test/test-fixtures/multi-module/settings.gradle index c5a9ea3..0ca4cdc 100644 --- a/plugin/src/test/test-fixtures/multi-module/settings.gradle +++ b/plugin/src/test/test-fixtures/multi-module/settings.gradle @@ -18,4 +18,4 @@ dependencyResolutionManagement { } } -include ':app', ':library_android', ':library_java', ':library_nested:java' \ No newline at end of file +include ':app', ':library_android', ':library_android_flavors', ':library_java', ':library_nested:java' \ No newline at end of file