From c2c4a156debe52c619e1cca8e878f75c21b5de0b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 12 Aug 2016 00:24:22 -0800 Subject: [PATCH] Handle zero projects more gracefully. --- .../beust/kobalt/internal/BuildListeners.kt | 6 +++- .../com/beust/kobalt/internal/DynamicGraph.kt | 34 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) 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 23042dff..1a8781a5 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 @@ -59,7 +59,6 @@ class BuildListeners : IBuildListener, IBuildReportContributor { 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) { @@ -94,6 +93,11 @@ class BuildListeners : IBuildListener, IBuildReportContributor { // } } + val buildTime = + if (buildStartTime != null) + millisToSeconds(System.currentTimeMillis() - buildStartTime!!) + else + 0 // BUILD SUCCESSFUL / FAILED message val message = if (hasFailures) { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt index c618472c..81a50616 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt @@ -339,26 +339,28 @@ class DynamicGraphExecutor(val graph : DynamicGraph, val factory: IThreadW } fun displayRegularLog(table: AsciiTable.Builder) : AsciiTable.Builder { - val start = historyLog[0].timestamp - val projectStart = ConcurrentHashMap() - historyLog.forEach { line -> - val row = arrayListOf() - row.add(toSeconds(line.timestamp - start)) - threadIds.keys.forEach { - if (line.threadId == it) { - var duration = "" - if (line.start) { - projectStart[line.name] = line.timestamp + if (historyLog.any()) { + val start = historyLog[0].timestamp + val projectStart = ConcurrentHashMap() + historyLog.forEach { line -> + val row = arrayListOf() + row.add(toSeconds(line.timestamp - start)) + threadIds.keys.forEach { + if (line.threadId == it) { + var duration = "" + if (line.start) { + projectStart[line.name] = line.timestamp + } else { + duration = " (" + ((line.timestamp - projectStart[line.name]!!) / 1000) + .toInt().toString() + ")" + } + row.add((line.name + duration)) } else { - duration = " (" + ((line.timestamp - projectStart[line.name]!!) / 1000) - .toInt().toString() + ")" + row.add("") } - row.add((line.name + duration)) - } else { - row.add("") } + table.addRow(row) } - table.addRow(row) } return table }