From a4282b299ab2ddbd98f56010975424fb97a7d538 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 13:14:25 -0700 Subject: [PATCH] Added kobaltOptions(). --- .../src/main/kotlin/com/beust/kobalt/Args.kt | 6 +++++- .../src/main/kotlin/com/beust/kobalt/BuildScript.kt | 9 +++++++-- .../src/main/kotlin/com/beust/kobalt/api/Kobalt.kt | 6 ++++++ src/main/kotlin/com/beust/kobalt/Main.kt | 10 ++++++++++ 4 files changed, 28 insertions(+), 3 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 443a48de..fe4cf2a3 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 @@ -82,7 +82,11 @@ class Args { @Parameter(names = arrayOf("--noIncrementalKotlin"), description = "Disable incremental Kotlin compilation") var noIncrementalKotlin: Boolean = false - @Parameter(names = arrayOf("--sequential"), description = "Build all the projects in sequence") + companion object { + const val SEQUENTIAL = "--sequential" + } + + @Parameter(names = arrayOf(Args.SEQUENTIAL), description = "Build all the projects in sequence") var sequential: Boolean = false @Parameter(names = arrayOf("--server"), description = "Run in server mode") diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt index 3d75614e..0f594fcd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -27,8 +27,13 @@ class BuildScriptConfig { @Directive fun buildFileClasspath(vararg bfc: String) = newBuildFileClasspath(*bfc) - // The following settings modify the compiler used to compile the build file. - // Projects should use kotlinCompiler { compilerVersion } to configure the Kotin compiler for their source files. + /** Options passed to Kobalt */ + @Directive + fun kobaltOptions(vararg options: String) = Kobalt.addKobaltOptions(options) + + // The following settings modify the compiler used to compile the build file, which regular users should + // probably never need to do. Projects should use kotlinCompiler { compilerVersion } to configure the + // Kotin compiler for their source files. var kobaltCompilerVersion : String? = null var kobaltCompilerRepo: String? = null var kobaltCompilerFlags: String? = null diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt index 49b82050..2c381b1d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt @@ -118,5 +118,11 @@ class Kobalt { get() = Duration.parse( kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT) ?: "P1D") fun findPlugin(name: String) = Plugins.findPlugin(name) + + val optionsFromBuild = arrayListOf() + + fun addKobaltOptions(options: Array) { + optionsFromBuild.addAll(options) + } } } diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 8e8b2ae1..b209c147 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -161,6 +161,7 @@ private class Main @Inject constructor( } else { val allProjects = projectFinder.initForBuildFile(buildFile, args) + addOptionsFromBuild(args, Kobalt.optionsFromBuild) if (args.listTemplates) { // --listTemplates Templates().displayTemplates(pluginInfo) @@ -213,6 +214,15 @@ private class Main @Inject constructor( return result } + private fun addOptionsFromBuild(args: Args, optionsFromBuild: ArrayList) { + optionsFromBuild.forEach { + when(it) { + Args.SEQUENTIAL -> args.sequential = true + else -> throw IllegalArgumentException("Unsupported option found in kobaltOptions(): " + it) + } + } + } + private fun findBuildFile(): File { val deprecatedLocation = File(Constants.BUILD_FILE_NAME) val result: File =