From be40f5c81db3b985ba10109e97c0f635406e8e3a Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 5 Nov 2017 17:11:11 -0800 Subject: [PATCH 1/7] Fixed finding tools.jar under Windows when JAVA_HOME is set to JRE. --- .../kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt index 598ca401..14c55efd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt @@ -67,7 +67,7 @@ open class Jvm constructor( return toolsJar } if (javaHome!!.name.equals("jre", true)) { - javaHome = javaHome!!.parentFile + _javaHome = javaHome!!.parentFile toolsJar = File(javaHome, "lib/tools.jar") if (toolsJar.exists()) { return toolsJar @@ -78,7 +78,7 @@ open class Jvm constructor( val version = SystemProperties.Companion.javaVersion if (javaHome!!.name.toRegex().matches("jre\\d+") || javaHome!!.name == "jre$version") { - javaHome = File(javaHome!!.parentFile, "jdk$version") + _javaHome = File(javaHome!!.parentFile, "jdk$version") toolsJar = File(javaHome, "lib/tools.jar") if (toolsJar.exists()) { return toolsJar From 2e2444c2bcdc25808c44eb7f14cc1dcfbcfd1293 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Mon, 6 Nov 2017 19:49:28 +0100 Subject: [PATCH 2/7] :ok_hand: Code review change Thanks to @ethauvin for his very good hint! --- .../src/main/kotlin/com/beust/kobalt/archive/Archives.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt index 3d685865..5334e09f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt @@ -18,7 +18,7 @@ class Archives { const val JAR_NAME_WITH_MAIN_CLASS = "jarNameWithMainClass" fun defaultArchiveName(project: Project) = project.name + - if (project.version == null || project.version == "") "" else "-${project.version}" + if (project.version.isNullOrBlank()) "" else "-${project.version}" fun generateArchive(project: Project, context: KobaltContext, From f4f3827fd1a0c6a73b398b35832d0efbd95fa834 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Mon, 6 Nov 2017 19:54:54 +0100 Subject: [PATCH 3/7] :speech_balloon: Adding trimming of line in format string Before: ***** WARNING Old profile syntax detected for " val debug = false", please update to "val debug by profile()" After: ***** WARNING Old profile syntax detected for "val debug = false", please update to "val debug by profile() --- src/main/kotlin/com/beust/kobalt/app/Profiles.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/Profiles.kt b/src/main/kotlin/com/beust/kobalt/app/Profiles.kt index bb5ea346..b2cf1a5a 100644 --- a/src/main/kotlin/com/beust/kobalt/app/Profiles.kt +++ b/src/main/kotlin/com/beust/kobalt/app/Profiles.kt @@ -56,7 +56,7 @@ class Profiles(val context: KobaltContext) { val variable = if (match.first) match.second else oldMatch.second if (oldMatch.first) { - warn("Old profile syntax detected for \"$line\"," + + warn("Old profile syntax detected for \"${line.trim()}\"," + " please update to \"val $variable by profile()\"") } From 20a01f8de00672fec0554c12a5e2de774dd320df Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 8 Nov 2017 01:05:16 -0800 Subject: [PATCH 4/7] Added ignoreInputStream, ignoreErrorStream and ignoreExitvalue to the application plugin. --- .../kotlin/com/beust/kobalt/misc/NewRunCommand.kt | 11 ++++++++--- .../kobalt/plugin/application/ApplicationPlugin.kt | 13 ++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt index 7188cf10..25742fee 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt @@ -19,6 +19,7 @@ class RunCommandInfo { */ var useErrorStreamAsErrorIndicator : Boolean = true var useInputStreamAsErrorIndicator : Boolean = false + var ignoreExitValue : Boolean = false var errorCallback: Function1, Unit> = NewRunCommand.DEFAULT_ERROR var successCallback: Function1, Unit> = NewRunCommand.DEFAULT_SUCCESS @@ -89,10 +90,14 @@ open class NewRunCommand(val info: RunCommandInfo) { // Check to see if the command succeeded val isSuccess = if (info.containsErrors != null) ! info.containsErrors!!(error) - else isSuccess(returnCode, input, error) + else isSuccess(if (info.ignoreExitValue) true else returnCode, input, error) if (isSuccess) { - info.successCallback(input) + if (!info.useErrorStreamAsErrorIndicator) { + info.successCallback(error + input) + } else { + info.successCallback(input) + } } else { info.errorCallback(error + input) } @@ -105,7 +110,7 @@ open class NewRunCommand(val info: RunCommandInfo) { * have various ways to signal errors. */ open protected fun isSuccess(isSuccess: Boolean, input: List, error: List) : Boolean { - var hasErrors = ! isSuccess + var hasErrors: Boolean = ! isSuccess if (info.useErrorStreamAsErrorIndicator && ! hasErrors) { hasErrors = hasErrors || error.isNotEmpty() } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index 2c7433d7..549c2e13 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -17,7 +17,6 @@ import com.beust.kobalt.plugin.packaging.PackageConfig import com.beust.kobalt.plugin.packaging.PackagingPlugin import com.google.inject.Inject import com.google.inject.Singleton -import org.jetbrains.kotlin.config.TargetPlatformVersion.NoVersion.description import java.io.File class ApplicationConfig { @@ -34,6 +33,15 @@ class ApplicationConfig { @Directive fun args(vararg argv: String) = argv.forEach { args.add(it) } val args = arrayListOf() + + @Directive + var ignoreErrorStream: Boolean = false + + @Directive + var ignoreInputStream: Boolean = true + + @Directive + var ignoreExitValue: Boolean = false } @Directive @@ -147,6 +155,9 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigsActor Date: Wed, 8 Nov 2017 10:50:34 -0800 Subject: [PATCH 5/7] 1.0.91. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 21b1f733..be1be459 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.90 \ No newline at end of file +kobalt.version=1.0.91 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index a6a43168..3308b4c2 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.90 +kobalt.version=1.0.91 From 3d2e5b069d87d7a0153868f3616c8ebfcefd79ce Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Nov 2017 13:41:36 -0800 Subject: [PATCH 6/7] BuildConfig not being generated. (#464). --- .../main/kotlin/com/beust/kobalt/Variant.kt | 91 ++++++++++--------- .../kobalt/api/IBuildConfigContributor.kt | 2 +- .../kobalt/internal/JvmCompilerPlugin.kt | 4 + .../kobalt/plugin/kotlin/KotlinCompiler.kt | 4 +- .../plugin/packaging/PackagingPlugin.kt | 2 +- 5 files changed, 55 insertions(+), 48 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt index d15327b1..13120fa0 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt @@ -126,61 +126,62 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null, var generatedSourceDirectory: File? = null -// private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? { -// val buildTypeName = variant?.buildType?.name -// return project.buildTypes[buildTypeName]?.buildConfig -// } -// -// private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? { -// val buildTypeName = variant?.productFlavor?.name -// return project.productFlavors[buildTypeName]?.buildConfig -// } + private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? { + val buildTypeName = variant?.buildType?.name + return project.buildTypes[buildTypeName]?.buildConfig + } + + private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? { + val buildTypeName = variant?.productFlavor?.name + return project.productFlavors[buildTypeName]?.buildConfig + } /** * Return a list of the BuildConfigs found on the productFlavor{}, buildType{} and project{} (in that order). */ -// private fun findBuildConfigs(project: Project, variant: Variant?) : List { -// val result = listOf( -// findBuildTypeBuildConfig(project, variant), -// findProductFlavorBuildConfig(project, variant), -// project.buildConfig) -// .filterNotNull() -// -// return result -// } + private fun findBuildConfigs(project: Project, variant: Variant?) : List { + val result = listOf( + findBuildTypeBuildConfig(project, variant), + findProductFlavorBuildConfig(project, variant), + project.buildConfig) + .filterNotNull() + + return result + } /** * Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type, * product flavor or main project, and use them to generateAndSave any additional field (in that order to * respect the priorities). Return the generated file if it was generated, null otherwise. */ -// fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? { -// val buildConfigs = findBuildConfigs(project, this) -// -// if (buildConfigs.size > 0) { -// val pkg = project.packageName ?: project.group -// ?: throw KobaltException( -// "packageName needs to be defined on the project in order to generateAndSave BuildConfig") -// -// val contributor = ActorUtils.selectAffinityActor(context.pluginInfo.buildConfigContributors, project) -// if (contributor != null) { -// val code = contributor.generateBuildConfig(project, context, pkg, this, buildConfigs) -// val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig")) -// // Make sure the generatedSourceDirectory doesn't contain the project.directory since -// // that directory will be added when trying to find recursively all the sources in it -// generatedSourceDirectory = result.relativeTo(File(project.directory)) -// val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar)) -// val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix) -// KFiles.saveFile(outputDir, code) -// context.logger.log(project.name, 2, "Generated ${outputDir.path}") -// return result -// } else { -// throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig") -// } -// } else { -// return null -// } -// } + fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? { + val buildConfigs = findBuildConfigs(project, this) + + if (buildConfigs.size > 0) { + val pkg = project.packageName ?: project.group + ?: throw KobaltException( + "packageName needs to be defined on the project in order to generateAndSave BuildConfig") + + val contributor = ActorUtils.selectAffinityActor(project, context, + context.pluginInfo.buildConfigContributors) + if (contributor != null) { + val code = contributor.generateBuildConfig(project, context, pkg, this, buildConfigs) + val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig")) + // Make sure the generatedSourceDirectory doesn't contain the project.directory since + // that directory will be added when trying to find recursively all the sources in it + generatedSourceDirectory = result.relativeTo(File(project.directory)) + val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar)) + val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix) + KFiles.saveFile(outputDir, code) + context.logger.log(project.name, 2, "Generated ${outputDir.path}") + return result + } else { + throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig") + } + } else { + return null + } + } override fun toString() = toTask("") diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfigContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfigContributor.kt index 35553f74..ef9d3b4d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfigContributor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfigContributor.kt @@ -5,7 +5,7 @@ import com.beust.kobalt.Variant /** * Plug-ins that can generate a BuildConfig file. */ -interface IBuildConfigContributor : ISimpleAffinity { +interface IBuildConfigContributor : IProjectAffinity { fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant, buildConfigs: List) : String diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 26884af3..51f10052 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -157,6 +157,10 @@ open class JvmCompilerPlugin @Inject constructor( if (compilerContributors.isEmpty()) { throw KobaltException("Couldn't find any compiler for project ${project.name}") } else { + + // Generate BuildConfig if applicable + context.variant.maybeGenerateBuildConfig(project, context) + val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context)}.sorted() /** diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 1d37234a..c001d8db 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -239,7 +239,9 @@ class KotlinCompiler @Inject constructor( location: CompilerMessageLocation?) { if (severity.isError) { "Couldn't compile file: ${dump(location, message)}".let { fullMessage -> - throw KobaltException(fullMessage) + error(fullMessage) + val ex = KobaltException(fullMessage) + throw ex } } else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) { warn(dump(location, message)) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index 3252f750..b7871c90 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -105,7 +105,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana val outputFile = jarGenerator.fullArchiveName(project, context, it.name) outputFiles.add(outputFile) allIncludedFiles.addAll(files) - zipToFiles[it.name] = files + zipToFiles[outputFile.name] = files } } } From 6d7490a34d1928176d7a614e09f54867e1c51437 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Nov 2017 13:42:48 -0800 Subject: [PATCH 7/7] 1.0.92. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index be1be459..ee38765c 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.91 \ No newline at end of file +kobalt.version=1.0.92 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 3308b4c2..ee38765c 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.91 +kobalt.version=1.0.92