Skip to content

Commit

Permalink
feat(testkit): add SettingsScript.Builder and withSettingsScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Aug 20, 2024
1 parent 0d2aec1 commit 6fb437d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ abstract class AbstractProject extends AbstractGradleProject {
return super.newGradleProjectBuilder(dslKind)
.withRootProject { r ->
r.gradleProperties += additionalProperties
r.settingsScript.plugins = new com.autonomousapps.kit.gradle.Plugins(plugins)
r.withSettingsScript { s ->
s.plugins(plugins)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ abstract class AbstractAndroidProject extends AbstractProject {
return newSettingsProjectBuilder(dslKind, withKotlin)
.withRootProject { root ->
root.gradleProperties += GradleProperties.minimalAndroidProperties()
root.settingsScript.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
root.withSettingsScript { s ->
s.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,23 @@ public class RootProject(
public var variant: String? = null
public val files: MutableList<File> = mutableListOf()

// sub-builders
/*
* sub-builders
*/

private var settingsScriptBuilder: SettingsScript.Builder? = null
private var buildScriptBuilder: BuildScript.Builder? = null

public fun withSettingsScript(block: SettingsScript.Builder.() -> Unit) {
val builder = settingsScriptBuilder ?: SettingsScript.Builder()
settingsScript = with(builder) {
block(this)
// store for later building-upon
settingsScriptBuilder = this
build()
}
}

public fun withBuildScript(block: BuildScript.Builder.() -> Unit) {
val builder = buildScriptBuilder ?: defaultBuildScriptBuilder()
buildScript = with(builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,36 @@ public class SettingsScript @JvmOverloads constructor(
DslKind.GROOVY -> "include ':$subproject'"
DslKind.KOTLIN -> "include(\":$subproject\")"
}

public class Builder {
public var pluginManagement: PluginManagement = PluginManagement.DEFAULT
public var buildscript: BuildscriptBlock? = null
public var plugins: Plugins = Plugins.EMPTY
public var dependencyResolutionManagement: DependencyResolutionManagement? = DependencyResolutionManagement.DEFAULT
public var rootProjectName: String = "the-project"
public var subprojects: Set<String> = emptySet()

/** For random stuff, as-yet unmodeled. */
public var additions: String = ""

public fun plugins(vararg plugins: Plugin) {
this.plugins = Plugins(plugins.toMutableList())
}

public fun plugins(plugins: Iterable<Plugin>) {
this.plugins = Plugins(plugins.toMutableList())
}

public fun build(): SettingsScript {
return SettingsScript(
pluginManagement = pluginManagement,
buildscript = buildscript,
plugins = plugins,
dependencyResolutionManagement = dependencyResolutionManagement,
rootProjectName = rootProjectName,
subprojects = subprojects,
additions = additions,
)
}
}
}

0 comments on commit 6fb437d

Please sign in to comment.