From a08b8852e8262bc13d48b54ff3c0c72532dc115c Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 31 May 2016 23:43:26 -0800 Subject: [PATCH] GITHUB-212: Honor project dependencies for single task targets. Fixes https://github.com/cbeust/kobalt/issues/212 --- .../com/beust/kobalt/internal/TaskManager.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index 2039c9e1..7dc8c2eb 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -81,10 +81,11 @@ class TaskManager @Inject constructor(val args: Args, } } - fun runTargets(taskNames: List, projects: List): RunTargetResult { + fun runTargets(passedTaskNames: List, projects: List): RunTargetResult { var result = 0 val failedProjects = hashSetOf() val messages = Collections.synchronizedList(arrayListOf()) + 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, projects: List): List { + val projectMap = hashMapOf().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 /**