Skip to content

Instantly share code, notes, and snippets.

@jonnycaley
Last active June 21, 2022 08:17
Show Gist options
  • Save jonnycaley/de8eea211c3e2c74eace472e6ac13e08 to your computer and use it in GitHub Desktop.
Save jonnycaley/de8eea211c3e2c74eace472e6ac13e08 to your computer and use it in GitHub Desktop.
BuildTaskService - capturing task execution information
abstract class BuildTaskService : BuildService<BuildServiceParameters.None>, OperationCompletionListener {
var fromCacheTasksCount = 0
var upToDateTasksCount = 0
var executedTasksCount = 0
var buildPhaseFailureMessage: String? = null
val buildPhaseFailed: Boolean
get() = buildPhaseFailureMessage != null
override fun onFinish(event: FinishEvent?) {
if (event == null || event !is TaskFinishEvent)
return
when {
event.isFromCache() -> {
fromCacheTasksCount++
}
event.isUpToDate() -> {
upToDateTasksCount++
}
event.isSuccess() -> {
executedTasksCount++
}
}
if (event.result is TaskFailureResult) {
buildPhaseFailureMessage =
(event.result as TaskFailureResult).failures.firstOrNull()?.message
?: "${event.displayName} Failed without message"
}
}
private fun FinishEvent.isUpToDate(): Boolean {
return this.displayName.endsWith("UP-TO-DATE")
}
private fun FinishEvent.isFromCache(): Boolean {
return this.displayName.endsWith("FROM-CACHE")
}
private fun FinishEvent.isSuccess(): Boolean {
return this.displayName.endsWith("SUCCESS")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment