1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Move the BUILD SUCCESSFUL message to the build listener.

This commit is contained in:
Cedric Beust 2016-08-03 19:15:18 -08:00
parent 635cc9cd3c
commit 1969252d16
2 changed files with 27 additions and 11 deletions

View file

@ -18,6 +18,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
private val projectInfos = hashMapOf<String, ProjectInfo>()
private var hasFailures = false
private val args: Args get() = Kobalt.INJECTOR.getInstance(Args::class.java)
private var buildStartTime: Long? = null
// IBuildListener
override fun taskStart(project: Project, context: KobaltContext, taskName: String) {
@ -41,6 +42,11 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
private val projectStatuses = arrayListOf<Pair<Project, ProjectBuildStatus>>()
// IBuildListener
override fun projectStart(project: Project, context: KobaltContext) {
if (buildStartTime == null) buildStartTime = System.currentTimeMillis()
}
// IBuildListener
override fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) {
projectStatuses.add(Pair(project, status))
@ -52,6 +58,9 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
fun formatMillisRight(millis: Long, length: Int) = formatMillis(millis, "%1\$$length.2f")
fun formatMillisLeft(millis: Long, length: Int) = formatMillis(millis, "%1\$-$length.2f")
fun millisToSeconds(millis: Long) = (millis.toDouble() / 1000).toInt()
val buildTime = millisToSeconds(System.currentTimeMillis() - buildStartTime!!)
val profiling = args.profiling
if (profiling) {
log(1, "\n" + AsciiArt.horizontalSingleLine + " Timings (in seconds)")
@ -79,10 +88,21 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
log(1, " " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar)
}
log(1, " " + AsciiArt.lowerBox(line.length))
if (args.parallel) log(1, "Sequential build time would be " +
(projectInfos.values.sumByDouble { it.durationMillis.toDouble() }) / 1000 + " seconds")
// }
// BUILD SUCCESSFUL / FAILED message
val message = StringBuilder(if (args.parallel) "PARALLEL " else "")
.append(if (hasFailures) "BUILD FAILED" else "BUILD SUCCESSFUL ($buildTime seconds")
if (args.parallel) {
val sequentialBuildTime = ((projectInfos.values.sumByDouble { it.durationMillis.toDouble() }) / 1000)
.toInt()
message.append(", sequential build would have been $sequentialBuildTime seconds)")
} else {
message.append(")")
}
log(1, message)
}
}

View file

@ -114,18 +114,14 @@ private class Main @Inject constructor(
var result = 0
val latestVersionFuture = github.latestKobaltVersion
val timing = benchmarkSeconds {
try {
result = runWithArgs(jc, args, argv, pluginClassLoader)
} catch(ex: Throwable) {
error("", ex.cause ?: ex)
result = 1
}
try {
result = runWithArgs(jc, args, argv, pluginClassLoader)
} catch(ex: Throwable) {
error("", ex.cause ?: ex)
result = 1
}
if (!args.update) {
log(1, if (result != 0) "BUILD FAILED: $result" else "BUILD SUCCESSFUL (${timing.first} seconds)")
updateKobalt.checkForNewVersion(latestVersionFuture)
}
return result