From eb0b4b1e0f8bbafb1a7ab6315196fa4347046bc8 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 11 Aug 2016 22:36:50 -0800 Subject: [PATCH] Make parallel builds the default. --- .../src/main/kotlin/com/beust/kobalt/Args.kt | 5 ++++- .../com/beust/kobalt/internal/BuildListeners.kt | 4 ++-- .../com/beust/kobalt/internal/ParallelLogger.kt | 6 +++--- .../beust/kobalt/internal/ParallelProjectRunner.kt | 2 +- .../kotlin/com/beust/kobalt/internal/TaskManager.kt | 11 +++++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt index ee3f0bd0..b2b7ec97 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt @@ -58,7 +58,7 @@ class Args { var noIncremental: Boolean = false @Parameter(names = arrayOf("--parallel"), description = "Build all the projects in parallel whenever possible") - var parallel: Boolean = false + var parallel: Boolean = true @Parameter(names = arrayOf("--plugins"), description = "Comma-separated list of plug-in Maven id's") var pluginIds: String? = null @@ -82,6 +82,9 @@ class Args { @Parameter(names = arrayOf("--projectInfo"), description = "Display information about the current projects") var projectInfo: Boolean = false + @Parameter(names = arrayOf("--sequential"), description = "Build all the projects in sequence") + var sequential: Boolean = false + @Parameter(names = arrayOf("--server"), description = "Run in server mode") var serverMode: Boolean = false 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 38bca022..23042dff 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 @@ -98,10 +98,10 @@ class BuildListeners : IBuildListener, IBuildReportContributor { val message = if (hasFailures) { String.format("BUILD FAILED", buildTime) - } else if (args.parallel) { + } else if (! args.sequential) { val sequentialBuildTime = ((projectInfos.values.sumByDouble { it.durationMillis.toDouble() }) / 1000) .toInt() - String.format("PARALLEL BUILD SUCCESSFUL (%d SECONDS), sequential build sould have taken %d seconds", + String.format("PARALLEL BUILD SUCCESSFUL (%d SECONDS), sequential build would have taken %d seconds", buildTime, sequentialBuildTime) } else { String.format("BUILD SUCCESSFUL (%d SECONDS)", buildTime) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt index 0ffd44d4..afaa7e21 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt @@ -116,10 +116,10 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger { } override fun log(tag: CharSequence, level: Int, message: CharSequence, newLine: Boolean) { - if (args.parallel) { - addLogLine(tag, LogLine(tag, level, message, Type.LOG, newLine)) - } else { + if (args.sequential) { kobaltLog(level, message, newLine) + } else { + addLogLine(tag, LogLine(tag, level, message, Type.LOG, newLine)) } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt index b2f0ec02..a46cd7bc 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt @@ -105,7 +105,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap tasksByNames(p) }, dependsOn, - reverseDependsOn, runBefore, runAfter, alwaysRunAfter, args, pluginInfo, kobaltLog) - else SequentialProjectRunner({ p -> tasksByNames(p) }, dependsOn, - reverseDependsOn, runBefore, runAfter, alwaysRunAfter, args, pluginInfo) + if (args.sequential) { + SequentialProjectRunner({ p -> tasksByNames(p) }, dependsOn, + reverseDependsOn, runBefore, runAfter, alwaysRunAfter, args, pluginInfo) + } else { + ParallelProjectRunner({ p -> tasksByNames(p) }, dependsOn, + reverseDependsOn, runBefore, runAfter, alwaysRunAfter, args, pluginInfo, kobaltLog) + } return projectRunner.runProjects(taskInfos, projectsToRun) }