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 e4876785..ffa1c107 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 @@ -18,6 +18,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor { private val projectInfos = hashMapOf() 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>() + // 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) + } } diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index b0b04fc2..2fc98023 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -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