Skip to content

Commit

Permalink
Allow running build types for multiple subprojects at once
Browse files Browse the repository at this point in the history
So we can invoke e.g. `baseServices:quickTest cli:quickTest`.
  • Loading branch information
wolfs committed Jul 10, 2019
1 parent f45238e commit 3245f74
Showing 1 changed file with 18 additions and 15 deletions.
Expand Up @@ -14,6 +14,10 @@ class BuildTypesPlugin : Plugin<Project> {
extensions.add("buildTypes", buildTypes)
buildTypes.all {
register(this)
val activeBuildTypes = buildTypes.filter { it.active }
require(activeBuildTypes.size <= 1) {
"Only one build type can be active. Active build types: ${activeBuildTypes.joinToString(", ") { it.name }}"
}
}
}

Expand All @@ -31,16 +35,19 @@ class BuildTypesPlugin : Plugin<Project> {
}

val invokedTaskNames = gradle.startParameter.taskNames
buildType.findUsedTaskNameAndIndexIn(invokedTaskNames)?.let { (usedName, index) ->
val usedTaskNames = buildType.findUsedTaskNamesWithIndexIn(invokedTaskNames).reversed()
usedTaskNames.forEach { (_, usedName) ->
require(usedName.isNotEmpty())
if (!isTaskHelpInvocation(invokedTaskNames, index)) {
buildType.active = true
buildType.onProjectProperties = { properties: ProjectProperties ->
properties.forEach { (name, value) ->
project.setOrCreateProperty(name, value)
}
buildType.active = true
buildType.onProjectProperties = { properties: ProjectProperties ->
properties.forEach { (name, value) ->
project.setOrCreateProperty(name, value)
}
afterEvaluate {
}
}
if (usedTaskNames.isNotEmpty()) {
afterEvaluate {
usedTaskNames.forEach { (index, usedName) ->
invokedTaskNames.removeAt(index)

val subproject = usedName.substringBeforeLast(":", "")
Expand All @@ -53,16 +60,12 @@ class BuildTypesPlugin : Plugin<Project> {
}

private
fun BuildType.findUsedTaskNameAndIndexIn(taskNames: List<String>): Pair<String, Int>? {
fun BuildType.findUsedTaskNamesWithIndexIn(taskNames: List<String>): List<IndexedValue<String>> {
val candidates = arrayOf(name, abbreviation)
val nameSuffix = ":$name"
val abbreviationSuffix = ":$abbreviation"
return taskNames.indexOfFirst {
it in candidates || it.endsWith(nameSuffix) || it.endsWith(abbreviationSuffix)
}.takeIf {
it >= 0
}?.let {
taskNames[it] to it
return taskNames.withIndex().filter { (index, taskName) ->
(taskName in candidates || taskName.endsWith(nameSuffix) || taskName.endsWith(abbreviationSuffix)) && !isTaskHelpInvocation(taskNames, index)
}
}

Expand Down

0 comments on commit 3245f74

Please sign in to comment.