mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Project build listeners.
This commit is contained in:
parent
755f305e4d
commit
f319bf5e16
3 changed files with 46 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<Pair<Project, ProjectBuildStatus>>()
|
||||
|
||||
override fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) {
|
||||
projectStatuses.add(Pair(project, status))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -134,6 +134,15 @@ class TaskManager @Inject constructor(val args: Args,
|
|||
var result = TaskResult()
|
||||
val failedProjects = hashSetOf<String>()
|
||||
val messages = Collections.synchronizedList(arrayListOf<ProfilerInfo>())
|
||||
|
||||
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<ITask>, val dryRun: Boolean, val pluginInfo: PluginInfo) : IWorker<ITask> {
|
||||
|
||||
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<ITask>, 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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue