1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

GITHUB-212: Honor project dependencies for single task targets.

Fixes https://github.com/cbeust/kobalt/issues/212
This commit is contained in:
Cedric Beust 2016-05-31 23:43:26 -08:00
parent 85347e9ac5
commit a08b8852e8

View file

@ -81,10 +81,11 @@ class TaskManager @Inject constructor(val args: Args,
}
}
fun runTargets(taskNames: List<String>, projects: List<Project>): RunTargetResult {
fun runTargets(passedTaskNames: List<String>, projects: List<Project>): RunTargetResult {
var result = 0
val failedProjects = hashSetOf<String>()
val messages = Collections.synchronizedList(arrayListOf<String>())
val taskNames = calculateDependentTaskNames(passedTaskNames, projects)
projects.forEach { project ->
AsciiArt.logBox("Building ${project.name}")
@ -140,6 +141,28 @@ class TaskManager @Inject constructor(val args: Args,
return RunTargetResult(result, messages)
}
/**
* If the user wants to run a single task on a single project (e.g. "kobalt:assemble"), we need to
* see if that project depends on others and if it does, invoke these tasks on all of them. This
* function returns all these task names (including dependent).
*/
private fun calculateDependentTaskNames(taskNames: List<String>, projects: List<Project>): List<String> {
val projectMap = hashMapOf<String, Project>().apply {
projects.forEach { put(it.name, it)}
}
val result = ArrayList(taskNames)
taskNames.forEach { taskName ->
val ti = TaskInfo(taskName)
projectMap[ti.project]?.let { project ->
project.projectExtra.dependsOn.forEach { dp ->
result.add(TaskInfo(dp.projectName, ti.taskName).id)
}
}
}
return result
}
val LOG_LEVEL = 3
/**