Last active
June 21, 2022 08:17
-
-
Save jonnycaley/de8eea211c3e2c74eace472e6ac13e08 to your computer and use it in GitHub Desktop.
BuildTaskService - capturing task execution information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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