From 96d0cc64f4bbe91dcb71762e8efba7f49c225e46 Mon Sep 17 00:00:00 2001 From: CedrickFlocon Date: Thu, 20 Sep 2018 16:24:59 +0200 Subject: [PATCH 1/2] Add test for dynamic feature --- .../junit5/util/TestProjectFactory.groovy | 31 +++++++++++++------ .../gradle/plugins/junit5/PluginSpec.kt | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/util/TestProjectFactory.groovy b/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/util/TestProjectFactory.groovy index e2cbb00b..4bf9fce4 100644 --- a/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/util/TestProjectFactory.groovy +++ b/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/util/TestProjectFactory.groovy @@ -28,7 +28,7 @@ class TestProjectFactory { class TestProjectBuilder { enum Type { - UNSET, APPLICATION, LIBRARY, FEATURE + UNSET, APPLICATION, LIBRARY, FEATURE, DYNAMIC_FEATURE } private final Project project @@ -52,27 +52,28 @@ class TestProjectFactory { /* Public */ TestProjectBuilder asAndroidApplication() { - if (projectType != Type.UNSET) { - throw new IllegalArgumentException("Project type already set to $projectType") - } + assertProjectTypeUnset() projectType = Type.APPLICATION return this } TestProjectBuilder asAndroidFeature() { - if (projectType != Type.UNSET) { - throw new IllegalArgumentException("Project type already set to $projectType") - } + assertProjectTypeUnset() projectType = Type.FEATURE return this } + TestProjectBuilder asAndroidDynamicFeature() { + assertProjectTypeUnset() + + projectType = Type.DYNAMIC_FEATURE + return this + } + TestProjectBuilder asAndroidLibrary() { - if (projectType != Type.UNSET) { - throw new IllegalArgumentException("Project type already set to $projectType") - } + assertProjectTypeUnset() projectType = Type.LIBRARY return this @@ -113,6 +114,10 @@ class TestProjectFactory { project.apply plugin: "com.android.feature" break + case Type.DYNAMIC_FEATURE: + project.apply plugin: "com.android.dynamic-feature" + break + case Type.LIBRARY: project.apply plugin: "com.android.library" break @@ -165,5 +170,11 @@ class TestProjectFactory { """ } + + private void assertProjectTypeUnset() { + if (projectType != Type.UNSET) { + throw new IllegalArgumentException("Project type already set to $projectType") + } + } } } diff --git a/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt b/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt index 1ab3a7d8..77f3c867 100644 --- a/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt +++ b/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt @@ -82,6 +82,7 @@ class PluginSpec : Spek({ differentPlugins["application"] = { this.asAndroidApplication() } differentPlugins["library"] = { this.asAndroidLibrary() } differentPlugins["feature"] = { this.asAndroidFeature() } + differentPlugins["dynamic-feature"] = { this.asAndroidDynamicFeature() } differentPlugins.forEach { (pluginName, configFunc) -> describe("a project using the $pluginName plugin") { From 2edcc74eaac691456d4e753ebc029b4434c551e2 Mon Sep 17 00:00:00 2001 From: CedrickFlocon Date: Thu, 20 Sep 2018 16:58:50 +0200 Subject: [PATCH 2/2] Add dynamic feature as know android plugin --- .../de/mannodermaus/gradle/plugins/junit5/Configuration.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Configuration.kt b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Configuration.kt index 8c23a395..bb26e12d 100644 --- a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Configuration.kt +++ b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Configuration.kt @@ -62,10 +62,15 @@ private sealed class Type(val pluginId: String) { override fun variants(extension: FeatureExtension): DomainObjectSet = extension.libraryVariants } + + object DynamicFeature : Type("com.android.dynamic-feature") { + override fun variants(extension: FeatureExtension): DomainObjectSet = + extension.libraryVariants + } } private val allTypes: List> = - listOf(Application, Test, Library, Feature) + listOf(Application, Test, Library, Feature, DynamicFeature) @Suppress("UNCHECKED_CAST") private fun findType(project: Project): Type {