Skip to content

Commit e4c1278

Browse files
CedrickFloconmannodermaus
authored andcommitted
Add support for dynamic-feature plugin (#115)
1 parent 667d696 commit e4c1278

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/util/TestProjectFactory.groovy

+21-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestProjectFactory {
2828
class TestProjectBuilder {
2929

3030
enum Type {
31-
UNSET, APPLICATION, LIBRARY, FEATURE
31+
UNSET, APPLICATION, LIBRARY, FEATURE, DYNAMIC_FEATURE
3232
}
3333

3434
private final Project project
@@ -52,27 +52,28 @@ class TestProjectFactory {
5252
/* Public */
5353

5454
TestProjectBuilder asAndroidApplication() {
55-
if (projectType != Type.UNSET) {
56-
throw new IllegalArgumentException("Project type already set to $projectType")
57-
}
55+
assertProjectTypeUnset()
5856

5957
projectType = Type.APPLICATION
6058
return this
6159
}
6260

6361
TestProjectBuilder asAndroidFeature() {
64-
if (projectType != Type.UNSET) {
65-
throw new IllegalArgumentException("Project type already set to $projectType")
66-
}
62+
assertProjectTypeUnset()
6763

6864
projectType = Type.FEATURE
6965
return this
7066
}
7167

68+
TestProjectBuilder asAndroidDynamicFeature() {
69+
assertProjectTypeUnset()
70+
71+
projectType = Type.DYNAMIC_FEATURE
72+
return this
73+
}
74+
7275
TestProjectBuilder asAndroidLibrary() {
73-
if (projectType != Type.UNSET) {
74-
throw new IllegalArgumentException("Project type already set to $projectType")
75-
}
76+
assertProjectTypeUnset()
7677

7778
projectType = Type.LIBRARY
7879
return this
@@ -113,6 +114,10 @@ class TestProjectFactory {
113114
project.apply plugin: "com.android.feature"
114115
break
115116

117+
case Type.DYNAMIC_FEATURE:
118+
project.apply plugin: "com.android.dynamic-feature"
119+
break
120+
116121
case Type.LIBRARY:
117122
project.apply plugin: "com.android.library"
118123
break
@@ -165,5 +170,11 @@ class TestProjectFactory {
165170
</manifest>
166171
"""
167172
}
173+
174+
private void assertProjectTypeUnset() {
175+
if (projectType != Type.UNSET) {
176+
throw new IllegalArgumentException("Project type already set to $projectType")
177+
}
178+
}
168179
}
169180
}

android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class PluginSpec : Spek({
8282
differentPlugins["application"] = { this.asAndroidApplication() }
8383
differentPlugins["library"] = { this.asAndroidLibrary() }
8484
differentPlugins["feature"] = { this.asAndroidFeature() }
85+
differentPlugins["dynamic-feature"] = { this.asAndroidDynamicFeature() }
8586

8687
differentPlugins.forEach { (pluginName, configFunc) ->
8788
describe("a project using the $pluginName plugin") {

android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Configuration.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.android.build.gradle.api.ApplicationVariant
99
import com.android.build.gradle.api.BaseVariant
1010
import com.android.build.gradle.api.LibraryVariant
1111
import de.mannodermaus.gradle.plugins.junit5.Type.Application
12+
import de.mannodermaus.gradle.plugins.junit5.Type.DynamicFeature
1213
import de.mannodermaus.gradle.plugins.junit5.Type.Feature
1314
import de.mannodermaus.gradle.plugins.junit5.Type.Library
1415
import de.mannodermaus.gradle.plugins.junit5.Type.Test
@@ -62,10 +63,15 @@ private sealed class Type<in T : BaseExtension>(val pluginId: String) {
6263
override fun variants(extension: FeatureExtension): DomainObjectSet<LibraryVariant> =
6364
extension.libraryVariants
6465
}
66+
67+
object DynamicFeature : Type<FeatureExtension>("com.android.dynamic-feature") {
68+
override fun variants(extension: FeatureExtension): DomainObjectSet<LibraryVariant> =
69+
extension.libraryVariants
70+
}
6571
}
6672

6773
private val allTypes: List<Type<*>> =
68-
listOf(Application, Test, Library, Feature)
74+
listOf(Application, Test, Library, Feature, DynamicFeature)
6975

7076
@Suppress("UNCHECKED_CAST")
7177
private fun findType(project: Project): Type<BaseExtension> {

0 commit comments

Comments
 (0)