diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildListener.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildListener.kt index bba9a57b..1e53cc49 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildListener.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildListener.kt @@ -4,6 +4,13 @@ package com.beust.kobalt.api * Plug-ins that listen to build events. */ interface IBuildListener : IListener { - fun taskStart(project: Project, context: KobaltContext, taskName: String) - fun taskEnd(project: Project, context: KobaltContext, taskName: String) + fun taskStart(project: Project, context: KobaltContext, taskName: String) {} + fun taskEnd(project: Project, context: KobaltContext, taskName: String, success: Boolean) {} + + fun projectStart(project: Project, context: KobaltContext) {} + fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) {} +} + +enum class ProjectBuildStatus { + SUCCESS, FAILED, SKIPPED } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt index 535f16e1..5ca93797 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt @@ -19,7 +19,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor { startTimes.put(taskName, System.currentTimeMillis()) } - override fun taskEnd(project: Project, context: KobaltContext, taskName: String) { + override fun taskEnd(project: Project, context: KobaltContext, taskName: String, success: Boolean) { startTimes[taskName]?.let { timings.add(ProfilerInfo(taskName, System.currentTimeMillis() - it)) } @@ -34,6 +34,22 @@ class BuildListeners : IBuildListener, IBuildReportContributor { + " " + it.taskName) } log(1, "\n") + + log(1, "\n" + AsciiArt.horizontalSingleLine + " Build status") + projectStatuses.forEach { pair -> + log(1, " " + pair.first.name + " " + pair.second) + } } + } + + +// override fun projectStart(project: Project, context: KobaltContext) {} + + private val projectStatuses = arrayListOf>() + + override fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) { + projectStatuses.add(Pair(project, status)) + } + } 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 65234019..15a95ea5 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 @@ -134,6 +134,15 @@ class TaskManager @Inject constructor(val args: Args, var result = TaskResult() val failedProjects = hashSetOf() val messages = Collections.synchronizedList(arrayListOf()) + + fun runProjectListeners(project: Project, context: KobaltContext, start: Boolean, + status: ProjectBuildStatus = ProjectBuildStatus.SUCCESS) { + context.pluginInfo.buildListeners.forEach { + if (start) it.projectStart(project, context) else it.projectEnd(project, context, status) + } + } + + val context = Kobalt.context!! projects.forEach { project -> AsciiArt.logBox("Building ${project.name}") @@ -147,10 +156,13 @@ class TaskManager @Inject constructor(val args: Args, if (fp.size > 0) { log(2, "Marking project ${project.name} as skipped") failedProjects.add(project.name) + runProjectListeners(project, context, false, ProjectBuildStatus.SKIPPED) kobaltError("Not building project ${project.name} since it depends on failed " + Strings.pluralize(fp.size, "project") + " " + fp.joinToString(",")) } else { + runProjectListeners(project, context, true) + // There can be multiple tasks by the same name (e.g. PackagingPlugin and AndroidPlugin both // define "install"), so use a multimap val tasksByNames = tasksByNames(project) @@ -181,6 +193,10 @@ class TaskManager @Inject constructor(val args: Args, log(2, "Marking project ${project.name} as failed") failedProjects.add(project.name) } + + runProjectListeners(project, context, false, + if (thisResult.success) ProjectBuildStatus.SUCCESS else ProjectBuildStatus.FAILURE) + if (result.success) { result = thisResult } @@ -540,9 +556,10 @@ class TaskManager @Inject constructor(val args: Args, class TaskWorker(val tasks: List, val dryRun: Boolean, val pluginInfo: PluginInfo) : IWorker { - private fun runBuildListeners(project: Project, context: KobaltContext, taskName: String, start: Boolean) { + private fun runBuildListeners(project: Project, context: KobaltContext, taskName: String, start: Boolean, + success: Boolean = false) { context.pluginInfo.buildListeners.forEach { - if (start) it.taskStart(project, context, taskName) else it.taskEnd(project, context, taskName) + if (start) it.taskStart(project, context, taskName) else it.taskEnd(project, context, taskName, success) } } @@ -559,7 +576,7 @@ class TaskWorker(val tasks: List, val dryRun: Boolean, val pluginInfo: Pl val name = it.project.name + ":" + it.name runBuildListeners(it.project, context, name, start = true) val tr = if (dryRun) TaskResult() else it.call() - runBuildListeners(it.project, context, name, start = false) + runBuildListeners(it.project, context, name, start = false, success = tr.success) success = success and tr.success if (tr.errorMessage != null) errorMessages.add(tr.errorMessage) }