Skip to content

Android dynamic feature plugin #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestProjectFactory {
class TestProjectBuilder {

enum Type {
UNSET, APPLICATION, LIBRARY, FEATURE
UNSET, APPLICATION, LIBRARY, FEATURE, DYNAMIC_FEATURE
}

private final Project project
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -165,5 +170,11 @@ class TestProjectFactory {
</manifest>
"""
}

private void assertProjectTypeUnset() {
if (projectType != Type.UNSET) {
throw new IllegalArgumentException("Project type already set to $projectType")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,15 @@ private sealed class Type<in T : BaseExtension>(val pluginId: String) {
override fun variants(extension: FeatureExtension): DomainObjectSet<LibraryVariant> =
extension.libraryVariants
}

object DynamicFeature : Type<FeatureExtension>("com.android.dynamic-feature") {
override fun variants(extension: FeatureExtension): DomainObjectSet<LibraryVariant> =
extension.libraryVariants
}
}

private val allTypes: List<Type<*>> =
listOf(Application, Test, Library, Feature)
listOf(Application, Test, Library, Feature, DynamicFeature)

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