From c90125ede0953abbea3cd0c1ae7e7a04653283c8 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 3 Mar 2017 14:20:01 -0800 Subject: [PATCH 001/532] Incremental compilation timing. --- .../kobalt/plugin/kotlin/KotlinCompiler.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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 66d78b8d..b4863119 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -224,12 +224,19 @@ class KotlinCompiler @Inject constructor( val result = if (cliArgs.noIncrementalKotlin) { - log(2, "Kotlin incremental compilation is disabled") - val exitCode = K2JVMCompiler().exec(collector, Services.Builder().build(), args) - TaskResult(exitCode == ExitCode.OK) + log(2, " Kotlin incremental compilation is disabled") + val duration = benchmarkMillis { + K2JVMCompiler().exec(collector, Services.Builder().build(), args) + } + log(1, " Regular compilation time: ${duration.first} ms") + TaskResult(duration.second == ExitCode.OK) } else { - log(2, "Kotlin incremental compilation is enabled") - compileIncrementally(filesToCompile, sourceFiles, outputDir, info, args, collector) + log(1, " Kotlin incremental compilation is enabled") + val start = System.currentTimeMillis() + val duration = benchmarkMillis { + compileIncrementally(filesToCompile, sourceFiles, outputDir, info, args, collector) + } + log(1, " Incremental compilation time: ${duration.first} ms") TaskResult() } return result From 204ca452e54ff1ebad97363f0f78e75bbe40f671 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 7 Mar 2017 13:24:49 -0800 Subject: [PATCH 002/532] Allow variables in buildScript{}. Fixes https://github.com/cbeust/kobalt/issues/340 --- .../src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt index f8c3d76e..4a5c56ab 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt @@ -21,6 +21,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) var foundClosing = false var count = 0 val result = StringBuffer() + val topLines = arrayListOf() fun updateCount(line: String) { val currentLine = StringBuffer() @@ -46,8 +47,10 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) if (found) { foundKeyword = true count = 1 + result.append(topLines.joinToString("\n")) result.append(line).append("\n") } else { + topLines.add(line) updateCount(line) } From e297586e620a3c808c18e46032816d93da56ad42 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 7 Mar 2017 13:25:05 -0800 Subject: [PATCH 003/532] 1.0.4. --- 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 91fe49a0..16db99fc 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.3 \ No newline at end of file +kobalt.version=1.0.4 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 4c044480..52e2fe1e 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.3 +kobalt.version=1.0.4 From bdd80bdedd020cb157c412f98a64d402890fe555 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 7 Mar 2017 13:53:45 -0800 Subject: [PATCH 004/532] =?UTF-8?q?Don=E2=80=99t=20run=20buildScript{}=20t?= =?UTF-8?q?wice.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/beust/kobalt/misc/BlockExtractor.kt | 16 ++++- .../com/beust/kobalt/app/ParsedBuildFile.kt | 64 ++++++------------- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt index 4a5c56ab..bc1f41cc 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt @@ -11,12 +11,19 @@ fun main(argv: Array) { // BlockExtractor("plugins", '(', ')').extractBlock(lines) } +class BuildScriptInfo(val content: String, val startLine: Int, val endLine: Int) + /** * Used to extract a keyword followed by opening and closing tags out of a list of strings, * e.g. buildScript { ... }. */ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) { - fun extractBlock(lines: List): String? { + fun extractBlock(lines: List): BuildScriptInfo? { + var currentLineNumber = 0 + // First line of the buildScript block + var startLine = 0 + // Last line of the buildScript block + var endLine = 0 var foundKeyword = false var foundClosing = false var count = 0 @@ -34,6 +41,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) if (count == 0) { currentLine.append(closing).append("\n") foundClosing = true + endLine = currentLineNumber } } if (foundKeyword && count > 0) currentLine.append(c) @@ -43,8 +51,10 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) } lines.forEach { line -> + currentLineNumber++ val found = regexp.matcher(line).matches() if (found) { + startLine = currentLineNumber foundKeyword = true count = 1 result.append(topLines.joinToString("\n")) @@ -55,12 +65,12 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) } if (foundKeyword && foundClosing && count == 0) { - return result.toString() + return BuildScriptInfo(result.toString(), startLine, endLine) } } if (foundKeyword && foundClosing && count == 0) { - return result.toString() + return BuildScriptInfo(result.toString(), startLine, endLine) } else { return null } diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index f7064e02..50ea72b0 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -10,14 +10,12 @@ import com.beust.kobalt.internal.build.VersionFile import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.BlockExtractor import com.beust.kobalt.misc.KFiles -import com.beust.kobalt.misc.countChar import com.beust.kobalt.misc.kobaltLog import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate import java.io.File import java.net.URL import java.nio.charset.Charset import java.nio.file.Paths -import java.util.* import java.util.regex.Pattern class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val buildScriptUtil: BuildScriptUtil, @@ -44,14 +42,11 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val } private fun parseBuildFile() { - var parenCount = 0 - var current: ArrayList? = null - /** * If the current line matches one of the profiles, turn the declaration into * val profile = true, otherwise return the same line */ - fun correctProfileLine(line: String) : String { + fun correctProfileLine(line: String): String { (context.profiles as List).forEach { if (line.matches(Regex("[ \\t]*val[ \\t]+$it[ \\t]*=.*"))) { with("val $it = true") { @@ -65,7 +60,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val return line } - fun applyProfiles(lines: List) : List { + fun applyProfiles(lines: List): List { val result = arrayListOf() lines.forEach { line -> result.add(correctProfileLine(line)) @@ -74,51 +69,28 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val } val buildWithCorrectProfiles = applyProfiles(buildFile.path.toFile().readLines()) - val bs = BlockExtractor(Pattern.compile("^val.*buildScript.*\\{"), '{', '}').extractBlock(buildWithCorrectProfiles) + val buildScriptInfo = BlockExtractor(Pattern.compile("^val.*buildScript.*\\{"), '{', '}') + .extractBlock(buildWithCorrectProfiles) - buildFile.path.toFile().forEachLine(Charset.defaultCharset()) { line -> - var index = line.indexOf("plugins(") - if (current == null) { - if (index >= 0) { - current = pluginList - } else { - index = line.indexOf("repos(") - if (index >= 0) { - current = repos - } else { - index = line.indexOf("buildFileClasspath(") - if (index >= 0) { - current = buildFileClasspath - } - } - } - } - - if (parenCount > 0 || current != null) { - if (index == -1) index = 0 - with(line.substring(index)) { - parenCount += line countChar '(' - if (parenCount > 0) { - current!!.add(line) - } - parenCount -= line countChar ')' - } - } - - if (parenCount == 0) { - current = null - } - - buildScript.add(correctProfileLine(line)) - } - - if (bs != null) { - preBuildScript.add(bs) + if (buildScriptInfo != null) { + preBuildScript.add(buildScriptInfo.content) } else { repos.forEach { preBuildScript.add(it) } pluginList.forEach { preBuildScript.add(it) } buildFileClasspath.forEach { preBuildScript.add(it) } } + + // + // Write the build file excluding the buildScript{} tag since we already ran it + // + var lineNumber = 1 + buildFile.path.toFile().forEachLine { line -> + if (buildScriptInfo == null || + (lineNumber < buildScriptInfo.startLine || lineNumber > buildScriptInfo.endLine)) { + buildScript.add(correctProfileLine(line)) + } + lineNumber++ + } } private fun initPluginUrls() { From eaf0b96d6c0af07d50e3fb7251a9ba05030fc47d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 7 Mar 2017 18:27:45 -0800 Subject: [PATCH 005/532] Variables in buildScript(). --- .../src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt | 4 +++- src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt index bc1f41cc..3c48025f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt @@ -60,7 +60,9 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) result.append(topLines.joinToString("\n")) result.append(line).append("\n") } else { - topLines.add(line) + if (! line.startsWith("import") || (line.startsWith("import") && line.contains("com.beust"))) { + topLines.add(line) + } updateCount(line) } diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index 50ea72b0..bf829f40 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -73,6 +73,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val .extractBlock(buildWithCorrectProfiles) if (buildScriptInfo != null) { + kobaltLog(2, "About to compile build file\n" + buildScriptInfo.content) preBuildScript.add(buildScriptInfo.content) } else { repos.forEach { preBuildScript.add(it) } From bfbe4b35a95dac3a775d2cad31af559f88c96253 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 7 Mar 2017 18:27:49 -0800 Subject: [PATCH 006/532] Refactor. --- src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 9d0c4405..00dc4729 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -101,7 +101,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil buildScriptJarFile.parentFile.let { dir -> if (! VersionFile.isSameVersionFile(dir)) { kobaltLog(1, "Detected new installation, wiping $dir") - dir.listFiles().map { it.delete() } + dir.listFiles().map(File::delete) } } From b99eb756ca419212598a686a9985cfadd14da33c Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 7 Mar 2017 18:28:13 -0800 Subject: [PATCH 007/532] 1.0.5. --- 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 16db99fc..1ec95218 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.4 \ No newline at end of file +kobalt.version=1.0.5 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 52e2fe1e..a9a71abb 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.4 +kobalt.version=1.0.5 From 3503405488822446fbfb378da26454d98f9fa442 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 10:26:30 -0800 Subject: [PATCH 008/532] Allow more imports in preBuildScript. --- .../src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt index 3c48025f..922ad515 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt @@ -7,7 +7,6 @@ import java.util.regex.Pattern fun main(argv: Array) { val lines = File(homeDir("kotlin/kobalt/kobalt/src/Build.kt")).readLines() val result = BlockExtractor(Pattern.compile("val.*buildScript.*\\{"), '{', '}').extractBlock(lines) - // BlockExtractor("plugins", '(', ')').extractBlock(lines) } @@ -60,7 +59,9 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) result.append(topLines.joinToString("\n")) result.append(line).append("\n") } else { - if (! line.startsWith("import") || (line.startsWith("import") && line.contains("com.beust"))) { + val allowedImports = listOf("com.beust", "java") + if (! line.startsWith("import") || + (line.startsWith("import") && allowedImports.any { line.contains(it) })) { topLines.add(line) } updateCount(line) From 289c67557cc1a169b3af628cfd5d65fce5be9e93 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 10:26:35 -0800 Subject: [PATCH 009/532] Better logging. --- src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index bf829f40..188974c9 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -73,7 +73,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val .extractBlock(buildWithCorrectProfiles) if (buildScriptInfo != null) { - kobaltLog(2, "About to compile build file\n" + buildScriptInfo.content) + kobaltLog(2, "About to compile build file:\n=====\n" + buildScriptInfo.content + "\n=====") preBuildScript.add(buildScriptInfo.content) } else { repos.forEach { preBuildScript.add(it) } From 6dadd3d751bfcf4c3b771c7d8a6b78292f81ccb1 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 10:26:43 -0800 Subject: [PATCH 010/532] 1.0.6. --- 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 1ec95218..f3cd7d11 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.5 \ No newline at end of file +kobalt.version=1.0.6 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index a9a71abb..f29cc98b 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.5 +kobalt.version=1.0.6 From caf4b1c62a695c2216226c505d24f4bd77652e1d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 13:38:41 -0800 Subject: [PATCH 011/532] Fix StackOverFlow. Fixes https://github.com/cbeust/kobalt/issues/339. --- .../beust/kobalt/maven/aether/KobaltMavenResolver.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 69192c20..0320d456 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -45,7 +45,8 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, fun resolve(artifact: Artifact, scope: Scope? = null, filter: DependencyFilter? = null) = resolve(artifactToId(artifact), scope, filter) - fun resolveToIds(id: String, scope: Scope? = null, filter: DependencyFilter? = null) : List { + fun resolveToIds(id: String, scope: Scope? = null, filter: DependencyFilter? = null, + seen: HashSet = hashSetOf()) : List { val rr = resolve(id, scope, filter) val children = rr.root.children.filter { @@ -55,7 +56,12 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, } val result = listOf(artifactToId(rr.root.artifact)) + children.flatMap { val thisId = artifactToId(it.artifact) - resolveToIds(thisId, scope, filter) + if (! seen.contains(thisId)) { + seen.add(thisId) + resolveToIds(thisId, scope, filter, seen) + } else { + emptyList() + } } return result } From 6f593d5c53febe41106a1289bbb12dee9e48a98c Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 13:47:18 -0800 Subject: [PATCH 012/532] Logging. --- .../kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 b4863119..59348d44 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -254,11 +254,11 @@ class KotlinCompiler @Inject constructor( } override fun report(message: () -> String) { - log(2, " ICReport: ${message()}") + log(3, " ICReport: ${message()}") } override fun reportCompileIteration(sourceFiles: Collection, exitCode: ExitCode) { - log(2, " ICCompileIteration Compiled files: ${pathsAsString(sourceFiles)}") + log(3, " ICCompileIteration Compiled files: ${pathsAsString(sourceFiles)}") compiledFiles.addAll(sourceFiles) } } From a99ce1ce4df3a4bbe62c9ea6c769cc9bc9d7dbb9 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 13:47:33 -0800 Subject: [PATCH 013/532] Logging. --- src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index 188974c9..d4f7e436 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -73,7 +73,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val .extractBlock(buildWithCorrectProfiles) if (buildScriptInfo != null) { - kobaltLog(2, "About to compile build file:\n=====\n" + buildScriptInfo.content + "\n=====") + kobaltLog(3, "About to compile build file:\n=====\n" + buildScriptInfo.content + "\n=====") preBuildScript.add(buildScriptInfo.content) } else { repos.forEach { preBuildScript.add(it) } From df7d9e7d68796996f9672c35a3fa22ff7d607363 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 14:24:43 -0800 Subject: [PATCH 014/532] Better runtime scope handling. --- .../beust/kobalt/api/IDependencyManager.kt | 2 +- .../beust/kobalt/maven/DependencyManager.kt | 32 ++++++++++++------- .../plugin/application/ApplicationPlugin.kt | 3 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt index ce1778aa..c2e7fdb9 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt @@ -26,7 +26,7 @@ interface IDependencyManager { /** * @return the source dependencies for this project, including the contributors. */ - fun dependencies(project: Project, context: KobaltContext): List + fun dependencies(project: Project, context: KobaltContext, scopes: List): List /** * @return the test dependencies for this project, including the contributors. diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index d5b4cd2b..9bcbee7a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -70,12 +70,14 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, /** * @return the source dependencies for this project, including the contributors. */ - override fun dependencies(project: Project, context: KobaltContext) = dependencies(project, context, false) + override fun dependencies(project: Project, context: KobaltContext, scopes: List) + = privateDependencies(project, context, listOf(Scope.COMPILE)) /** * @return the test dependencies for this project, including the contributors. */ - override fun testDependencies(project: Project, context: KobaltContext) = dependencies(project, context, true) + override fun testDependencies(project: Project, context: KobaltContext) + = privateDependencies(project, context, listOf(Scope.COMPILE, Scope.TEST)) /** * Transitive dependencies for the compilation of this project. @@ -232,18 +234,26 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, } } - private fun dependencies(project: Project, context: KobaltContext, isTest: Boolean) + private fun privateDependencies(project: Project, context: KobaltContext, passedScopes: List) : List { + val isTest = passedScopes.contains(Scope.TEST) val transitive = hashSetOf() with(project) { val scopeFilters : ArrayList = arrayListOf(Scope.COMPILE) context.variant.let { variant -> - val deps = arrayListOf(compileDependencies, compileProvidedDependencies, - variant.buildType.compileDependencies, - variant.buildType.compileProvidedDependencies, - variant.productFlavor.compileDependencies, - variant.productFlavor.compileProvidedDependencies - ) + val deps: ArrayList> = + if (passedScopes.contains(Scope.COMPILE)) { + arrayListOf(compileDependencies, compileProvidedDependencies, + variant.buildType.compileDependencies, + variant.buildType.compileProvidedDependencies, + variant.productFlavor.compileDependencies, + variant.productFlavor.compileProvidedDependencies) + } else if (passedScopes.contains(Scope.RUNTIME)) { + arrayListOf(compileRuntimeDependencies) + } else { + arrayListOf(arrayListOf()) + } + val runtimeDeps = arrayListOf(compileRuntimeDependencies) if (isTest) { deps.add(testDependencies) deps.add(testProvidedDependencies) @@ -252,9 +262,9 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val filter = if (isTest) OrDependencyFilter(Filters.COMPILE_FILTER, Filters.TEST_FILTER) else Filters.COMPILE_FILTER - deps.filter { it.any() }.forEach { + runtimeDeps.filter { it.any() }.forEach { transitive.addAll(calculateDependencies(project, context, filter, - scopes = Scope.toScopes(isTest), + passedScopes, // scopes = Scope.toScopes(isTest), passedDependencies = it)) } } 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 d053b918..69a61ceb 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -61,7 +61,8 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor 0) { - return runContributor.run(project, context, dependencyManager.dependencies(project, context)) + return runContributor.run(project, context, + dependencyManager.dependencies(project, context, listOf(Scope.RUNTIME))) } else { context.logger.log(project.name, 1, "Couldn't find a runner for project ${project.name}. Please make sure" + From 5591380dddde1c2d167a6e9282b88f3e4f210a1f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 14:24:52 -0800 Subject: [PATCH 015/532] 1.0.7. --- 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 f3cd7d11..73dd9753 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.6 \ No newline at end of file +kobalt.version=1.0.7 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index f29cc98b..73dd9753 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.6 +kobalt.version=1.0.7 From 6ef86693c739bcecb1d05d6f11123d11c27e46f7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 15:44:33 -0800 Subject: [PATCH 016/532] Added description/vcsTag to bintray{} directive. --- .../beust/kobalt/plugin/publish/BintrayApi.kt | 56 +++++++++++++++---- .../kobalt/plugin/publish/PublishPlugin.kt | 6 ++ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt index 1b5de7bd..7793a77d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt @@ -61,6 +61,14 @@ class BintrayApi @Inject constructor(val http: Http, @Path("name") name: String, @Path("publish") publish: Int, @Body file: File): Call + + class UpdateVersion(val desc: String?, val vcsTag: String?) + + @PATCH("/packages/{owner}/maven/{repo}/versions/{version}") + fun updateVersion(@Path("owner") owner: String, + @Path("repo") repo: String, + @Path("version") version: String, + @Body content: UpdateVersion): Call } private val service: Api @@ -155,13 +163,13 @@ class BintrayApi @Inject constructor(val http: Http, } val results = arrayListOf() - filesToUpload.forEachIndexed { i, file -> - val owner = org ?: username!! - val repo = project.name - val group = project.group!!.replace('.', '/') - val artifact = project.artifactId!! - val version = project.version!! + val owner = org ?: username!! + val repo = project.name + val group = project.group!!.replace('.', '/') + val artifact = project.artifactId!! + val version = project.version!! + filesToUpload.forEachIndexed { i, file -> val result = service.uploadArtifact(owner, repo, group, artifact, version, file.name, if (config.publish) 1 else 0, file) .execute() @@ -181,6 +189,18 @@ class BintrayApi @Inject constructor(val http: Http, logger.log(project.name, 1, " Uploaded $success / $fileCount " + dots(fileCount, results), false) logger.log(project.name, 1, "", true) if (errorMessages.isEmpty()) { + if (config.description != null || config.vcsTag != null) { + // + // Update the version if the user specified some additional version information + // + val versionUpdateResult = service.updateVersion(owner, repo, version, + Api.UpdateVersion(config.description, config.vcsTag)) + .execute() + if (!versionUpdateResult.isSuccessful) { + warn("Couldn't update the version description: " + versionUpdateResult.errorBody()) + } + } + return TaskResult() } else { error(" Errors while uploading:\n" + errorMessages.map { " $it" }.joinToString("\n")) @@ -203,13 +223,18 @@ class BintrayApi @Inject constructor(val http: Http, } class ConverterFactory : Converter.Factory() { - override fun responseBodyConverter(type: Type, annotations: Array, retrofit: Retrofit): Converter? { + override fun responseBodyConverter(type: Type, annotations: Array, + retrofit: Retrofit): Converter? { return GsonResponseBodyConverter(Gson(), Gson().getAdapter(TypeToken.get(type))) } - override fun requestBodyConverter(type: Type, parameterAnnotations: Array, methodAnnotations: Array, - retrofit: Retrofit?): Converter<*, RequestBody>? { - return RequestBodyConverter() + override fun requestBodyConverter(type: Type, parameterAnnotations: Array, + methodAnnotations: Array, + retrofit: Retrofit?): Converter<*, RequestBody>? { + val result = + if (type.typeName == File::class.java.name) FileBodyConverter() + else GsonBodyConverter() + return result } } @@ -224,8 +249,15 @@ class GsonResponseBodyConverter(private val gson: Gson, private val adapter: Typ } } -class RequestBodyConverter : Converter { +class FileBodyConverter : Converter { override fun convert(value: File): RequestBody { return CountingFileRequestBody(value, "application/*", { }) } -} \ No newline at end of file +} + +class GsonBodyConverter : Converter { + override fun convert(value: Any): RequestBody { + val jo = Gson().toJson(value) + return RequestBody.create(MediaType.parse("application/json"), jo.toString()) + } +} diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 9ffea810..56883401 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -241,6 +241,12 @@ data class BintrayConfig(val project: Project) { fun file(filePath: String, url: String) { files.add(Pair(filePath, url)) } + + @Directive + var description: String? = null + + @Directive + var vcsTag: String? = null } @Directive From 443847c171ce6218d6ed79b543a7ee425dececb6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 15:44:54 -0800 Subject: [PATCH 017/532] 1.0.8. --- 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 73dd9753..127a961a 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.7 +kobalt.version=1.0.8 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 73dd9753..127a961a 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.7 +kobalt.version=1.0.8 From 5ea2fe30b0b238e5abfafb6bc29e51ddf0a721db Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 8 Mar 2017 15:56:50 -0800 Subject: [PATCH 018/532] Investigate TeamCity build failures. --- .../src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 04fee461..8172ab6f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -265,9 +265,12 @@ class KFiles { } fun saveFile(file: File, text: String) { - file.absoluteFile.parentFile.mkdirs() - file.writeText(text) - kobaltLog(2, "Created $file") + if (file.absoluteFile.parentFile.mkdirs()) { + file.writeText(text) + kobaltLog(2, "Created $file") + } else { + warn("Couldn't create directory to save $file") + } } private fun isWindows() = System.getProperty("os.name").contains("Windows") From 87c56d320e2f0887d6097227f70dbbd012bff417 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 9 Mar 2017 13:32:10 -0800 Subject: [PATCH 019/532] BuildParser fix. --- .../src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt index 922ad515..7e30198f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt @@ -60,8 +60,10 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) result.append(line).append("\n") } else { val allowedImports = listOf("com.beust", "java") + val disallowedImports = listOf("com.beust.kobalt.plugin") if (! line.startsWith("import") || - (line.startsWith("import") && allowedImports.any { line.contains(it) })) { + (line.startsWith("import") && allowedImports.any { line.contains(it) } + && ! disallowedImports.any { line.contains(it) })) { topLines.add(line) } updateCount(line) From de052ea7f2e7bef19794c00bc1a5b7488d5be34e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 9 Mar 2017 13:32:17 -0800 Subject: [PATCH 020/532] Warnings. --- .../src/main/kotlin/com/beust/kobalt/AsciiArt.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt index df506b9f..6247caeb 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt @@ -150,9 +150,9 @@ class AsciiTable { append("\n") } var lineLength = 0 - rows.forEachIndexed { index, row -> + rows.forEachIndexed { _, row -> val formattedRow = row.mapIndexed { i, s -> col(widths[i], s) }.joinToString(vb) - val line = vb + " " + formattedRow + " " + vb + val line = "$vb $formattedRow $vb" result.append(line).append("\n") lineLength = line.length } From c590ed2ebda65797b2743038dd7a37084b5416cb Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 9 Mar 2017 13:32:23 -0800 Subject: [PATCH 021/532] 1.0.9. --- 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 127a961a..c8248995 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.8 +kobalt.version=1.0.9 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 127a961a..a80e7062 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.8 +kobalt.version=1.0.9 From e8bdd888a7a972e3f27b4b159d22c59e80c0ba2f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 9 Mar 2017 13:48:39 -0800 Subject: [PATCH 022/532] Better file detection. --- .../main/kotlin/com/beust/kobalt/misc/KFiles.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 8172ab6f..22f5432f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -265,11 +265,19 @@ class KFiles { } fun saveFile(file: File, text: String) { - if (file.absoluteFile.parentFile.mkdirs()) { + var canCreate = true + with(file.absoluteFile.parentFile) { + if (!exists()) { + val success = mkdirs() + if (!success) { + warn("Couldn't create directory to save $file") + canCreate = false + } + } + } + if (canCreate) { file.writeText(text) kobaltLog(2, "Created $file") - } else { - warn("Couldn't create directory to save $file") } } From 94082e125188d49793721ea6af4a75cbc65c7a93 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 09:55:22 -0800 Subject: [PATCH 023/532] Indent. --- .../kotlin/com/beust/kobalt/misc/KobaltLogger.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt index 0bcbd313..8cd201da 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt @@ -5,6 +5,8 @@ import com.beust.kobalt.AsciiArt import com.beust.kobalt.KobaltException import com.beust.kobalt.api.Kobalt import com.beust.kobalt.maven.aether.Exceptions +import jdk.nashorn.internal.objects.Global.print +import java.lang.Exception import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -51,11 +53,11 @@ object KobaltLogger { var LOG_LEVEL: Int = 1 val logger: Logger get() = - if (Kobalt.context != null) { - Logger(Kobalt.context!!.args.dev) - } else { - Logger(false) - } + if (Kobalt.context != null) { + Logger(Kobalt.context!!.args.dev) + } else { + Logger(false) + } } class Logger(val dev: Boolean) { From 99c5bd560f28b87937d44839d916da51557086eb Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 09:55:38 -0800 Subject: [PATCH 024/532] Trim dependencies. --- .../src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 9bcbee7a..6913c8ed 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -150,7 +150,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, result.filter { ! isDependencyExcluded(it, project.excludedDependencies) } } else { result - } + }.toHashSet() val reordered = reorderDependencies(shortResult) return reordered } From ef79394d49d71abad76137abe0fe6257a29b6b7e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 09:55:52 -0800 Subject: [PATCH 025/532] Wipe the jar file. --- src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 00dc4729..97f08a0d 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -147,7 +147,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil } else { kobaltLog(2, " Need to recompile ${buildFile.name}") - buildScriptJarFile.delete() + buildScriptJarFile.deleteRecursively() val buildFileClasspath = Kobalt.buildFileClasspath.map { it.jarFile.get() }.map { it.absolutePath } val result = kotlinCompilePrivate { classpath(files.kobaltJar) From d111df75d2f7060eda4b97e14c5a550212b4f938 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 09:56:11 -0800 Subject: [PATCH 026/532] 1.0.11. --- 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 c8248995..297298a1 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.9 \ No newline at end of file +kobalt.version=1.0.11 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index a80e7062..297298a1 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.9 +kobalt.version=1.0.11 From 49d142659a271fe4c89cbb9e97f3fe91548e4523 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 10:15:20 -0800 Subject: [PATCH 027/532] Silly import completely wrecked the logger. --- .../src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt index 8cd201da..a361b0d5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt @@ -5,7 +5,6 @@ import com.beust.kobalt.AsciiArt import com.beust.kobalt.KobaltException import com.beust.kobalt.api.Kobalt import com.beust.kobalt.maven.aether.Exceptions -import jdk.nashorn.internal.objects.Global.print import java.lang.Exception import java.time.LocalDateTime import java.time.format.DateTimeFormatter From 187593b9b17832b8d05b26508cf13eec86183b0d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 10:48:31 -0800 Subject: [PATCH 028/532] Test that BuildKt.class is not in the shipped jar file. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 750e7531..01cbd9a7 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -13,25 +13,11 @@ import java.util.jar.JarFile import java.util.jar.JarInputStream class VerifyKobaltZipTest : KobaltTest() { - private fun verifyMainJarFile(ins: InputStream) { - assertExistsInJarInputStream(JarInputStream(ins), "com/beust/kobalt/MainKt.class", - "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", - "com/beust/kobalt/wrapper/Main.class") - } @Test fun verifySourceJarFile() { assertExistsInJar("kobalt-$KOBALT_VERSION-sources.jar", "com/beust/kobalt/Main.kt") } - // Can't use Kobalt.version since the tests have their own src/test/resources/kobalt.properties - val KOBALT_VERSION: String - get() { - val p = Properties() - p.load(FileReader("src/main/resources/kobalt.properties")) - val result = p.getProperty("kobalt.version") - return result - } - @Test fun verifyZipFile() { var foundKobaltw = false @@ -57,7 +43,7 @@ class VerifyKobaltZipTest : KobaltTest() { } else if (entry.name.endsWith("kobalt-wrapper.jar")) { val ins = zipFile.getInputStream(entry) foundWrapperJar = true - assertExistsInJarInputStream(JarInputStream(ins), "kobalt.properties") + assertExistsInJar(JarInputStream(ins), "kobalt.properties") } entry = stream.nextEntry } @@ -76,10 +62,38 @@ class VerifyKobaltZipTest : KobaltTest() { } } - private fun assertExistsInJarInputStream(ins: JarInputStream, vararg fileNames: String) { + // Can't use Kobalt.version since the tests have their own src/test/resources/kobalt.properties + val KOBALT_VERSION: String + get() { + val p = Properties() + p.load(FileReader("src/main/resources/kobalt.properties")) + val result = p.getProperty("kobalt.version") + return result + } + + private fun verifyMainJarFile(ins: InputStream) { + JarInputStream(ins).let { jar -> + assertExistsInJar(jar, "com/beust/kobalt/MainKt.class", + "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", + "com/beust/kobalt/wrapper/Main.class") + assertDoesNotExistInJar(jar, "BuildKt.class") + } + } + + private fun assertExistsInJar(ins: JarInputStream, vararg fileNames: String) + = assertExistence(ins, true, *fileNames) + + private fun assertDoesNotExistInJar(ins: JarInputStream, vararg fileNames: String) + = assertExistence(ins, false, *fileNames) + + private fun assertExistence(ins: JarInputStream, verifyExistence: Boolean, vararg fileNames: String) { with(jarContents(ins)) { fileNames.forEach { fileName -> - Assert.assertTrue(contains(fileName), "Couldn't find $fileName") + if (verifyExistence) { + Assert.assertTrue(contains(fileName), "Couldn't find $fileName") + } else { + Assert.assertFalse(contains(fileName), "Couldn't find $fileName") + } } } } @@ -88,7 +102,7 @@ class VerifyKobaltZipTest : KobaltTest() { val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val file = File(sourceJarPath) if (file.exists()) { - assertExistsInJarInputStream(JarInputStream(FileInputStream(file)), *fileNames) + assertExistsInJar(JarInputStream(FileInputStream(file)), *fileNames) } else { kobaltLog(1, "Couldn't find $file, skipping test") } From 1f3f666d93b34c0cfc4eb3553677a1f74f5b5f78 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 12:39:44 -0800 Subject: [PATCH 029/532] Always compile the build files with Kotlin incremental compilation disabled. --- .../main/kotlin/com/beust/kobalt/api/KobaltContext.kt | 9 ++++++++- .../kotlin/com/beust/kobalt/internal/CompilerUtils.kt | 2 +- .../kotlin/com/beust/kobalt/app/BuildFileCompiler.kt | 5 +++-- .../kotlin/com/beust/kobalt/app/ParsedBuildFile.kt | 2 ++ .../kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt | 2 +- .../com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt | 11 ++++++++--- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt index 57939069..b7e5ace8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt @@ -19,7 +19,6 @@ import java.io.File class KobaltContext(val args: Args) { lateinit var variant: Variant val profiles = arrayListOf() - var forceRecompile: Boolean = false init { args.profiles?.split(',')?.filterNotNull()?.forEach { @@ -106,4 +105,12 @@ class InternalContext { * The absolute directory of the current project. */ var absoluteDir: File? = null + + /** + * If true, will force a recompile of the files even if using the incremental compile + */ + var forceRecompile: Boolean = false + + var noIncrementalKotlin: Boolean = false + } \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index e17ee4d4..b47fab50 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -167,7 +167,7 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager // Finally, alter the info with the compiler interceptors before returning it val initialActionInfo = CompilerActionInfo(projectDirectory.path, classpath, allSources, sourceSuffixes, buildDirectory, emptyList() /* the flags will be provided by flag contributors */, - emptyList(), context.forceRecompile) + emptyList(), context.internalContext.forceRecompile) val result = context.pluginInfo.compilerInterceptors.fold(initialActionInfo, { ai, interceptor -> interceptor.intercept(project, context, ai) }) diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 97f08a0d..730cb304 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -61,7 +61,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil context.resolver = resolver context.pomGeneratorFactory = pomGeneratorFactory context.logger = parallelLogger - context.forceRecompile = forceRecompile + context.internalContext.forceRecompile = forceRecompile Kobalt.context = context // The list of dynamic plug-ins has to be a companion since it's modified directly from @@ -111,7 +111,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil KFiles.saveFile(modifiedBuildFile, parsedBuildFile.buildScriptCode) val taskResult = maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path), "Modified ${Constants.BUILD_FILE_NAME}", buildFile.realPath), - buildScriptJarFile, pluginUrls, context.forceRecompile) + buildScriptJarFile, pluginUrls, context.internalContext.forceRecompile) if (taskResult.success) { projects.addAll(buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context)) } else { @@ -155,6 +155,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil classpath(buildFileClasspath) sourceFiles(listOf(buildFile.path.toFile().absolutePath)) output = buildScriptJarFile + noIncrementalKotlin = true }.compile(context = context) diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index d4f7e436..8f7d3fe3 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -138,11 +138,13 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val val kotlinDeps = dependencyManager.calculateDependencies(null, context) val deps: List = kotlinDeps.map { it.jarFile.get().absolutePath } val outputJar = File(buildScriptJarFile.absolutePath) + val saved = context.internalContext.noIncrementalKotlin val result = kotlinCompilePrivate { classpath(files.kobaltJar) classpath(deps) sourceFiles(buildFile.path.toFile().absolutePath) output = outputJar + noIncrementalKotlin = true }.compile(context = context) if (! result.success) { throw KobaltException("Couldn't compile ${originalFile.realPath}:\n" diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 2aa3156d..168027ad 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -91,7 +91,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va val dependencies = dependencyManager.calculateDependencies(project, context) val info = CompilerActionInfo(sourceDir.absolutePath, dependencies, listOf(javaFile.absolutePath), listOf("java"), File(sourceDir, "generated"), - listOf(), listOf(), context.forceRecompile) + listOf(), listOf(), context.internalContext.forceRecompile) val results = compilerUtils.invokeCompiler(project, context, javaCompiler, info) } 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 59348d44..4d8a0f85 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -223,7 +223,7 @@ class KotlinCompiler @Inject constructor( System.setProperty("kotlin.incremental.compilation.experimental", "true") val result = - if (cliArgs.noIncrementalKotlin) { + if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) { log(2, " Kotlin incremental compilation is disabled") val duration = benchmarkMillis { K2JVMCompiler().exec(collector, Services.Builder().build(), args) @@ -383,7 +383,7 @@ class KotlinCompiler @Inject constructor( emptyList() } val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args, - friendPaths, context?.forceRecompile ?: false) + friendPaths, context?.internalContext?.forceRecompile ?: false) return jvmCompiler.doCompile(project, context, compilerAction, info, if (context != null) compilerUtils.sourceCompilerFlags(project, context, info) else emptyList()) @@ -396,6 +396,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ var source = arrayListOf() var output: File by Delegates.notNull() val args = arrayListOf() + var noIncrementalKotlin = false fun sourceFiles(s: String) = source.add(s) @@ -408,7 +409,11 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ fun compilerArgs(s: List) = args.addAll(s) fun compile(project: Project? = null, context: KobaltContext? = null) : TaskResult { - return compiler.compile(project, context, dependencies, classpath, source, output, args) + val saved = context?.internalContext?.noIncrementalKotlin ?: false + if (context != null) context.internalContext.noIncrementalKotlin = noIncrementalKotlin + val result = compiler.compile(project, context, dependencies, classpath, source, output, args) + if (context != null) context.internalContext.noIncrementalKotlin = saved + return result } } From 3ca1f5612f4a9c275816de407880310f1149f319 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 12 Mar 2017 21:22:52 -0700 Subject: [PATCH 030/532] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e8db3ef6..d2a79419 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Kobalt [![Build Status](https://travis-ci.org/cbeust/kobalt.svg?branch=master)](https://travis-ci.org/cbeust/kobalt) +# Kobalt Kobalt is a universal build system. From 1fb4278cd62ae4c4779120d9361b713acc4d1585 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 13 Mar 2017 11:26:32 -0700 Subject: [PATCH 031/532] Investigate the TeamCity build failure. --- .../src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 22f5432f..32bde0f5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -259,7 +259,8 @@ class KFiles { * The build location for build scripts is .kobalt/build */ fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String { - val result = joinDir(buildFile.dotKobaltDir.absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile) + val result = joinDir(File(".").absolutePath,buildFile.dotKobaltDir.absolutePath, + KFiles.SCRIPT_BUILD_DIR, jarFile) kobaltLog(2, "Script jar file: $result") return result } From 2bfe9b1339678ebd5ba47793f41d0f5654b9ecdb Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 13 Mar 2017 11:40:56 -0700 Subject: [PATCH 032/532] Restore log level. --- src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt index 491f5f73..00d71d5f 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt @@ -36,7 +36,6 @@ class ExcludeTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor } """ - KobaltLogger.LOG_LEVEL = 3 val project = compileSingleProject(projectText) val allIds = dependencyManager.calculateDependencies(project, Kobalt.context!!, scopes = listOf(Scope.COMPILE)) From 28ed175979970385715b89921a9c1368500be79d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 13 Mar 2017 12:37:59 -0700 Subject: [PATCH 033/532] Redundant. --- src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt index 9e913779..55f980f8 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt @@ -80,7 +80,7 @@ class BuildScriptUtil @Inject constructor(val plugins: Plugins, val files: KFile try { val r = method.invoke(null) if (r is Project) { - kobaltLog(2, "Found project ${r.name} in class $cls") + kobaltLog(2, "Found project ${r.name} in $cls") projects.add(r) } } catch(ex: Throwable) { From c056fa5c9fa8c58b9ba8a049f3f41e6cc4cfb9b2 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 13 Mar 2017 12:38:15 -0700 Subject: [PATCH 034/532] Restore path. --- .../src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 32bde0f5..22f5432f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -259,8 +259,7 @@ class KFiles { * The build location for build scripts is .kobalt/build */ fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String { - val result = joinDir(File(".").absolutePath,buildFile.dotKobaltDir.absolutePath, - KFiles.SCRIPT_BUILD_DIR, jarFile) + val result = joinDir(buildFile.dotKobaltDir.absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile) kobaltLog(2, "Script jar file: $result") return result } From 383128d96b7737c30c9ffa296169510bc1f5dbbe Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 14 Mar 2017 15:52:03 -0700 Subject: [PATCH 035/532] Work in progress for incremental archival task. --- .../com/beust/kobalt/ArchiveFileFinder.kt | 11 +++++++ .../kotlin/com/beust/kobalt/JarGenerator.kt | 13 +++++--- .../kotlin/com/beust/kobalt/archive/Jar.kt | 2 +- .../kotlin/com/beust/kobalt/archive/Zip.kt | 3 +- .../plugin/packaging/PackagingPlugin.kt | 32 ++++++++++++++++++- .../kobalt/plugin/packaging/WarGenerator.kt | 6 ++-- .../kobalt/plugin/packaging/ZipGenerator.kt | 10 ++++-- 7 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt new file mode 100644 index 00000000..6cddba35 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt @@ -0,0 +1,11 @@ +package com.beust.kobalt.plugin.packaging + +import com.beust.kobalt.api.KobaltContext +import com.beust.kobalt.api.Project +import com.beust.kobalt.archive.Zip +import com.beust.kobalt.misc.IncludedFile + +interface ArchiveFileFinder { + fun findIncludedFiles(project: Project, context: KobaltContext, zip: Zip) : List +} + diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt index aeef361c..e2383e50 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt @@ -4,9 +4,11 @@ import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.archive.Archives import com.beust.kobalt.archive.Jar +import com.beust.kobalt.archive.Zip import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.aether.Scope import com.beust.kobalt.misc.* +import com.beust.kobalt.plugin.packaging.ArchiveFileFinder import com.google.inject.Inject import java.io.File import java.io.FileInputStream @@ -15,9 +17,10 @@ import java.nio.file.Paths import java.util.jar.JarOutputStream import java.util.jar.Manifest -class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) { +class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) : ArchiveFileFinder { companion object { - fun findIncludedFiles(directory: String, files: List, excludes: List) + fun findIncludedFiles(directory: String, files: List, excludes: List, + throwOnError: Boolean = true) : List { val result = arrayListOf() files.forEach { includedFile -> @@ -27,7 +30,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) if (File(directory, fromPath).exists()) { spec.toFiles(directory, fromPath).forEach { file -> val fullFile = File(KFiles.joinDir(directory, fromPath, file.path)) - if (! fullFile.exists()) { + if (! fullFile.exists() && throwOnError) { throw AssertionError("File should exist: $fullFile") } @@ -52,7 +55,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) } } - fun findIncludedFiles(project: Project, context: KobaltContext, jar: Jar) : List { + override fun findIncludedFiles(project: Project, context: KobaltContext, jar: Zip) : List { // // Add all the applicable files for the current project // @@ -86,7 +89,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) // // The user specified an include, just use it verbatim // - val includedFiles = findIncludedFiles(project.directory, jar.includedFiles, jar.excludes) + val includedFiles = findIncludedFiles(project.directory, jar.includedFiles, jar.excludes, false) result.addAll(includedFiles) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt index f8a47848..80a7bd1a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt @@ -8,7 +8,7 @@ import com.beust.kobalt.api.annotation.Directive */ open class Jar(override val project: Project, override var name : String = Archives.defaultArchiveName(project) + ".jar", - var fatJar: Boolean = false) : Zip(project, name), AttributeHolder { + override var fatJar: Boolean = false) : Zip(project, name, fatJar), AttributeHolder { @Directive fun manifest(init: Manifest.(p: Manifest) -> Unit) : Manifest { val m = Manifest(this) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt index 61237291..22b5809d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt @@ -8,7 +8,8 @@ import com.beust.kobalt.misc.From import com.beust.kobalt.misc.IncludedFile import com.beust.kobalt.misc.To -open class Zip(open val project: Project, open var name: String = Archives.defaultArchiveName(project) + ".zip") { +open class Zip(open val project: Project, open var name: String = Archives.defaultArchiveName(project) + ".zip", + open var fatJar: Boolean = false) { val excludes = arrayListOf() @Directive 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 0518fed6..ba04971e 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -11,7 +11,9 @@ import com.beust.kobalt.internal.IncrementalManager import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.ParallelLogger import com.beust.kobalt.maven.DependencyManager +import com.beust.kobalt.maven.Md5 import com.beust.kobalt.maven.PomGenerator +import com.beust.kobalt.misc.IncludedFile import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors import java.io.File @@ -68,6 +70,34 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana * skipped. */ override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { + val allArchivers = packages.filter { it.project.name == project.name } + + if (false) { + // Work in progress + val allIncludedFiles = arrayListOf() + val zipToFiles = hashMapOf>() + allArchivers.forEach { packageConfig -> + listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> + archives.forEach { + val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) + allIncludedFiles.addAll(files) + zipToFiles[it.name] = files + } + } + } + val allFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> + val foundFiles = includedFile.allFromFiles(project.directory) + val absFiles = foundFiles.map { + File(KFiles.joinDir(project.directory, includedFile.from, it.path)) + } + files.addAll(absFiles) + files + } + + val md5 = Md5.toMd5Directories(allFiles) + println("MD5 is: " + md5) + } + return IncrementalTaskInfo( { null }, { null }, @@ -75,7 +105,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana try { project.projectProperties.put(Archives.JAR_NAME, context.variant.archiveName(project, null, ".jar")) - packages.filter { it.project.name == project.name }.forEach { packageConfig -> + allArchivers.forEach { packageConfig -> packageConfig.jars.forEach { jarGenerator.generateJar(packageConfig.project, context, it) } packageConfig.wars.forEach { warGenerator.generateWar(packageConfig.project, context, it) } packageConfig.zips.forEach { zipGenerator.generateZip(packageConfig.project, context, it) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt index 8ecafab1..1bce23eb 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt @@ -7,6 +7,7 @@ import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.archive.Archives import com.beust.kobalt.archive.War +import com.beust.kobalt.archive.Zip import com.beust.kobalt.internal.ParallelLogger import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.From @@ -19,7 +20,8 @@ import java.io.OutputStream import java.nio.file.Paths import java.util.jar.JarOutputStream -class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) { +class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) + : ArchiveFileFinder { companion object { val WEB_INF = "WEB-INF" @@ -27,7 +29,7 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val LIB = "$WEB_INF/lib" } - fun findIncludedFiles(project: Project, context: KobaltContext, war: War) : List { + override fun findIncludedFiles(project: Project, context: KobaltContext, war: Zip) : List { // // src/main/web app and classes // diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt index fed784a0..4427892b 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt @@ -7,11 +7,17 @@ import com.beust.kobalt.archive.Archives import com.beust.kobalt.archive.Zip import com.beust.kobalt.internal.ParallelLogger import com.beust.kobalt.maven.DependencyManager +import com.beust.kobalt.misc.IncludedFile import com.google.inject.Inject -class ZipGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) { +class ZipGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) + : ArchiveFileFinder { + override fun findIncludedFiles(project: Project, context: KobaltContext, zip: Zip): List { + return JarGenerator.findIncludedFiles(project.directory, zip.includedFiles, zip.excludes) + } + fun generateZip(project: Project, context: KobaltContext, zip: Zip) { - val allFiles = JarGenerator.findIncludedFiles(project.directory, zip.includedFiles, zip.excludes) + val allFiles = findIncludedFiles(project, context, zip) Archives.generateArchive(project, context, zip.name, ".zip", allFiles) } } From a0ce7498e32cbe372610f45949a9433a118c1b2d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 14 Mar 2017 16:06:13 -0700 Subject: [PATCH 036/532] Output checksums. --- .../kotlin/com/beust/kobalt/ArchiveFileFinder.kt | 9 ++++++++- .../kobalt/plugin/packaging/PackagingPlugin.kt | 14 ++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt index 6cddba35..9c53196e 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt @@ -4,8 +4,15 @@ import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.archive.Zip import com.beust.kobalt.misc.IncludedFile +import com.beust.kobalt.misc.KFiles +import java.io.File interface ArchiveFileFinder { fun findIncludedFiles(project: Project, context: KobaltContext, zip: Zip) : List + fun fullArchiveName(project: Project, context: KobaltContext, archiveName: String?, suffix: String) : File { + val fullArchiveName = context.variant.archiveName(project, archiveName, suffix) + val archiveDir = File(KFiles.libsDir(project)) + val result = File(archiveDir.path, fullArchiveName) + return result + } } - 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 ba04971e..a52bc732 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -70,16 +70,21 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana * skipped. */ override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { - val allArchivers = packages.filter { it.project.name == project.name } + val allConfigs = packages.filter { it.project.name == project.name } if (false) { // Work in progress val allIncludedFiles = arrayListOf() val zipToFiles = hashMapOf>() - allArchivers.forEach { packageConfig -> + val outputArchives = arrayListOf() + allConfigs.forEach { packageConfig -> listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> archives.forEach { val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) + val suffixIndex = it.name.lastIndexOf(".") + val suffix = it.name.substring(suffixIndex) + val outputFile = jarGenerator.fullArchiveName(project, context, it.name, suffix) + outputArchives.add(outputFile) allIncludedFiles.addAll(files) zipToFiles[it.name] = files } @@ -95,7 +100,8 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } val md5 = Md5.toMd5Directories(allFiles) - println("MD5 is: " + md5) + val outMd5 = Md5.toMd5Directories(outputArchives) + println("Input MD5: $md5 output MD5: $outMd5") } return IncrementalTaskInfo( @@ -105,7 +111,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana try { project.projectProperties.put(Archives.JAR_NAME, context.variant.archiveName(project, null, ".jar")) - allArchivers.forEach { packageConfig -> + allConfigs.forEach { packageConfig -> packageConfig.jars.forEach { jarGenerator.generateJar(packageConfig.project, context, it) } packageConfig.wars.forEach { warGenerator.generateWar(packageConfig.project, context, it) } packageConfig.zips.forEach { zipGenerator.generateZip(packageConfig.project, context, it) } From 5000368d6489bac5a35248cbd54ed757d1b82ca1 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 14 Mar 2017 18:40:07 -0700 Subject: [PATCH 037/532] Log. --- .../src/main/kotlin/com/beust/kobalt/JarGenerator.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt index e2383e50..bbb1a093 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt @@ -43,7 +43,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) } } else { - kobaltLog(2, "Directory $fromPath doesn't exist, not including it in the jar") + kobaltLog(2, " Directory $fromPath doesn't exist, not including it in the jar") } } if (includedSpecs.size > 0) { @@ -97,8 +97,6 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) // If fatJar is true, add all the transitive dependencies as well: compile, runtime and dependent projects // if (jar.fatJar) { - context.logger.log(project.name, 2, "Finding included files for fat jar") - val seen = hashSetOf() @Suppress("UNCHECKED_CAST") val allDependencies = project.compileDependencies + project.compileRuntimeDependencies + From c974330612ebfb5cd363241341fb3a8c9beb8063 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 14 Mar 2017 18:40:18 -0700 Subject: [PATCH 038/532] Less verbose Md5. --- .../src/main/kotlin/com/beust/kobalt/maven/Md5.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt index bc5f2fef..efa34944 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt @@ -31,13 +31,13 @@ class Md5 { var fileCount = 0 filesOrDirectories.filter(File::exists).forEach { file -> if (file.isFile) { - kobaltLog(2, " Calculating checksum of $file") + kobaltLog(3, " Calculating checksum of $file") val bytes = toBytes(file) md5.update(bytes, 0, bytes.size) fileCount++ } else { val files = KFiles.findRecursively(file) // , { f -> f.endsWith("java")}) - kobaltLog(2, " Calculating checksum of ${files.size} files in $file") + kobaltLog(3, " Calculating checksum of ${files.size} files in $file") files.map { File(file, it) }.filter { From b2390f34f888d2ed59ec2de46b0f4490b4a0c6d6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 14 Mar 2017 18:40:28 -0700 Subject: [PATCH 039/532] Incremental packaging. --- .../plugin/packaging/PackagingPlugin.kt | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) 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 a52bc732..c3a38412 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -61,52 +61,52 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana runTask = { taskInstall(project) }) } - /** - * "assemble" is an incremental task but with a twist. Because it can be costly to determine if any - * of the class files generated in the previous phase is new or not, we just don't do that and always - * return "null" for both input and output checksums, which would cause that task to always be rerun. - * However, we are depending on Kobalt's cascading incremental management to skip us whenever appropriate: - * whenever a previous incremental task was a success, all following incremental tasks are automatically - * skipped. - */ override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { val allConfigs = packages.filter { it.project.name == project.name } - if (false) { - // Work in progress - val allIncludedFiles = arrayListOf() - val zipToFiles = hashMapOf>() - val outputArchives = arrayListOf() - allConfigs.forEach { packageConfig -> - listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> - archives.forEach { - val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) - val suffixIndex = it.name.lastIndexOf(".") - val suffix = it.name.substring(suffixIndex) - val outputFile = jarGenerator.fullArchiveName(project, context, it.name, suffix) - outputArchives.add(outputFile) - allIncludedFiles.addAll(files) - zipToFiles[it.name] = files + val start = System.currentTimeMillis() + val checksums = + if (true) { + val allIncludedFiles = arrayListOf() + val zipToFiles = hashMapOf>() + val outputArchives = arrayListOf() + allConfigs.forEach { packageConfig -> + listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> + archives.forEach { + val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) + val suffixIndex = it.name.lastIndexOf(".") + val suffix = it.name.substring(suffixIndex) + val outputFile = jarGenerator.fullArchiveName(project, context, it.name, suffix) + outputArchives.add(outputFile) + allIncludedFiles.addAll(files) + zipToFiles[it.name] = files + } } } - } - val allFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> - val foundFiles = includedFile.allFromFiles(project.directory) - val absFiles = foundFiles.map { - File(KFiles.joinDir(project.directory, includedFile.from, it.path)) + val allFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> + val foundFiles = includedFile.allFromFiles(project.directory) + val absFiles = foundFiles.map { + File(KFiles.joinDir(project.directory, includedFile.from, it.path)) + } + files.addAll(absFiles) + files } - files.addAll(absFiles) - files + + val inMd5 = Md5.toMd5Directories(allFiles) + val outMd5 = Md5.toMd5Directories(outputArchives) + Pair(inMd5, outMd5) + } else { + Pair(null, null) } - val md5 = Md5.toMd5Directories(allFiles) - val outMd5 = Md5.toMd5Directories(outputArchives) - println("Input MD5: $md5 output MD5: $outMd5") - } + val inMd5 = checksums.first + val outMd5 = checksums.second + context.logger.log(project.name, 2, + " Time to calculate packaging checksum: " + (System.currentTimeMillis() - start) + " ms") return IncrementalTaskInfo( - { null }, - { null }, + { -> inMd5 }, + { -> outMd5 }, { project -> try { project.projectProperties.put(Archives.JAR_NAME, From 3d689b3367df182d0dc37305ef1173548de1c947 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 14 Mar 2017 20:21:32 -0700 Subject: [PATCH 040/532] Better test failure message. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 9f82990d..bfcdf095 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -34,8 +34,15 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { } """ + args.noIncremental = true val projectResults = compileBuildFile(buildFileText, args) - return projectResults.projects.first { it.name == projectName } + val result = projectResults.projects.firstOrNull { it.name == projectName } + if (result == null) { + throw IllegalArgumentException("Couldn't find project named $projectName in " + + projectResults.projects.map { it.name }.joinToString(", ", "[", "]")) + } else { + return result + } } /** @@ -52,6 +59,8 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt") args.apply { buildFile = tmpBuildFile.absolutePath + noIncremental = true + noIncrementalKotlin = true } val jvmCompilerPlugin = Kobalt.findPlugin("JvmCompiler") as JvmCompilerPlugin val pluginInfo = PluginInfo(KobaltPluginXml(), null, null).apply { From 33f7d4bd9fff9eb05914c7a4bfa3caf6e2166c5d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 10:53:45 -0700 Subject: [PATCH 041/532] =?UTF-8?q?Don=E2=80=99t=20break=20incremental=20c?= =?UTF-8?q?ompilation=20in=20the=20build=20file.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kobalt/src/Build.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 99949300..168a9cea 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -238,9 +238,12 @@ fun taskCopyVersionForWrapper(project: Project) : TaskResult { File(toString).mkdirs() val from = Paths.get("src/main/resources/kobalt.properties") val to = Paths.get("$toString/kobalt.properties") - Files.copy(from, - to, - StandardCopyOption.REPLACE_EXISTING) + // Only copy if necessary so we don't break incremental compilation + if (from.toFile().readLines() != to.toFile().readLines()) { + Files.copy(from, + to, + StandardCopyOption.REPLACE_EXISTING) + } } return TaskResult() } From 72bcffab2c4282166d7fcabaffc2408eba963766 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 10:54:01 -0700 Subject: [PATCH 042/532] Move the file to the correct location. --- .../src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt | 2 +- .../src/main/kotlin/com/beust/kobalt/JarGenerator.kt | 1 - .../kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt | 1 + .../kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt index 9c53196e..92eae8ac 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt @@ -1,4 +1,4 @@ -package com.beust.kobalt.plugin.packaging +package com.beust.kobalt import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt index bbb1a093..0c6a97fd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt @@ -8,7 +8,6 @@ import com.beust.kobalt.archive.Zip import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.aether.Scope import com.beust.kobalt.misc.* -import com.beust.kobalt.plugin.packaging.ArchiveFileFinder import com.google.inject.Inject import java.io.File import java.io.FileInputStream diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt index 1bce23eb..d03588ca 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.plugin.packaging +import com.beust.kobalt.ArchiveFileFinder import com.beust.kobalt.IFileSpec import com.beust.kobalt.JarGenerator import com.beust.kobalt.api.IClasspathDependency diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt index 4427892b..af1edbc2 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.plugin.packaging +import com.beust.kobalt.ArchiveFileFinder import com.beust.kobalt.JarGenerator import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project From 908610ba3a5e8784c2abdc2a5bd597189fa02766 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 11:01:10 -0700 Subject: [PATCH 043/532] Refactor. --- .../beust/kobalt/plugin/packaging/PackagingPlugin.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 c3a38412..4a72131f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -16,6 +16,7 @@ import com.beust.kobalt.maven.PomGenerator import com.beust.kobalt.misc.IncludedFile import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors +import com.beust.kobalt.misc.benchmarkMillis import java.io.File import javax.inject.Inject import javax.inject.Singleton @@ -64,8 +65,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { val allConfigs = packages.filter { it.project.name == project.name } - val start = System.currentTimeMillis() - val checksums = + val benchmark = benchmarkMillis { if (true) { val allIncludedFiles = arrayListOf() val zipToFiles = hashMapOf>() @@ -98,11 +98,11 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } else { Pair(null, null) } + } - val inMd5 = checksums.first - val outMd5 = checksums.second - context.logger.log(project.name, 2, - " Time to calculate packaging checksum: " + (System.currentTimeMillis() - start) + " ms") + context.logger.log(project.name, 2, " Time to calculate packaging checksum: ${benchmark.first} ms") + + val (inMd5, outMd5) = benchmark.second return IncrementalTaskInfo( { -> inMd5 }, From d01af588cd6ebfcef48a5be1d749acc0f0a1ae31 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 11:03:25 -0700 Subject: [PATCH 044/532] Logging. --- .../src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 afaa7e21..7fda0eac 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 @@ -67,7 +67,7 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger { } private fun debug(s: CharSequence) { - if (args.log >= 2) { + if (args.log >= 3) { val time = System.currentTimeMillis() - startTime!! println(" ### [$time] $s") } From ca27a131ca3158b44d69f68557070f8558522621 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 11:38:41 -0700 Subject: [PATCH 045/532] Build file fix. --- kobalt/src/Build.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 168a9cea..ad08b98d 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -239,7 +239,7 @@ fun taskCopyVersionForWrapper(project: Project) : TaskResult { val from = Paths.get("src/main/resources/kobalt.properties") val to = Paths.get("$toString/kobalt.properties") // Only copy if necessary so we don't break incremental compilation - if (from.toFile().readLines() != to.toFile().readLines()) { + if (! to.toFile().exists() || (from.toFile().readLines() != to.toFile().readLines())) { Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING) From ac96f92b29d8fe13c37c07cdc60569b2cdf8c06f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 12:20:31 -0700 Subject: [PATCH 046/532] Use relative path for preBuildScript.jar. --- .../src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 22f5432f..31655ab0 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -259,7 +259,7 @@ class KFiles { * The build location for build scripts is .kobalt/build */ fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String { - val result = joinDir(buildFile.dotKobaltDir.absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile) + val result = joinDir(buildFile.dotKobaltDir.path, KFiles.SCRIPT_BUILD_DIR, jarFile) kobaltLog(2, "Script jar file: $result") return result } From bbadd4904dda4f250c5912542ad1ded109d88f06 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 12:20:36 -0700 Subject: [PATCH 047/532] Not needed. --- src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt index 00d71d5f..a772e428 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt @@ -6,7 +6,6 @@ import com.beust.kobalt.api.Kobalt import com.beust.kobalt.app.BuildFileCompiler import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.aether.Scope -import com.beust.kobalt.misc.KobaltLogger import com.google.inject.Inject import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.DataProvider @@ -21,12 +20,12 @@ class ExcludeTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor @DataProvider fun dp() = arrayOf>( - arrayOf("p1", null), - arrayOf("p2", EXCLUDED_DEPENDENCY) + arrayOf(null), + arrayOf(EXCLUDED_DEPENDENCY) ) @Test(dataProvider = "dp") - fun excludeShouldWork(projectName: String, excludedDependency: String?) { + fun excludeShouldWork(excludedDependency: String?) { val projectText = """ dependencies { compile("org.apache.maven:maven-model:jar:3.3.9") From 7b28290b8b785376afb43f11eb3f2de0329b1bde Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 13:02:37 -0700 Subject: [PATCH 048/532] More refactoring. --- ...chiveFileFinder.kt => ArchiveGenerator.kt} | 8 +++-- .../kotlin/com/beust/kobalt/JarGenerator.kt | 30 +++++++++---------- .../kotlin/com/beust/kobalt/archive/Jar.kt | 2 +- .../kotlin/com/beust/kobalt/archive/Zip.kt | 9 +++++- .../plugin/packaging/PackagingPlugin.kt | 28 +++++++++++++---- .../kobalt/plugin/packaging/WarGenerator.kt | 13 ++++---- .../kobalt/plugin/packaging/ZipGenerator.kt | 13 ++++---- 7 files changed, 67 insertions(+), 36 deletions(-) rename modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/{ArchiveFileFinder.kt => ArchiveGenerator.kt} (76%) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveGenerator.kt similarity index 76% rename from modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveGenerator.kt index 92eae8ac..dc3fda2d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveFileFinder.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ArchiveGenerator.kt @@ -7,12 +7,16 @@ import com.beust.kobalt.misc.IncludedFile import com.beust.kobalt.misc.KFiles import java.io.File -interface ArchiveFileFinder { +interface ArchiveGenerator { fun findIncludedFiles(project: Project, context: KobaltContext, zip: Zip) : List - fun fullArchiveName(project: Project, context: KobaltContext, archiveName: String?, suffix: String) : File { + val suffix: String + fun generateArchive(project: Project, context: KobaltContext, zip: Zip, files: List) : File + + fun fullArchiveName(project: Project, context: KobaltContext, archiveName: String?) : File { val fullArchiveName = context.variant.archiveName(project, archiveName, suffix) val archiveDir = File(KFiles.libsDir(project)) val result = File(archiveDir.path, fullArchiveName) return result } + } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt index 0c6a97fd..ddddaebd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt @@ -3,7 +3,6 @@ package com.beust.kobalt import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.archive.Archives -import com.beust.kobalt.archive.Jar import com.beust.kobalt.archive.Zip import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.aether.Scope @@ -16,7 +15,7 @@ import java.nio.file.Paths import java.util.jar.JarOutputStream import java.util.jar.Manifest -class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) : ArchiveFileFinder { +class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) : ArchiveGenerator { companion object { fun findIncludedFiles(directory: String, files: List, excludes: List, throwOnError: Boolean = true) @@ -54,7 +53,9 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) } } - override fun findIncludedFiles(project: Project, context: KobaltContext, jar: Zip) : List { + override val suffix = ".jar" + + override fun findIncludedFiles(project: Project, context: KobaltContext, zip: Zip) : List { // // Add all the applicable files for the current project // @@ -62,7 +63,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) val result = arrayListOf() val classesDir = KFiles.makeDir(buildDir.path, "classes") - if (jar.includedFiles.isEmpty()) { + if (zip.includedFiles.isEmpty()) { // If no includes were specified, assume the user wants a simple jar file made of the // classes of the project, so we specify a From("build/classes/"), To("") and // a list of files containing everything under it @@ -72,7 +73,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) // Class files val files = KFiles.findRecursively(classesDir).map { File(relClassesDir.toFile(), it) } val filesNotExcluded : List = files.filter { - ! KFiles.Companion.isExcluded(KFiles.joinDir(project.directory, it.path), jar.excludes) + ! KFiles.Companion.isExcluded(KFiles.joinDir(project.directory, it.path), zip.excludes) } val fileSpecs = arrayListOf() filesNotExcluded.forEach { @@ -88,14 +89,14 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) // // The user specified an include, just use it verbatim // - val includedFiles = findIncludedFiles(project.directory, jar.includedFiles, jar.excludes, false) + val includedFiles = findIncludedFiles(project.directory, zip.includedFiles, zip.excludes, false) result.addAll(includedFiles) } // // If fatJar is true, add all the transitive dependencies as well: compile, runtime and dependent projects // - if (jar.fatJar) { + if (zip.fatJar) { val seen = hashSetOf() @Suppress("UNCHECKED_CAST") val allDependencies = project.compileDependencies + project.compileRuntimeDependencies + @@ -110,7 +111,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) }.forEach { file : File -> if (! seen.contains(file.path)) { seen.add(file.path) - if (! KFiles.Companion.isExcluded(file, jar.excludes)) { + if (! KFiles.Companion.isExcluded(file, zip.excludes)) { result.add(IncludedFile(specs = arrayListOf(IFileSpec.FileSpec(file.absolutePath)), expandJarFiles = true)) } @@ -121,19 +122,18 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) return result } - fun generateJar(project: Project, context: KobaltContext, jar: Jar) : File { - val includedFiles = findIncludedFiles(project, context, jar) - + override fun generateArchive(project: Project, context: KobaltContext, zip: Zip, + includedFiles: List) : File { // // Generate the manifest // If manifest attributes were specified in the build file, use those to generateAndSave the manifest. Otherwise, // try to find a META-INF/MANIFEST.MF and use that one if we find any. Otherwise, use the default manifest. // val manifest = - if (jar.attributes.size > 1) { - context.logger.log(project.name, 2, "Creating MANIFEST.MF from " + jar.attributes.size + " attributes") + if (zip.attributes.size > 1) { + context.logger.log(project.name, 2, "Creating MANIFEST.MF from " + zip.attributes.size + " attributes") Manifest().apply { - jar.attributes.forEach { attribute -> + zip.attributes.forEach { attribute -> mainAttributes.putValue(attribute.first, attribute.second) } } @@ -157,7 +157,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) } - return Archives.generateArchive(project, context, jar.name, ".jar", includedFiles, + return Archives.generateArchive(project, context, zip.name, ".jar", includedFiles, true /* expandJarFiles */, jarFactory) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt index 80a7bd1a..d5086cbd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Jar.kt @@ -18,7 +18,7 @@ open class Jar(override val project: Project, // Need to specify the version or attributes will just be dropped @Directive - val attributes = arrayListOf(Pair("Manifest-Version", "1.0")) + override val attributes = arrayListOf(Pair("Manifest-Version", "1.0")) override fun addAttribute(k: String, v: String) { attributes.add(Pair(k, v)) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt index 22b5809d..296eb784 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Zip.kt @@ -9,7 +9,7 @@ import com.beust.kobalt.misc.IncludedFile import com.beust.kobalt.misc.To open class Zip(open val project: Project, open var name: String = Archives.defaultArchiveName(project) + ".zip", - open var fatJar: Boolean = false) { + open var fatJar: Boolean = false): AttributeHolder { val excludes = arrayListOf() @Directive @@ -49,6 +49,13 @@ open class Zip(open val project: Project, open var name: String = Archives.defau */ val includedFiles = arrayListOf() + @Directive + open val attributes = arrayListOf(Pair("Manifest-Version", "1.0")) + + override fun addAttribute(k: String, v: String) { + attributes.add(Pair(k, v)) + } + } 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 4a72131f..ea541efa 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -62,13 +62,14 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana runTask = { taskInstall(project) }) } + val zipToFiles = hashMapOf>() + override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { val allConfigs = packages.filter { it.project.name == project.name } val benchmark = benchmarkMillis { if (true) { val allIncludedFiles = arrayListOf() - val zipToFiles = hashMapOf>() val outputArchives = arrayListOf() allConfigs.forEach { packageConfig -> listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> @@ -76,7 +77,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) val suffixIndex = it.name.lastIndexOf(".") val suffix = it.name.substring(suffixIndex) - val outputFile = jarGenerator.fullArchiveName(project, context, it.name, suffix) + val outputFile = jarGenerator.fullArchiveName(project, context, it.name) outputArchives.add(outputFile) allIncludedFiles.addAll(files) zipToFiles[it.name] = files @@ -111,10 +112,27 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana try { project.projectProperties.put(Archives.JAR_NAME, context.variant.archiveName(project, null, ".jar")) + + fun findFiles(ff: ArchiveGenerator, zip: Zip) : List { + val archiveName = ff.fullArchiveName(project, context, zip.name).name + return zipToFiles[archiveName]!! + } + allConfigs.forEach { packageConfig -> - packageConfig.jars.forEach { jarGenerator.generateJar(packageConfig.project, context, it) } - packageConfig.wars.forEach { warGenerator.generateWar(packageConfig.project, context, it) } - packageConfig.zips.forEach { zipGenerator.generateZip(packageConfig.project, context, it) } + val pairs = listOf( + Pair(packageConfig.jars, jarGenerator), + Pair(packageConfig.wars, warGenerator), + Pair(packageConfig.zips, zipGenerator) + ) + + pairs.forEach { pair -> + val zips = pair.first + val generator = pair.second + zips.forEach { + generator.generateArchive(packageConfig.project, context, it, + findFiles(generator, it)) + } + } if (packageConfig.generatePom) { pomFactory.create(project).generateAndSave() } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt index d03588ca..295224c7 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt @@ -1,13 +1,12 @@ package com.beust.kobalt.plugin.packaging -import com.beust.kobalt.ArchiveFileFinder +import com.beust.kobalt.ArchiveGenerator import com.beust.kobalt.IFileSpec import com.beust.kobalt.JarGenerator import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.archive.Archives -import com.beust.kobalt.archive.War import com.beust.kobalt.archive.Zip import com.beust.kobalt.internal.ParallelLogger import com.beust.kobalt.maven.DependencyManager @@ -22,7 +21,7 @@ import java.nio.file.Paths import java.util.jar.JarOutputStream class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) - : ArchiveFileFinder { + : ArchiveGenerator { companion object { val WEB_INF = "WEB-INF" @@ -30,6 +29,8 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val LIB = "$WEB_INF/lib" } + override val suffix = ".war" + override fun findIncludedFiles(project: Project, context: KobaltContext, war: Zip) : List { // // src/main/web app and classes @@ -82,16 +83,16 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, return result } - fun generateWar(project: Project, context: KobaltContext, war: War) : File { + override fun generateArchive(project: Project, context: KobaltContext, war: Zip, + files: List) : File { val manifest = java.util.jar.Manifest()//FileInputStream(mf)) war.attributes.forEach { attribute -> manifest.mainAttributes.putValue(attribute.first, attribute.second) } - val allFiles = findIncludedFiles(project, context, war) val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) } - return Archives.generateArchive(project, context, war.name, ".war", allFiles, + return Archives.generateArchive(project, context, war.name, ".war", files, false /* don't expand jar files */, jarFactory) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt index af1edbc2..e15c61ae 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/ZipGenerator.kt @@ -1,6 +1,6 @@ package com.beust.kobalt.plugin.packaging -import com.beust.kobalt.ArchiveFileFinder +import com.beust.kobalt.ArchiveGenerator import com.beust.kobalt.JarGenerator import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project @@ -12,13 +12,14 @@ import com.beust.kobalt.misc.IncludedFile import com.google.inject.Inject class ZipGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger) - : ArchiveFileFinder { + : ArchiveGenerator { + + override val suffix = ".zip" + override fun findIncludedFiles(project: Project, context: KobaltContext, zip: Zip): List { return JarGenerator.findIncludedFiles(project.directory, zip.includedFiles, zip.excludes) } - fun generateZip(project: Project, context: KobaltContext, zip: Zip) { - val allFiles = findIncludedFiles(project, context, zip) - Archives.generateArchive(project, context, zip.name, ".zip", allFiles) - } + override fun generateArchive(project: Project, context: KobaltContext, zip: Zip, files: List) + = Archives.generateArchive(project, context, zip.name, ".zip", files) } From 9c6a68e47547e6a163f5d26675570b471f3361bb Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 13:23:04 -0700 Subject: [PATCH 049/532] Debug TeamCity failures. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index bfcdf095..fa7c4016 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -7,6 +7,7 @@ import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.KobaltPluginXml import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile +import com.beust.kobalt.misc.KobaltLogger import org.testng.annotations.BeforeClass import java.nio.file.Files import java.nio.file.Paths @@ -51,6 +52,7 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { * interfering with other tests. */ fun compileBuildFile(buildFileText: String, args: Args = Args()): BuildFileCompiler.FindProjectResult { + KobaltLogger.LOG_LEVEL = 3 val tmpBaseDir = Files.createTempDirectory("kobaltTest") val tmpBuildFile = Files.createTempFile(tmpBaseDir, "kobaltTest", "").toFile().apply { deleteOnExit() From bd861a9198d3afe1be8a495f12401605b72ba0ea Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 13:35:54 -0700 Subject: [PATCH 050/532] 1.0.12. --- 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 297298a1..26487e73 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.11 +kobalt.version=1.0.12 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 297298a1..067473ac 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.11 +kobalt.version=1.0.12 From c16aa0aa67e5fbc333379298574b86026ca5f558 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 14:14:27 -0700 Subject: [PATCH 051/532] Attempt to fix the tests for TeamCity. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 15 ++++++++++----- .../com/beust/kobalt/internal/ProfileTest.kt | 7 +++++-- .../beust/kobalt/maven/DependencyManagerTest.kt | 5 ++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index fa7c4016..763404f7 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -9,6 +9,7 @@ import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.misc.KobaltLogger import org.testng.annotations.BeforeClass +import java.io.File import java.nio.file.Files import java.nio.file.Paths import java.util.* @@ -26,17 +27,20 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { */ fun compileSingleProject(projectText: String, args: Args = Args()) : Project { val projectName = "p" + Math.abs(Random().nextInt()) + val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path + val buildFileText= """ import com.beust.kobalt.* import com.beust.kobalt.api.* val $projectName = project { name = "$projectName" + directory = "$projectDirectory" $projectText } - """ + """.trim() args.noIncremental = true - val projectResults = compileBuildFile(buildFileText, args) + val projectResults = compileBuildFile(projectDirectory, buildFileText, args) val result = projectResults.projects.firstOrNull { it.name == projectName } if (result == null) { throw IllegalArgumentException("Couldn't find project named $projectName in " @@ -51,10 +55,11 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { * should preferably use random names for the projects defined in their build file to avoid * interfering with other tests. */ - fun compileBuildFile(buildFileText: String, args: Args = Args()): BuildFileCompiler.FindProjectResult { + fun compileBuildFile(projectDirectory: String, buildFileText: String, args: Args = Args()) + : BuildFileCompiler .FindProjectResult { KobaltLogger.LOG_LEVEL = 3 - val tmpBaseDir = Files.createTempDirectory("kobaltTest") - val tmpBuildFile = Files.createTempFile(tmpBaseDir, "kobaltTest", "").toFile().apply { + val path = Paths.get(projectDirectory) + val tmpBuildFile = File(path.toFile(), "Build.kt").apply { deleteOnExit() writeText(buildFileText) } diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index 2ae08f54..fe12191d 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -11,6 +11,7 @@ import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.DataProvider import org.testng.annotations.Guice import org.testng.annotations.Test +import java.nio.file.Files import java.util.* @Guice(modules = arrayOf(TestModule::class)) @@ -18,6 +19,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor private fun runTestWithProfile(enabled: Boolean) : Project { val projectVal = "p" + Math.abs(Random().nextInt()) + val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path fun buildFileString(): String { return """ @@ -26,13 +28,14 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor val profile = false val $projectVal = project { name = if (profile) "profileOn" else "profileOff" + directory = "$projectDirectory" } - """ + """.trim() } val args = Args() if (enabled) args.profiles = "profile" - val results = compileBuildFile(buildFileString(), args) + val results = compileBuildFile(projectDirectory, buildFileString(), args) return results.projects[0] } diff --git a/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt index 9a45939b..77cf8953 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt @@ -13,6 +13,7 @@ import org.assertj.core.api.Assertions.assertThat import org.eclipse.aether.util.filter.AndDependencyFilter import org.testng.annotations.Guice import org.testng.annotations.Test +import java.nio.file.Files @Guice(modules = arrayOf(TestModule::class)) class DependencyManagerTest @Inject constructor(val dependencyManager: DependencyManager, @@ -106,11 +107,13 @@ class DependencyManagerTest @Inject constructor(val dependencyManager: Dependenc } private fun findDependentProject(): Project { + val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path val sharedBuildFile = """ import com.beust.kobalt.* val lib2 = project { name = "lib2" + directory = "$projectDirectory" dependencies { // pick dependencies that don't have dependencies themselves, to avoid interferences compile("com.beust:klaxon:0.27", @@ -125,7 +128,7 @@ class DependencyManagerTest @Inject constructor(val dependencyManager: Dependenc } """ Kobalt.context = null - return compileBuildFile(sharedBuildFile).projects.first { it.name == "transitive2" } + return compileBuildFile(projectDirectory, sharedBuildFile).projects.first { it.name == "transitive2" } } } From 87ff2b34cf941a9c95b1757f6dedfa9d115afc87 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 14:30:26 -0700 Subject: [PATCH 052/532] More test fixing. --- .../src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 31655ab0..83f6cc32 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -260,6 +260,7 @@ class KFiles { */ fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String { val result = joinDir(buildFile.dotKobaltDir.path, KFiles.SCRIPT_BUILD_DIR, jarFile) + kobaltLog(2, "Build file dotKobaltDir: " + buildFile.dotKobaltDir) kobaltLog(2, "Script jar file: $result") return result } From a91bd04e41549959c901dda053e2b751fca84476 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 14:38:11 -0700 Subject: [PATCH 053/532] Test fix. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 763404f7..cecabeba 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -8,6 +8,7 @@ import com.beust.kobalt.internal.KobaltPluginXml import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.misc.KobaltLogger +import com.beust.kobalt.misc.log import org.testng.annotations.BeforeClass import java.io.File import java.nio.file.Files @@ -58,14 +59,24 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { fun compileBuildFile(projectDirectory: String, buildFileText: String, args: Args = Args()) : BuildFileCompiler .FindProjectResult { KobaltLogger.LOG_LEVEL = 3 - val path = Paths.get(projectDirectory) - val tmpBuildFile = File(path.toFile(), "Build.kt").apply { + val actualBuildFilePath = Paths.get(projectDirectory, "kobalt", "src") + val actualBuildFile = File(actualBuildFilePath.toFile(), "Build.kt").apply { + File(parent).mkdirs() deleteOnExit() writeText(buildFileText) } - val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt") + val tmpBuildFilePath = Paths.get(Files.createTempDirectory("").toFile().absolutePath, "kobalt", "src") + val tmpBuildFile = File(tmpBuildFilePath.toFile(), "Build.kt").apply { + File(parent).mkdirs() + deleteOnExit() + writeText(buildFileText) + } + + val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt", + Paths.get(actualBuildFile.absolutePath)) + Kobalt.context?.log(2, "About to compile build file $thisBuildFile .kobaltDir: " + thisBuildFile.dotKobaltDir) args.apply { - buildFile = tmpBuildFile.absolutePath + buildFile = actualBuildFile.absolutePath noIncremental = true noIncrementalKotlin = true } From 1c10965e771ccce2e651c3ad12b9d315164ee4b4 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 14:45:34 -0700 Subject: [PATCH 054/532] Problem solved, removing the logs. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index cecabeba..2fbcbbe5 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -7,7 +7,6 @@ import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.KobaltPluginXml import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile -import com.beust.kobalt.misc.KobaltLogger import com.beust.kobalt.misc.log import org.testng.annotations.BeforeClass import java.io.File @@ -58,7 +57,6 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { */ fun compileBuildFile(projectDirectory: String, buildFileText: String, args: Args = Args()) : BuildFileCompiler .FindProjectResult { - KobaltLogger.LOG_LEVEL = 3 val actualBuildFilePath = Paths.get(projectDirectory, "kobalt", "src") val actualBuildFile = File(actualBuildFilePath.toFile(), "Build.kt").apply { File(parent).mkdirs() @@ -74,7 +72,9 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt", Paths.get(actualBuildFile.absolutePath)) - Kobalt.context?.log(2, "About to compile build file $thisBuildFile .kobaltDir: " + thisBuildFile.dotKobaltDir) + Kobalt.context?.log(2, "About to compile build file " + + thisBuildFile.path + " " + thisBuildFile.realPath + + ".kobaltDir: " + thisBuildFile.dotKobaltDir) args.apply { buildFile = actualBuildFile.absolutePath noIncremental = true From 2e603b050408d1e138c34662c4387720f9e8028f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 14:49:58 -0700 Subject: [PATCH 055/532] Refactoring. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 2fbcbbe5..7da65d26 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -57,19 +57,19 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { */ fun compileBuildFile(projectDirectory: String, buildFileText: String, args: Args = Args()) : BuildFileCompiler .FindProjectResult { - val actualBuildFilePath = Paths.get(projectDirectory, "kobalt", "src") - val actualBuildFile = File(actualBuildFilePath.toFile(), "Build.kt").apply { - File(parent).mkdirs() - deleteOnExit() - writeText(buildFileText) - } - val tmpBuildFilePath = Paths.get(Files.createTempDirectory("").toFile().absolutePath, "kobalt", "src") - val tmpBuildFile = File(tmpBuildFilePath.toFile(), "Build.kt").apply { - File(parent).mkdirs() - deleteOnExit() - writeText(buildFileText) + + fun createBuildFile(projectDirectory: String) : File { + val path = Paths.get(projectDirectory, "kobalt", "src") + return File(path.toFile(), "Build.kt").apply { + File(parent).mkdirs() + deleteOnExit() + writeText(buildFileText) + } } + val actualBuildFile = createBuildFile(projectDirectory) + val tmpBuildFile = createBuildFile(Files.createTempDirectory("").toFile().absolutePath) + val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt", Paths.get(actualBuildFile.absolutePath)) Kobalt.context?.log(2, "About to compile build file " From 1a01d7c8d8303df29bb3f081c911556264337cf6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 15:08:40 -0700 Subject: [PATCH 056/532] Testing TeamCity build status publisher. --- src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index fe12191d..a9ebb362 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -52,3 +52,4 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor } + From e30e188368c49b186ec00652001d9833fe3cba50 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 15:19:20 -0700 Subject: [PATCH 057/532] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d2a79419..c7d9c3b7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Kobalt + + Kobalt is a universal build system. To build it: From 71b7c6d58c1f8ba7a4533308cd828d9ca7511a34 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 09:23:50 -0700 Subject: [PATCH 058/532] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7d9c3b7..81d87855 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Kobalt - +[](https://teamcity.jetbrains.com/project.html?projectId=OpenSourceProjects_Kobalt&tab=projectOverview) + Kobalt is a universal build system. From 3f1155a280bd2d71a602fdbcf53c4ada8bdfa4f6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 10:01:49 -0700 Subject: [PATCH 059/532] Better warning. --- .../main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt index 7882cfd0..fa48427e 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt @@ -58,10 +58,12 @@ class CompilerDescription(override val name: String, override val sourceDirecto if (info.sourceFiles.isNotEmpty()) { compiler.compile(project, context, info) } else { - warn("Couldn't find any source files to compile") + warn("$name cdouldn't find any source files to compile") TaskResult() } return result } + + override fun toString() = name + " compiler" } From 66b39aa21357b596aa890127345c3df4023e6df7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 14:20:30 -0700 Subject: [PATCH 060/532] Log exclusions. --- .../kotlin/com/beust/kobalt/maven/DependencyManager.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 6913c8ed..9ff45407 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -139,8 +139,14 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, * Should probably make exclusion more generic (full on string) or allow exclusion to be specified * formally by groupId or artifactId. */ - fun isDependencyExcluded(dep: IClasspathDependency, excluded: List) - = excluded.any { excluded -> dep.id.startsWith(excluded.id) } + fun isDependencyExcluded(dep: IClasspathDependency, excluded: List): Boolean { + excluded.any { excluded -> dep.id.startsWith(excluded.id) }.let { result -> + if (result) { + context.logger.log(project?.name ?: "", 2, " Excluding dependency $dep") + } + return result + } + } // Dependencies get reordered by transitiveClosure() but since we just added a bunch of new ones, // we need to reorder them again in case we're adding dependencies that are already present From c2c4d8e254d0b951a101e7cdb1eaa86c5c66bd48 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 14:44:12 -0700 Subject: [PATCH 061/532] Clarify and document. --- .../plugin/packaging/PackagingPlugin.kt | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) 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 ea541efa..2e81d778 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -62,21 +62,28 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana runTask = { taskInstall(project) }) } - val zipToFiles = hashMapOf>() - override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { val allConfigs = packages.filter { it.project.name == project.name } + val zipToFiles = hashMapOf>() val benchmark = benchmarkMillis { if (true) { + // + // This loop prepares the data so we can calculate input and output checksums for the + // assemble task: + // - Input: Calculate the list of all the included files for every archive (jar/war/zip) and + // store them in the `zipToFiles` map. + // - Output: Calculate all the output archive files into `allFiles` + // + // `zipToFiles` is used again so we can pass that list of included files to the actual execution + // of the task, so we don't have to look for them a second time + // val allIncludedFiles = arrayListOf() val outputArchives = arrayListOf() allConfigs.forEach { packageConfig -> listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> archives.forEach { val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) - val suffixIndex = it.name.lastIndexOf(".") - val suffix = it.name.substring(suffixIndex) val outputFile = jarGenerator.fullArchiveName(project, context, it.name) outputArchives.add(outputFile) allIncludedFiles.addAll(files) @@ -84,7 +91,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } } } - val allFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> + val inputFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> val foundFiles = includedFile.allFromFiles(project.directory) val absFiles = foundFiles.map { File(KFiles.joinDir(project.directory, includedFile.from, it.path)) @@ -93,7 +100,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana files } - val inMd5 = Md5.toMd5Directories(allFiles) + val inMd5 = Md5.toMd5Directories(inputFiles) val outMd5 = Md5.toMd5Directories(outputArchives) Pair(inMd5, outMd5) } else { @@ -150,7 +157,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana context.pluginInfo.incrementalAssemblyContributors.forEach { val taskInfo = it.assemble(project, context) val closure = incrementalManagerFactory.create().toIncrementalTaskClosure(TASK_ASSEMBLE, { - p: Project -> taskInfo }, context.variant) + _: Project -> taskInfo }, context.variant) val thisResult = closure.invoke(project) if (! thisResult.success) { // Abort at the first failure @@ -174,24 +181,24 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } // @Task(name = "generateOsgiManifest", alwaysRunAfter = arrayOf(TASK_ASSEMBLE)) - fun generateManifest(project: Project): TaskResult { - val analyzer = Analyzer().apply { - jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String) - val dependencies = project.compileDependencies + project.compileRuntimeDependencies - dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach { - addClasspath(it.jarFile.get()) - } - setProperty(Analyzer.BUNDLE_VERSION, project.version) - setProperty(Analyzer.BUNDLE_NAME, project.group) - setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description) - setProperty(Analyzer.IMPORT_PACKAGE, "*") - setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version) - } - - val manifest = analyzer.calcManifest() - manifest.write(System.out) - return TaskResult() - } +// fun generateManifest(project: Project): TaskResult { +// val analyzer = Analyzer().apply { +// jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String) +// val dependencies = project.compileDependencies + project.compileRuntimeDependencies +// dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach { +// addClasspath(it.jarFile.get()) +// } +// setProperty(Analyzer.BUNDLE_VERSION, project.version) +// setProperty(Analyzer.BUNDLE_NAME, project.group) +// setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description) +// setProperty(Analyzer.IMPORT_PACKAGE, "*") +// setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version) +// } +// +// val manifest = analyzer.calcManifest() +// manifest.write(System.out) +// return TaskResult() +// } @Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts", From 8d06df9b8c58544390eb3cd1494b0c9e17e4cf2e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 15:21:51 -0700 Subject: [PATCH 062/532] Comments. --- .../kobalt/plugin/packaging/PackagingPlugin.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 2e81d778..0ac6fe18 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -1,6 +1,5 @@ package com.beust.kobalt.plugin.packaging -import aQute.bnd.osgi.Analyzer import com.beust.kobalt.* import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive @@ -73,24 +72,27 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana // assemble task: // - Input: Calculate the list of all the included files for every archive (jar/war/zip) and // store them in the `zipToFiles` map. - // - Output: Calculate all the output archive files into `allFiles` + // - Output: Calculate all the output archive files into `outputFiles` // - // `zipToFiles` is used again so we can pass that list of included files to the actual execution - // of the task, so we don't have to look for them a second time + // `zipToFiles` is used again after this loop so we can pass the list of included files we just + // calculated for all the archives in the actual execution of the task, so we don't have to + // look for them a second time. // val allIncludedFiles = arrayListOf() - val outputArchives = arrayListOf() + val outputFiles = arrayListOf() allConfigs.forEach { packageConfig -> listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> archives.forEach { val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) val outputFile = jarGenerator.fullArchiveName(project, context, it.name) - outputArchives.add(outputFile) + outputFiles.add(outputFile) allIncludedFiles.addAll(files) zipToFiles[it.name] = files } } } + + // Turn the IncludedFiles into actual Files val inputFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> val foundFiles = includedFile.allFromFiles(project.directory) val absFiles = foundFiles.map { @@ -101,7 +103,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } val inMd5 = Md5.toMd5Directories(inputFiles) - val outMd5 = Md5.toMd5Directories(outputArchives) + val outMd5 = Md5.toMd5Directories(outputFiles) Pair(inMd5, outMd5) } else { Pair(null, null) From 778db322a5978c78e670a2ab667a34bd3edb5edb Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 15:27:53 -0700 Subject: [PATCH 063/532] Kotlin 1.1.1. --- kobalt/src/Build.kt | 2 +- .../src/main/kotlin/com/beust/kobalt/Constants.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index ad08b98d..865a6d26 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -27,7 +27,7 @@ object Versions { val maven = "3.3.9" val mavenResolver = "1.0.3" val slf4j = "1.7.3" - val kotlin = "1.1.0" + val kotlin = "1.1.1" val aether = "1.0.2.v20150114" } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt index f6a8ea98..6305f1b1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt @@ -8,7 +8,7 @@ object Constants { val BUILD_FILE_NAME = "Build.kt" val BUILD_FILE_DIRECTORY = "kobalt/src" val BUILD_FILE_PATH = KFiles.joinDir(BUILD_FILE_DIRECTORY, BUILD_FILE_NAME) - val KOTLIN_COMPILER_VERSION = "1.1.0" + val KOTLIN_COMPILER_VERSION = "1.1.1" internal val DEFAULT_REPOS = listOf( // "https://maven-central.storage.googleapis.com/", From 99c447805e9d69f1ae2350dc5ebdc9e8540486b8 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 15:28:01 -0700 Subject: [PATCH 064/532] 1.0.13. --- 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 26487e73..20728f85 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.12 \ No newline at end of file +kobalt.version=1.0.13 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 067473ac..701a3432 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.12 +kobalt.version=1.0.13 From 4f32f0ba2f94c3c4d3a0a8ece3d531d599c95296 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 9 Mar 2017 15:10:18 -0800 Subject: [PATCH 065/532] Added parameters to autoGitTag directive. --- .../src/main/kotlin/com/beust/kobalt/misc/Git.kt | 13 +++++++------ .../beust/kobalt/plugin/publish/PublishPlugin.kt | 14 ++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt index 518250a5..e8fec4fa 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt @@ -6,10 +6,10 @@ import com.google.inject.Inject import java.io.File class Git @Inject constructor() { - fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Boolean) : TaskResult { + fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Triple) : TaskResult { val result = - if (uploadResult.success && autoGitTag) { - val tagSuccess = tagRelease(project) + if (uploadResult.success && autoGitTag.first) { + val tagSuccess = tagRelease(project, autoGitTag) if (! tagSuccess) { TaskResult(false, "Couldn't tag the project") } else { @@ -21,16 +21,17 @@ class Git @Inject constructor() { return result } - private fun tagRelease(project: Project) : Boolean { + private fun tagRelease(project: Project, autoGitTag: Triple) : Boolean { val success = try { - log(2, "Tagging this release as \"${project.version}\"") + val version = if (autoGitTag.second.isNullOrBlank()) project.version else autoGitTag.second + log(2, "Tagging this release as \"$version\"") val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder() .setGitDir(File(KFiles.joinDir(project.directory, ".git"))) .readEnvironment() .findGitDir() .build() val git = org.eclipse.jgit.api.Git(repo) - val ref = git.tag().setName(project.version).call() + val ref = git.tag().setName(version).setMessage(autoGitTag.third).call() git.push().setPushTags().call() true } catch(ex: Exception) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 56883401..78753ccc 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -191,13 +191,16 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener data class GithubConfig(val project: Project) { val files = arrayListOf() + var autoGitTag = Triple(true, project.version!!, "") /** * If true, automatically tag this release with the current version number and push that tag to origin when * the uploadGithub task is called. */ @Directive - var autoGitTag: Boolean = false + fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) { + autoGitTag = Triple(auto, tag, message) + } @Directive fun file(filePath: String, url: String) { @@ -213,6 +216,9 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig = } data class BintrayConfig(val project: Project) { + val files = arrayListOf>() + var autoGitTag = Triple(true, project.version!!, "") + /** * If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven). * Once the file is uploaded there, it can be automatically synchronized to JCenter by linking your project to @@ -233,9 +239,9 @@ data class BintrayConfig(val project: Project) { * the uploadBintray task is called. */ @Directive - var autoGitTag: Boolean = true - - val files = arrayListOf>() + fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) { + autoGitTag = Triple(auto, tag, message) + } @Directive fun file(filePath: String, url: String) { From c80020c36a93a1aefedd6b37e7a82f8d09c0ce69 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 10 Mar 2017 16:56:24 -0800 Subject: [PATCH 066/532] Added AutoGitTagConfig. --- .../main/kotlin/com/beust/kobalt/misc/Git.kt | 14 ++-- .../kobalt/plugin/publish/PublishPlugin.kt | 66 ++++++++++++------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt index e8fec4fa..67eb8bef 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt @@ -6,10 +6,10 @@ import com.google.inject.Inject import java.io.File class Git @Inject constructor() { - fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Triple) : TaskResult { + fun maybeTagRelease(project: Project, uploadResult: TaskResult, auto: Boolean, tag: String, message: String) : TaskResult { val result = - if (uploadResult.success && autoGitTag.first) { - val tagSuccess = tagRelease(project, autoGitTag) + if (uploadResult.success && auto) { + val tagSuccess = tagRelease(project, auto, tag, message) if (! tagSuccess) { TaskResult(false, "Couldn't tag the project") } else { @@ -21,9 +21,9 @@ class Git @Inject constructor() { return result } - private fun tagRelease(project: Project, autoGitTag: Triple) : Boolean { + private fun tagRelease(project: Project, auto: Boolean, tag: String, message: String) : Boolean { + val version = if (tag.isNullOrBlank()) project.version else tag val success = try { - val version = if (autoGitTag.second.isNullOrBlank()) project.version else autoGitTag.second log(2, "Tagging this release as \"$version\"") val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder() .setGitDir(File(KFiles.joinDir(project.directory, ".git"))) @@ -31,11 +31,11 @@ class Git @Inject constructor() { .findGitDir() .build() val git = org.eclipse.jgit.api.Git(repo) - val ref = git.tag().setName(version).setMessage(autoGitTag.third).call() + val ref = git.tag().setName(version).setMessage(message).call() git.push().setPushTags().call() true } catch(ex: Exception) { - warn("Couldn't create tag ${project.version}: ${ex.message}", ex) + warn("Couldn't create tag ${version}: ${ex.message}", ex) false } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 78753ccc..122c536f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -112,6 +112,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener val jcenter = bintrayFactory.create(user, password, org) var success = false val configuration = bintrayConfigurations[project.name] + val autoGitTagConfig = autoGitTagConfigurations[project.name] val messages = arrayListOf() val tmpResult = @@ -133,7 +134,13 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener messages.add(taskResult.errorMessage!!) } } - git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag) + if (autoGitTagConfig != null) { + with(autoGitTagConfig) { + git.maybeTagRelease(project, TaskResult(), auto, tag, message) + } + } else { + TaskResult() + } } else { context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything") TaskResult() @@ -153,6 +160,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener private fun uploadGithub(project: Project) : TaskResult { val configuration = githubConfigurations[project.name] + val autoGitTagConfig = autoGitTagConfigurations[project.name] // // Upload individual files, if applicable @@ -163,7 +171,13 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener logk(project.name, 2, "Uploading $it tag: ${project.version}") github.uploadRelease(project.name, project.version!!, it) } - git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag) + if (autoGitTagConfig != null) { + with(autoGitTagConfig) { + git.maybeTagRelease(project, TaskResult(), auto, tag, message) + } + } else { + TaskResult() + } } else { warn("Couldn't find any github{} configuration, not uploading anything") TaskResult() @@ -187,20 +201,29 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener fun addGithubConfiguration(projectName: String, config: GithubConfig) { githubConfigurations.put(projectName, config) } + + /** + * Map of project name -> AutoGitTagConfiguration + */ + private val autoGitTagConfigurations = hashMapOf() + fun addAutoGitTagConfiguration(projectName: String, config: AutoGitTagConfig) { + autoGitTagConfigurations.put(projectName, config) + } +} + +data class AutoGitTagConfig(val project: Project) { + @Directive + var auto: Boolean = true + + @Directive + var tag : String = project.version!! + + @Directive + var message : String = "" } data class GithubConfig(val project: Project) { val files = arrayListOf() - var autoGitTag = Triple(true, project.version!!, "") - - /** - * If true, automatically tag this release with the current version number and push that tag to origin when - * the uploadGithub task is called. - */ - @Directive - fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) { - autoGitTag = Triple(auto, tag, message) - } @Directive fun file(filePath: String, url: String) { @@ -215,9 +238,8 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig = (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addGithubConfiguration(name, config) } -data class BintrayConfig(val project: Project) { +data class BintrayConfig(val project: Project) { val files = arrayListOf>() - var autoGitTag = Triple(true, project.version!!, "") /** * If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven). @@ -234,15 +256,6 @@ data class BintrayConfig(val project: Project) { @Directive var sign: Boolean = false - /** - * If true, automatically tag this release with the current version number and push that tag to origin when - * the uploadBintray task is called. - */ - @Directive - fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) { - autoGitTag = Triple(auto, tag, message) - } - @Directive fun file(filePath: String, url: String) { files.add(Pair(filePath, url)) @@ -261,3 +274,10 @@ fun Project.bintray(init: BintrayConfig.() -> Unit) = config.init() (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addBintrayConfiguration(name, config) } + +@Directive +fun Project.autoGitTag(init: AutoGitTagConfig.() -> Unit) = + AutoGitTagConfig(this).also { config -> + config.init() + (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addAutoGitTagConfiguration(name, config) + } From 49538338a44f86231cfbf2f8733ed8043b93a46f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 16 Mar 2017 19:22:28 -0700 Subject: [PATCH 067/532] Refactored duplicate code. --- .../kobalt/plugin/publish/PublishPlugin.kt | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 122c536f..5a442893 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -44,6 +44,16 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener return TaskResult() } + private fun autoGitTag(project: Project, uploadResult: TaskResult, config: AutoGitTagConfig?) : TaskResult { + if (config != null) { + with(config) { + return git.maybeTagRelease(project, uploadResult, auto, tag, message) + } + } else { + return TaskResult() + } + } + private fun validateProject(project: Project) { requireNotNull(project.name, { "Project $project should have a name" }) requireNotNull(project.version, { "Project $project should have a version" }) @@ -112,7 +122,6 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener val jcenter = bintrayFactory.create(user, password, org) var success = false val configuration = bintrayConfigurations[project.name] - val autoGitTagConfig = autoGitTagConfigurations[project.name] val messages = arrayListOf() val tmpResult = @@ -134,13 +143,11 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener messages.add(taskResult.errorMessage!!) } } - if (autoGitTagConfig != null) { - with(autoGitTagConfig) { - git.maybeTagRelease(project, TaskResult(), auto, tag, message) - } - } else { - TaskResult() - } + + // + // Tag release, if applicable + // + autoGitTag(project, TaskResult(), autoGitTagConfigurations[project.name]) } else { context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything") TaskResult() @@ -160,7 +167,6 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener private fun uploadGithub(project: Project) : TaskResult { val configuration = githubConfigurations[project.name] - val autoGitTagConfig = autoGitTagConfigurations[project.name] // // Upload individual files, if applicable @@ -171,13 +177,11 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener logk(project.name, 2, "Uploading $it tag: ${project.version}") github.uploadRelease(project.name, project.version!!, it) } - if (autoGitTagConfig != null) { - with(autoGitTagConfig) { - git.maybeTagRelease(project, TaskResult(), auto, tag, message) - } - } else { - TaskResult() - } + + // + // Tag release, if applicable + // + autoGitTag(project, TaskResult(), autoGitTagConfigurations[project.name]) } else { warn("Couldn't find any github{} configuration, not uploading anything") TaskResult() @@ -238,7 +242,7 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig = (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addGithubConfiguration(name, config) } -data class BintrayConfig(val project: Project) { +data class BintrayConfig(val project: Project) { val files = arrayListOf>() /** From 02beb62195aa20abdc82d7f98b1398be544a6d2b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 15 Mar 2017 22:49:02 -0700 Subject: [PATCH 068/532] Warnings. --- .../main/kotlin/com/beust/kobalt/Variant.kt | 102 +++++++++--------- 1 file changed, 50 insertions(+), 52 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 1ef6b8aa..d15327b1 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 @@ -29,7 +29,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null, /** * for {internal, release}, return [internalRelease, internal, release] */ - fun allDirectories(project: Project): List { + fun allDirectories(): List { return arrayListOf().apply { add(toCamelcaseDir()) add(productFlavor.name) @@ -88,7 +88,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null, result.add(dir) } - result.addAll(allDirectories(project) + result.addAll(allDirectories() .map { File(KFiles.joinDir("src", it, suffix)) } .filter(File::exists)) @@ -113,8 +113,8 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null, if (isDefault) { archiveName ?: project.name + "-" + project.version + suffix } else { - val base = if (archiveName != null) archiveName.substring(0, archiveName.length - suffix.length) - else project.name + "-" + project.version + val base = archiveName?.substring(0, archiveName.length - suffix.length) + ?: project.name + "-" + project.version val flavor = if (productFlavor.name.isEmpty()) "" else "-" + productFlavor.name val type = if (buildType.name.isEmpty()) "" else "-" + buildType.name val result: String = base + flavor + type + suffix @@ -124,65 +124,63 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null, return result } - val shortArchiveName = if (isDefault) "" else "-" + productFlavor.name + "-" + buildType.name - var generatedSourceDirectory: File? = null - private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? { - val buildTypeName = variant?.buildType?.name - return project.buildTypes[buildTypeName]?.buildConfig ?: null - } - - private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? { - val buildTypeName = variant?.productFlavor?.name - return project.productFlavors[buildTypeName]?.buildConfig ?: 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 +// } /** * 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(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 +// } +// } override fun toString() = toTask("") @@ -222,7 +220,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null, } fun toCamelcaseDir() : String { - fun lci(s : String) = if (s.length == 0 || s.length == 1) s else s[0].toLowerCase() + s.substring(1) + fun lci(s : String) = if (s.isEmpty() || s.length == 1) s else s[0].toLowerCase() + s.substring(1) return lci(productFlavor.name) + buildType.name.capitalize() } From ebe475c997171f64e9d978986038e3d902c37acb Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 17 Mar 2017 13:27:01 -0700 Subject: [PATCH 069/532] Fix test-output. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 008f2291..f43be88c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -16,13 +16,14 @@ class TestNgRunner : GenericTestRunner() { override val annotationPackage = "org.testng" - fun defaultOutput(project: Project) = KFiles.joinDir(project.buildDirectory, "test-output") + fun defaultOutput(project: Project) = KFiles.joinDir(KFiles.KOBALT_BUILD_DIR, project.buildDirectory, "test-output") override fun args(project: Project, context: KobaltContext, classpath: List, testConfig: TestConfig) = arrayListOf().apply { - var addOutput = true - testConfig.testArgs.forEach { arg -> - if (arg == "-d") addOutput = false + + if (testConfig.testArgs.none { it == "-d" }) { + add("-d") + add(defaultOutput(project)) } if (testConfig.testArgs.size == 0) { @@ -32,11 +33,7 @@ class TestNgRunner : GenericTestRunner() { add(testngXml.absolutePath) } else { val testClasses = findTestClasses(project, context, testConfig) - if (testClasses.size > 0) { - if (addOutput) { - add("-d") - add(defaultOutput(project)) - } + if (testClasses.isNotEmpty()) { addAll(testConfig.testArgs) add("-testclass") @@ -48,10 +45,6 @@ class TestNgRunner : GenericTestRunner() { } } } else { - if (addOutput) { - add("-d") - add(defaultOutput(project)) - } addAll(testConfig.testArgs) } } From 5efd7a760a357e58e066ded4bd9a9269bc4c436f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 17 Mar 2017 13:27:13 -0700 Subject: [PATCH 070/532] 1.0.14. --- 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 20728f85..66905c1a 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.13 \ No newline at end of file +kobalt.version=1.0.14 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 701a3432..56814bf4 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.13 +kobalt.version=1.0.14 From e4bf002fce432ef146f912548125e5c835ac431f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 17 Mar 2017 23:16:17 -0700 Subject: [PATCH 071/532] Update build. --- kobalt/src/Build.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 865a6d26..be7d1d31 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -6,6 +6,7 @@ import com.beust.kobalt.plugin.application.application import com.beust.kobalt.plugin.java.javaCompiler import com.beust.kobalt.plugin.kotlin.kotlinCompiler import com.beust.kobalt.plugin.packaging.assemble +import com.beust.kobalt.plugin.publish.autoGitTag import com.beust.kobalt.plugin.publish.bintray import com.beust.kobalt.plugin.publish.github import com.beust.kobalt.project @@ -213,12 +214,15 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { github { file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip") - autoGitTag = true } test { args("-log", "2", "src/test/resources/testng.xml") } + + autoGitTag { + auto = true + } } fun readVersion() : String { From c6e15739e870d97b3badfe701b5f6190d30be54a Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 17 Mar 2017 23:16:29 -0700 Subject: [PATCH 072/532] 1.0.15. --- 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 66905c1a..1ce31437 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.14 \ No newline at end of file +kobalt.version=1.0.15 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 56814bf4..1f82a793 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.14 +kobalt.version=1.0.15 From 792fa886741ac259578861a03ab75b00e3293e3b Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 18 Mar 2017 00:45:06 -0700 Subject: [PATCH 073/532] Added annotated directive to autoGitTag. --- .../src/main/kotlin/com/beust/kobalt/misc/Git.kt | 8 ++++---- .../com/beust/kobalt/plugin/publish/PublishPlugin.kt | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt index 67eb8bef..264cdc2a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt @@ -6,10 +6,10 @@ import com.google.inject.Inject import java.io.File class Git @Inject constructor() { - fun maybeTagRelease(project: Project, uploadResult: TaskResult, auto: Boolean, tag: String, message: String) : TaskResult { + fun maybeTagRelease(project: Project, uploadResult: TaskResult, auto: Boolean, annotated: Boolean, tag: String, message: String) : TaskResult { val result = if (uploadResult.success && auto) { - val tagSuccess = tagRelease(project, auto, tag, message) + val tagSuccess = tagRelease(project, auto, annotated, tag, message) if (! tagSuccess) { TaskResult(false, "Couldn't tag the project") } else { @@ -21,7 +21,7 @@ class Git @Inject constructor() { return result } - private fun tagRelease(project: Project, auto: Boolean, tag: String, message: String) : Boolean { + private fun tagRelease(project: Project, auto: Boolean, annotated: Boolean, tag: String, message: String) : Boolean { val version = if (tag.isNullOrBlank()) project.version else tag val success = try { log(2, "Tagging this release as \"$version\"") @@ -31,7 +31,7 @@ class Git @Inject constructor() { .findGitDir() .build() val git = org.eclipse.jgit.api.Git(repo) - val ref = git.tag().setName(version).setMessage(message).call() + val ref = git.tag().setAnnotated(annotated).setName(version).setMessage(message).call() git.push().setPushTags().call() true } catch(ex: Exception) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 5a442893..a7d13dce 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -47,7 +47,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener private fun autoGitTag(project: Project, uploadResult: TaskResult, config: AutoGitTagConfig?) : TaskResult { if (config != null) { with(config) { - return git.maybeTagRelease(project, uploadResult, auto, tag, message) + return git.maybeTagRelease(project, uploadResult, auto, annotated, tag, message) } } else { return TaskResult() @@ -219,6 +219,9 @@ data class AutoGitTagConfig(val project: Project) { @Directive var auto: Boolean = true + @Directive + var annotated: Boolean = false + @Directive var tag : String = project.version!! From 17bd4a0cec4bb0bb72296c79848d140c807d4262 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 18 Mar 2017 11:32:14 -0700 Subject: [PATCH 074/532] Renamed auto paramter to enabled for autoGitTag directive. --- .../src/main/kotlin/com/beust/kobalt/misc/Git.kt | 8 ++++---- .../com/beust/kobalt/plugin/publish/PublishPlugin.kt | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt index 264cdc2a..0507130b 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt @@ -6,10 +6,10 @@ import com.google.inject.Inject import java.io.File class Git @Inject constructor() { - fun maybeTagRelease(project: Project, uploadResult: TaskResult, auto: Boolean, annotated: Boolean, tag: String, message: String) : TaskResult { + fun maybeTagRelease(project: Project, uploadResult: TaskResult, enabled: Boolean, annotated: Boolean, tag: String, message: String) : TaskResult { val result = - if (uploadResult.success && auto) { - val tagSuccess = tagRelease(project, auto, annotated, tag, message) + if (uploadResult.success && enabled) { + val tagSuccess = tagRelease(project, annotated, tag, message) if (! tagSuccess) { TaskResult(false, "Couldn't tag the project") } else { @@ -21,7 +21,7 @@ class Git @Inject constructor() { return result } - private fun tagRelease(project: Project, auto: Boolean, annotated: Boolean, tag: String, message: String) : Boolean { + private fun tagRelease(project: Project, annotated: Boolean, tag: String, message: String) : Boolean { val version = if (tag.isNullOrBlank()) project.version else tag val success = try { log(2, "Tagging this release as \"$version\"") diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index a7d13dce..23519c43 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -47,7 +47,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener private fun autoGitTag(project: Project, uploadResult: TaskResult, config: AutoGitTagConfig?) : TaskResult { if (config != null) { with(config) { - return git.maybeTagRelease(project, uploadResult, auto, annotated, tag, message) + return git.maybeTagRelease(project, uploadResult, enabled, annotated, tag, message) } } else { return TaskResult() @@ -217,7 +217,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener data class AutoGitTagConfig(val project: Project) { @Directive - var auto: Boolean = true + var enabled: Boolean = true @Directive var annotated: Boolean = false From b21d867ec25bbd046976a24fcd31be8236ddfefe Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:09:04 -0700 Subject: [PATCH 075/532] Warning. --- .../src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index b47fab50..aba91a24 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -30,7 +30,7 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager } val sourceFiles = KFiles.findSourceFiles(project.directory, contributedSourceDirs.map { it.path }, compiler.sourceSuffixes) - if (sourceFiles.size > 0) { + if (sourceFiles.isNotEmpty()) { // TODO: createCompilerActionInfo recalculates the source files, only compute them // once and pass them val info = createCompilerActionInfo(project, context, compiler, isTest, From d777ca20cbf95bbead887f9df5770107a788144e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:09:28 -0700 Subject: [PATCH 076/532] Change warn() to log(). --- .../main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt index fa48427e..18dde1a1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt @@ -58,7 +58,7 @@ class CompilerDescription(override val name: String, override val sourceDirecto if (info.sourceFiles.isNotEmpty()) { compiler.compile(project, context, info) } else { - warn("$name cdouldn't find any source files to compile") + log(2, "$name couldn't find any source files to compile") TaskResult() } return result From 6a50e01ebcfb731b22ca3570037bb4c43d290423 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:10:41 -0700 Subject: [PATCH 077/532] warn() to log(). --- .../main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt index 18dde1a1..b6ce8fd2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt @@ -1,7 +1,6 @@ package com.beust.kobalt.api import com.beust.kobalt.TaskResult -import com.beust.kobalt.misc.warn interface ICompilerDescription : Comparable { /** @@ -58,7 +57,7 @@ class CompilerDescription(override val name: String, override val sourceDirecto if (info.sourceFiles.isNotEmpty()) { compiler.compile(project, context, info) } else { - log(2, "$name couldn't find any source files to compile") + context.logger.log(project.name, 2, "$name couldn't find any source files to compile") TaskResult() } return result From 3bdc83b20e4ee22ac2fb12de413cbf634195224d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:17:48 -0700 Subject: [PATCH 078/532] Fix test path for Windows. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 7da65d26..8967a4d7 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -27,8 +27,7 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { */ fun compileSingleProject(projectText: String, args: Args = Args()) : Project { val projectName = "p" + Math.abs(Random().nextInt()) - val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path - + val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path.replace("\\", "/") val buildFileText= """ import com.beust.kobalt.* import com.beust.kobalt.api.* From 43b037171c65335090f11f7870b3d3a3729ff4a4 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:18:01 -0700 Subject: [PATCH 079/532] Reformat. --- .../kotlin/com/beust/kobalt/internal/ActorUtils.kt | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt index 42aac9e2..e9b315a5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt @@ -1,7 +1,6 @@ package com.beust.kobalt.internal import com.beust.kobalt.api.IProjectAffinity -import com.beust.kobalt.api.ISimpleAffinity import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project @@ -11,19 +10,13 @@ class ActorUtils { * Return the plug-in actor with the highest affinity. */ fun selectAffinityActor(project: Project, context: KobaltContext, actors: List) - = actors.maxBy { it.affinity(project, context) } + = actors.maxBy { it.affinity(project, context) } /** * Return all the plug-in actors with a non zero affinity sorted from the highest to the lowest. */ fun selectAffinityActors(project: Project, context: KobaltContext, actors: List) = actors.filter { it.affinity(project, context) > 0 } - .sortedByDescending { it.affinity(project, context) } - - /** - * Return the plug-in actor with the highest affinity. - */ - fun , A> selectAffinityActor(actors: List, arg: A) = actors.maxBy { it.affinity(arg) } + .sortedByDescending { it.affinity(project, context) } } - } From fd735947679c3c9b5ea22d4f1d99ef1b63cfaea5 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:18:42 -0700 Subject: [PATCH 080/532] 1.0.16. --- 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 1ce31437..e88179ec 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.15 \ No newline at end of file +kobalt.version=1.0.16 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 1f82a793..3ca21f62 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.15 +kobalt.version=1.0.16 From 3ee309fa37fc6a01c7ea0f85d63c2ad6e32f3571 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:42:19 -0700 Subject: [PATCH 081/532] 1.0.17. --- 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 e88179ec..aea11e8a 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.16 \ No newline at end of file +kobalt.version=1.0.17 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 3ca21f62..c0ad399b 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.16 +kobalt.version=1.0.17 From a3734f88c337f1fd1827c2f08a4f6cbd4adf64f7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 19 Mar 2017 09:06:26 -0700 Subject: [PATCH 082/532] TestNG runner work in progress. --- .../beust/kobalt/internal/GenericRunner.kt | 2 +- .../com/beust/kobalt/internal/TestNgRunner.kt | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index 2dcea900..a4796e83 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -94,7 +94,7 @@ abstract class GenericTestRunner: ITestRunnerContributor { /** * @return true if all the tests passed */ - fun runTests(project: Project, context: KobaltContext, classpath: List, + open fun runTests(project: Project, context: KobaltContext, classpath: List, configName: String) : Boolean { var result = false diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index f43be88c..6934e162 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -4,9 +4,17 @@ import com.beust.kobalt.TestConfig import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project +import com.beust.kobalt.homeDir import com.beust.kobalt.misc.KFiles +import com.beust.kobalt.misc.runCommand import com.beust.kobalt.misc.warn +import org.testng.remote.RemoteArgs +import org.testng.remote.strprotocol.JsonMessageSender +import org.testng.remote.strprotocol.MessageHelper +import org.testng.remote.strprotocol.MessageHub +import org.testng.remote.strprotocol.TestResultMessage import java.io.File +import java.io.IOException class TestNgRunner : GenericTestRunner() { @@ -48,4 +56,79 @@ class TestNgRunner : GenericTestRunner() { addAll(testConfig.testArgs) } } + + fun _runTests(project: Project, context: KobaltContext, classpath: List, + configName: String): Boolean { + var result = false + val port = 2345 + + val classpath = listOf(homeDir("java/jcommander/kobaltBuild/classes"), + homeDir(".kobalt/cache/org/testng/testng/6.10/testng-6.10.jar"), + homeDir(".kobalt/cache/com/beust/jcommander/1.66/jcommander-1.66.jar"), + homeDir(".kobalt/cache/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar"), + homeDir(".kobalt/cache/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.jar"), + homeDir("java/jcommander/kobaltBuild/test-classes"), + homeDir("java/jcommander/src/test/resources/testng.xml"), + homeDir("kotlin/kobalt/lib/testng-remote-1.3.0-SNAPSHOT.jar"), + homeDir("kotlin/kobalt/lib/testng-remote6_10-1.3.0-SNAPSHOT.jar") + ).joinToString(File.pathSeparator) + val passedArgs = listOf( + "-classpath", + classpath, + "org.testng.remote.RemoteTestNG", + "-serport", port.toString(), + "-version", "6.10", + "-dontexit", + RemoteArgs.PROTOCOL, + "json", + "src/test/resources/testng.xml") + + Thread { + val exitCode = runCommand { + command = "java" + directory = File(homeDir("java/jcommander")) + args = passedArgs + } + }.start() + +// Thread { +// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", +// "-version", "6.10", +// "src/test/resources/testng.xml") +// RemoteTestNG.main(args2) +// }.start() + + val mh = MessageHub(JsonMessageSender("localhost", port, true)) + mh.setDebug(true) + mh.initReceiver() + val passed = arrayListOf() + data class FailedTest(val method: String, val cls: String, val stackTrace: String) + val failed = arrayListOf() + var skipped = arrayListOf() + try { + var message = mh.receiveMessage() + println("") + while (message != null) { + message = mh.receiveMessage() + if (message is TestResultMessage) { + when(message.result) { + MessageHelper.PASSED_TEST -> passed.add(message.name) + MessageHelper.FAILED_TEST -> failed.add(FailedTest(message.testClass, + message.method, message.stackTrace)) + MessageHelper.SKIPPED_TEST -> skipped.add(message.name) + } + } + print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size)) +// Thread.sleep(200) + } + } catch(ex: IOException) { + println("Exception: ${ex.message}") + } + println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size) + failed.forEach { + val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n")) + println(" " + it.cls + "." + it.method + "\n " + top) + } + return result + } } From 7f6a39ecfae26c27bae7460323bd42b6a534e30c Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 19 Mar 2017 09:41:26 -0700 Subject: [PATCH 083/532] Fix build. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 152 +++++++++--------- 1 file changed, 72 insertions(+), 80 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 6934e162..568287f5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -4,17 +4,9 @@ import com.beust.kobalt.TestConfig import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project -import com.beust.kobalt.homeDir import com.beust.kobalt.misc.KFiles -import com.beust.kobalt.misc.runCommand import com.beust.kobalt.misc.warn -import org.testng.remote.RemoteArgs -import org.testng.remote.strprotocol.JsonMessageSender -import org.testng.remote.strprotocol.MessageHelper -import org.testng.remote.strprotocol.MessageHub -import org.testng.remote.strprotocol.TestResultMessage import java.io.File -import java.io.IOException class TestNgRunner : GenericTestRunner() { @@ -57,78 +49,78 @@ class TestNgRunner : GenericTestRunner() { } } - fun _runTests(project: Project, context: KobaltContext, classpath: List, - configName: String): Boolean { - var result = false - val port = 2345 - - val classpath = listOf(homeDir("java/jcommander/kobaltBuild/classes"), - homeDir(".kobalt/cache/org/testng/testng/6.10/testng-6.10.jar"), - homeDir(".kobalt/cache/com/beust/jcommander/1.66/jcommander-1.66.jar"), - homeDir(".kobalt/cache/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar"), - homeDir(".kobalt/cache/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.jar"), - homeDir("java/jcommander/kobaltBuild/test-classes"), - homeDir("java/jcommander/src/test/resources/testng.xml"), - homeDir("kotlin/kobalt/lib/testng-remote-1.3.0-SNAPSHOT.jar"), - homeDir("kotlin/kobalt/lib/testng-remote6_10-1.3.0-SNAPSHOT.jar") - ).joinToString(File.pathSeparator) - val passedArgs = listOf( - "-classpath", - classpath, - "org.testng.remote.RemoteTestNG", - "-serport", port.toString(), - "-version", "6.10", - "-dontexit", - RemoteArgs.PROTOCOL, - "json", - "src/test/resources/testng.xml") - - Thread { - val exitCode = runCommand { - command = "java" - directory = File(homeDir("java/jcommander")) - args = passedArgs - } - }.start() - +// fun _runTests(project: Project, context: KobaltContext, classpath: List, +// configName: String): Boolean { +// var result = false +// val port = 2345 +// +// val classpath = listOf(homeDir("java/jcommander/kobaltBuild/classes"), +// homeDir(".kobalt/cache/org/testng/testng/6.10/testng-6.10.jar"), +// homeDir(".kobalt/cache/com/beust/jcommander/1.66/jcommander-1.66.jar"), +// homeDir(".kobalt/cache/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar"), +// homeDir(".kobalt/cache/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.jar"), +// homeDir("java/jcommander/kobaltBuild/test-classes"), +// homeDir("java/jcommander/src/test/resources/testng.xml"), +// homeDir("kotlin/kobalt/lib/testng-remote-1.3.0-SNAPSHOT.jar"), +// homeDir("kotlin/kobalt/lib/testng-remote6_10-1.3.0-SNAPSHOT.jar") +// ).joinToString(File.pathSeparator) +// val passedArgs = listOf( +// "-classpath", +// classpath, +// "org.testng.remote.RemoteTestNG", +// "-serport", port.toString(), +// "-version", "6.10", +// "-dontexit", +// RemoteArgs.PROTOCOL, +// "json", +// "src/test/resources/testng.xml") +// // Thread { -// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", -// "-version", "6.10", -// "src/test/resources/testng.xml") -// RemoteTestNG.main(args2) +// val exitCode = runCommand { +// command = "java" +// directory = File(homeDir("java/jcommander")) +// args = passedArgs +// } // }.start() - - val mh = MessageHub(JsonMessageSender("localhost", port, true)) - mh.setDebug(true) - mh.initReceiver() - val passed = arrayListOf() - data class FailedTest(val method: String, val cls: String, val stackTrace: String) - val failed = arrayListOf() - var skipped = arrayListOf() - try { - var message = mh.receiveMessage() - println("") - while (message != null) { - message = mh.receiveMessage() - if (message is TestResultMessage) { - when(message.result) { - MessageHelper.PASSED_TEST -> passed.add(message.name) - MessageHelper.FAILED_TEST -> failed.add(FailedTest(message.testClass, - message.method, message.stackTrace)) - MessageHelper.SKIPPED_TEST -> skipped.add(message.name) - } - } - print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size)) -// Thread.sleep(200) - } - } catch(ex: IOException) { - println("Exception: ${ex.message}") - } - println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size) - failed.forEach { - val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n")) - println(" " + it.cls + "." + it.method + "\n " + top) - } - return result - } +// +//// Thread { +//// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", +//// "-version", "6.10", +//// "src/test/resources/testng.xml") +//// RemoteTestNG.main(args2) +//// }.start() +// +// val mh = MessageHub(JsonMessageSender("localhost", port, true)) +// mh.setDebug(true) +// mh.initReceiver() +// val passed = arrayListOf() +// data class FailedTest(val method: String, val cls: String, val stackTrace: String) +// val failed = arrayListOf() +// var skipped = arrayListOf() +// try { +// var message = mh.receiveMessage() +// println("") +// while (message != null) { +// message = mh.receiveMessage() +// if (message is TestResultMessage) { +// when(message.result) { +// MessageHelper.PASSED_TEST -> passed.add(message.name) +// MessageHelper.FAILED_TEST -> failed.add(FailedTest(message.testClass, +// message.method, message.stackTrace)) +// MessageHelper.SKIPPED_TEST -> skipped.add(message.name) +// } +// } +// print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size)) +//// Thread.sleep(200) +// } +// } catch(ex: IOException) { +// println("Exception: ${ex.message}") +// } +// println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size) +// failed.forEach { +// val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n")) +// println(" " + it.cls + "." + it.method + "\n " + top) +// } +// return result +// } } From 0de3327b05f97883da38ad3d31e42f000fd5a885 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 09:55:25 -0700 Subject: [PATCH 084/532] Adjust Build.kt. --- kobalt/src/Build.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index be7d1d31..7f46d9d2 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -221,7 +221,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { } autoGitTag { - auto = true + enabled = true } } From 4911677bc1d9084ad4abe49c9c0c9da7a4cc3ba0 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 12:04:57 -0700 Subject: [PATCH 085/532] Better ResolveDependency. --- .../src/main/kotlin/com/beust/kobalt/ResolveDependency.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt index b1a0fb2a..7c848461 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt @@ -9,6 +9,7 @@ import com.beust.kobalt.maven.aether.KobaltMavenResolver import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.Node import com.beust.kobalt.misc.kobaltLog +import com.beust.kobalt.misc.warn import com.google.inject.Inject import org.eclipse.aether.artifact.DefaultArtifact import org.eclipse.aether.graph.DependencyNode @@ -104,7 +105,12 @@ class ResolveDependency @Inject constructor( kobaltLog(2, "Found dependency ${dep.dep.id} level: ${dep.level}") result.add(node) seen.add(it.id) - node.addChildren(findChildren(node, seen)) + try { + node.addChildren(findChildren(node, seen)) + } catch(ex: Exception) { + if (! it.optional) warn("Couldn't resolve " + node) + // else don't warn about missing optional dependencies + } } } kobaltLog(2, "Children for ${root.value.dep.id}: ${result.size}") From a9bba0d83b8ba3a3999388e60387ac41569690fe Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 14:49:11 -0700 Subject: [PATCH 086/532] Better dependency exclusion. --- .../beust/kobalt/api/IClasspathDependency.kt | 2 + .../beust/kobalt/api/IDependencyManager.kt | 42 ++++++++++++++++++- .../kotlin/com/beust/kobalt/api/Project.kt | 26 +++++++++++- .../com/beust/kobalt/internal/JvmCompiler.kt | 4 +- .../kobalt/internal/JvmCompilerPlugin.kt | 1 + .../beust/kobalt/maven/DependencyManager.kt | 10 ++--- .../kobalt/maven/aether/AetherDependency.kt | 3 ++ .../kobalt/maven/dependency/FileDependency.kt | 3 ++ .../com/beust/kobalt/app/ParsedBuildFile.kt | 5 ++- 9 files changed, 84 insertions(+), 12 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt index a24344ad..527e6f13 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt @@ -36,4 +36,6 @@ interface IClasspathDependency { /** Used to only keep the most recent version for an artifact if no version was specified */ val shortId: String + + val excluded: ArrayList } \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt index c2e7fdb9..a1e9f6ba 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt @@ -1,8 +1,10 @@ package com.beust.kobalt.api -import com.beust.kobalt.maven.aether.Filters +import com.beust.kobalt.maven.aether.Filters.EXCLUDE_OPTIONAL_FILTER +import com.beust.kobalt.maven.aether.KobaltMavenResolver import com.beust.kobalt.maven.aether.Scope import org.eclipse.aether.graph.DependencyFilter +import org.eclipse.aether.graph.DependencyNode /** * Manage the creation of dependencies and also provide dependencies for projects. @@ -38,7 +40,43 @@ interface IDependencyManager { * allDependencies is typically either compileDependencies or testDependencies */ fun calculateDependencies(project: Project?, context: KobaltContext, - dependencyFilter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER, + dependencyFilter: DependencyFilter = createDependencyFilter(project?.compileDependencies ?: emptyList()), scopes: List = listOf(Scope.COMPILE), vararg passedDependencies: List): List + + /** + * Create an Aether dependency filter that uses the dependency configuration included in each + * IClasspathDependency. + */ + fun createDependencyFilter(dependencies: List) : DependencyFilter { + return DependencyFilter { p0, p1 -> + fun isNodeExcluded(passedDep: IClasspathDependency, node: DependencyNode) : Boolean { + val dep = create(KobaltMavenResolver.artifactToId(node.artifact)) + return passedDep.excluded.any { ex -> ex.isExcluded(dep)} + } + + val accept = dependencies.any { + // Is this dependency excluded? + val isExcluded = isNodeExcluded(it, p0) + + // Is the parent dependency excluded? + val isParentExcluded = + if (p1.any()) { + isNodeExcluded(it, p1[0]) + } else { + false + } + + // Only accept if no exclusions were found + ! isExcluded && ! isParentExcluded + } + + if (! accept) { + println(" FOUND EXCLUDED DEP: " + p0) + } + + if (accept) EXCLUDE_OPTIONAL_FILTER.accept(p0, p1) + else accept + } + } } \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index 5e45e7cb..60a29fed 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -145,7 +145,7 @@ class Dependencies(val project: Project, * future tasks receive a get(), the repos will be correct. */ private fun addToDependencies(project: Project, dependencies: ArrayList, - dep: Array, optional: Boolean = false): List> + dep: Array, optional: Boolean = false, excludeConfig: ExcludeConfig? = null): List> = with(dep.map { val resolved = if (KobaltMavenResolver.isRangeVersion(it)) { @@ -160,12 +160,36 @@ class Dependencies(val project: Project, DependencyManager.create(resolved, optional, project.directory) }) { dependencies.addAll(this) + if (excludeConfig != null) { + this.forEach { it.excluded.add(excludeConfig) } + } + this.map { FutureTask { it.jarFile.get() } } } @Directive fun compile(vararg dep: String) = addToDependencies(project, dependencies, dep) + class ExcludeConfig { + val ids = arrayListOf() + + @Directive + fun excludeIds(vararg passedIds: String) = ids.addAll(passedIds) + + fun isExcluded(dep: IClasspathDependency) : Boolean { + val result = ids.contains(dep.id) + return result + } + } + + @Directive + fun compile(dep: String, init: ExcludeConfig.() -> Unit) { + val excludeConfig = ExcludeConfig().apply { + init() + } + addToDependencies(project, dependencies, arrayOf(dep), excludeConfig = excludeConfig) + } + @Directive fun compileOptional(vararg dep: String) { addToDependencies(project, optionalDependencies, dep, optional = true) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt index 25294934..58f65776 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt @@ -23,8 +23,8 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) flags: List): TaskResult { // Dependencies - val allDependencies = (info.dependencies - + dependencyManager.calculateDependencies(project, context!!, passedDependencies = info.dependencies)) + val allDependencies = (info.dependencies + dependencyManager.calculateDependencies(project, context!!, + passedDependencies = info.dependencies)) .distinct() // Plugins that add flags to the compiler 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 c27e26bb..fa774ad3 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 @@ -88,6 +88,7 @@ open class JvmCompilerPlugin @Inject constructor( if (testContributor != null && testContributor.affinity(project, context) > 0) { // val td1 = dependencyManager.testDependencies(project, context) val testDependencies = dependencyManager.calculateDependencies(project, context, + dependencyFilter = dependencyManager.createDependencyFilter(project.testDependencies), scopes = listOf(Scope.TEST)) val compileDependencies = dependencyManager.calculateDependencies(project, context, scopes = listOf(Scope.COMPILE)) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 9ff45407..f93d92c2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -178,11 +178,11 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, dependencyFilter: DependencyFilter? = null, requiredBy: String? = null): List { val result = arrayListOf() - dependencies.forEach { - result.add(it) - if (it.isMaven) { - val resolved = resolver.resolveToIds(it.id, null, dependencyFilter) - result.addAll(resolved.map { create(it) }) + dependencies.forEach { dependency -> + result.add(dependency) + if (dependency.isMaven) { + val resolved = resolver.resolveToIds(dependency.id, null, dependencyFilter).map { create(it) } + result.addAll(resolved) } } val reordered = reorderDependencies(result) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt index 7ec9bfe0..5cd532fe 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.maven.aether +import com.beust.kobalt.api.Dependencies import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Kobalt import com.beust.kobalt.maven.CompletedFuture @@ -65,6 +66,8 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean = override val shortId = artifact.groupId + ":" + artifact.artifactId + ":" + artifact.classifier + override val excluded = arrayListOf() + override fun compareTo(other: AetherDependency): Int { return Versions.toLongVersion(artifact.version).compareTo(Versions.toLongVersion( other.artifact.version)) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt index a271cf9a..047754e2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.maven.dependency +import com.beust.kobalt.api.Dependencies import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.maven.CompletedFuture import org.apache.maven.model.Dependency @@ -31,6 +32,8 @@ open class FileDependency(open val fileName: String, override val optional: Bool override fun directDependencies() = arrayListOf() + override val excluded = arrayListOf() + override fun compareTo(other: FileDependency) = fileName.compareTo(other.fileName) override fun toString() = fileName diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index 8f7d3fe3..cf9afc94 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -8,6 +8,7 @@ import com.beust.kobalt.api.Project import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.internal.build.VersionFile import com.beust.kobalt.maven.DependencyManager +import com.beust.kobalt.maven.aether.Filters.EXCLUDE_OPTIONAL_FILTER import com.beust.kobalt.misc.BlockExtractor import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog @@ -129,8 +130,8 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val } } - private fun generateJarFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File, - originalFile: BuildFile) { + private fun generateJarFile(context: KobaltContext, buildFile: BuildFile, + buildScriptJarFile: File, originalFile: BuildFile) { // // Compile the jar file From 61bc02b04b6569fd7b382c81528e83cc5f740807 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 14:49:15 -0700 Subject: [PATCH 087/532] Indent. --- .../com/beust/kobalt/plugin/application/ApplicationPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 69a61ceb..17e7aacf 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -117,7 +117,7 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor Date: Mon, 20 Mar 2017 14:49:22 -0700 Subject: [PATCH 088/532] Clean TestNGRunner. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 75 ------------------- 1 file changed, 75 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 568287f5..f43be88c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -48,79 +48,4 @@ class TestNgRunner : GenericTestRunner() { addAll(testConfig.testArgs) } } - -// fun _runTests(project: Project, context: KobaltContext, classpath: List, -// configName: String): Boolean { -// var result = false -// val port = 2345 -// -// val classpath = listOf(homeDir("java/jcommander/kobaltBuild/classes"), -// homeDir(".kobalt/cache/org/testng/testng/6.10/testng-6.10.jar"), -// homeDir(".kobalt/cache/com/beust/jcommander/1.66/jcommander-1.66.jar"), -// homeDir(".kobalt/cache/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar"), -// homeDir(".kobalt/cache/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.jar"), -// homeDir("java/jcommander/kobaltBuild/test-classes"), -// homeDir("java/jcommander/src/test/resources/testng.xml"), -// homeDir("kotlin/kobalt/lib/testng-remote-1.3.0-SNAPSHOT.jar"), -// homeDir("kotlin/kobalt/lib/testng-remote6_10-1.3.0-SNAPSHOT.jar") -// ).joinToString(File.pathSeparator) -// val passedArgs = listOf( -// "-classpath", -// classpath, -// "org.testng.remote.RemoteTestNG", -// "-serport", port.toString(), -// "-version", "6.10", -// "-dontexit", -// RemoteArgs.PROTOCOL, -// "json", -// "src/test/resources/testng.xml") -// -// Thread { -// val exitCode = runCommand { -// command = "java" -// directory = File(homeDir("java/jcommander")) -// args = passedArgs -// } -// }.start() -// -//// Thread { -//// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", -//// "-version", "6.10", -//// "src/test/resources/testng.xml") -//// RemoteTestNG.main(args2) -//// }.start() -// -// val mh = MessageHub(JsonMessageSender("localhost", port, true)) -// mh.setDebug(true) -// mh.initReceiver() -// val passed = arrayListOf() -// data class FailedTest(val method: String, val cls: String, val stackTrace: String) -// val failed = arrayListOf() -// var skipped = arrayListOf() -// try { -// var message = mh.receiveMessage() -// println("") -// while (message != null) { -// message = mh.receiveMessage() -// if (message is TestResultMessage) { -// when(message.result) { -// MessageHelper.PASSED_TEST -> passed.add(message.name) -// MessageHelper.FAILED_TEST -> failed.add(FailedTest(message.testClass, -// message.method, message.stackTrace)) -// MessageHelper.SKIPPED_TEST -> skipped.add(message.name) -// } -// } -// print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size)) -//// Thread.sleep(200) -// } -// } catch(ex: IOException) { -// println("Exception: ${ex.message}") -// } -// println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size) -// failed.forEach { -// val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n")) -// println(" " + it.cls + "." + it.method + "\n " + top) -// } -// return result -// } } From 229e0b8f36b56f248cffed6478eb5a06087a7639 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 15:05:42 -0700 Subject: [PATCH 089/532] Include global excludes. --- .../com/beust/kobalt/api/IDependencyManager.kt | 15 ++++++++++----- .../beust/kobalt/internal/JvmCompilerPlugin.kt | 2 +- .../com/beust/kobalt/maven/DependencyManager.kt | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt index a1e9f6ba..252baf08 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt @@ -40,7 +40,8 @@ interface IDependencyManager { * allDependencies is typically either compileDependencies or testDependencies */ fun calculateDependencies(project: Project?, context: KobaltContext, - dependencyFilter: DependencyFilter = createDependencyFilter(project?.compileDependencies ?: emptyList()), + dependencyFilter: DependencyFilter = + createDependencyFilter(project, project?.compileDependencies ?: emptyList()), scopes: List = listOf(Scope.COMPILE), vararg passedDependencies: List): List @@ -48,21 +49,25 @@ interface IDependencyManager { * Create an Aether dependency filter that uses the dependency configuration included in each * IClasspathDependency. */ - fun createDependencyFilter(dependencies: List) : DependencyFilter { + fun createDependencyFilter(project: Project?, dependencies: List) : DependencyFilter { return DependencyFilter { p0, p1 -> - fun isNodeExcluded(passedDep: IClasspathDependency, node: DependencyNode) : Boolean { + fun isNodeExcluded(node: DependencyNode, passedDep: IClasspathDependency) : Boolean { val dep = create(KobaltMavenResolver.artifactToId(node.artifact)) return passedDep.excluded.any { ex -> ex.isExcluded(dep)} } + fun isDepExcluded(node: DependencyNode, excluded: List?) : Boolean { + val dep = create(KobaltMavenResolver.artifactToId(node.artifact)) + return excluded?.map { it.id }?.contains(dep.id) ?: false + } val accept = dependencies.any { // Is this dependency excluded? - val isExcluded = isNodeExcluded(it, p0) + val isExcluded = isNodeExcluded(p0, it) || isDepExcluded(p0, project?.excludedDependencies) // Is the parent dependency excluded? val isParentExcluded = if (p1.any()) { - isNodeExcluded(it, p1[0]) + isNodeExcluded(p1[0], it) || isDepExcluded(p1[0], project?.excludedDependencies) } else { false } 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 fa774ad3..15cd7fc3 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 @@ -88,7 +88,7 @@ open class JvmCompilerPlugin @Inject constructor( if (testContributor != null && testContributor.affinity(project, context) > 0) { // val td1 = dependencyManager.testDependencies(project, context) val testDependencies = dependencyManager.calculateDependencies(project, context, - dependencyFilter = dependencyManager.createDependencyFilter(project.testDependencies), + dependencyFilter = dependencyManager.createDependencyFilter(project, project.testDependencies), scopes = listOf(Scope.TEST)) val compileDependencies = dependencyManager.calculateDependencies(project, context, scopes = listOf(Scope.COMPILE)) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index f93d92c2..14ae2c3d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -140,7 +140,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, * formally by groupId or artifactId. */ fun isDependencyExcluded(dep: IClasspathDependency, excluded: List): Boolean { - excluded.any { excluded -> dep.id.startsWith(excluded.id) }.let { result -> + excluded.any { excluded -> dep.id == excluded.id }.let { result -> if (result) { context.logger.log(project?.name ?: "", 2, " Excluding dependency $dep") } From 49b66b7420add857e77e899c67ecc3767e82148f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 15:30:00 -0700 Subject: [PATCH 090/532] Regex match exclusions. --- .../kotlin/com/beust/kobalt/api/Project.kt | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index 60a29fed..e6796a9a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -3,6 +3,7 @@ package com.beust.kobalt.api import com.beust.kobalt.TestConfig import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.maven.DependencyManager +import com.beust.kobalt.maven.aether.AetherDependency import com.beust.kobalt.maven.aether.KobaltMavenResolver import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog @@ -11,6 +12,7 @@ import java.io.File import java.util.* import java.util.concurrent.Future import java.util.concurrent.FutureTask +import java.util.regex.Pattern open class Project( @Directive open var name: String = "", @@ -174,10 +176,44 @@ class Dependencies(val project: Project, val ids = arrayListOf() @Directive - fun excludeIds(vararg passedIds: String) = ids.addAll(passedIds) + fun exclude(vararg passedIds: String) = ids.addAll(passedIds) + class ArtifactConfig( + var groupId: String? = null, + var artifactId: String? = null, + var version: String? = null + ) + + val artifacts = arrayListOf() + + @Directive + fun exclude(groupId: String? = null, artifactId: String? = null, version: String? = null) + = artifacts.add(ArtifactConfig(groupId, artifactId, version)) + + fun match(pattern: String?, id: String) : Boolean { + return pattern == null || Pattern.compile(pattern).matcher(id).matches() + } + + /** + * @return true if the dependency is excluded with any of the exclude() directives. The matches + * are performed by a regular expression match against the dependency. + */ fun isExcluded(dep: IClasspathDependency) : Boolean { - val result = ids.contains(dep.id) + // Straight id match + var result = ids.any { match(it, dep.id) } + + // Match on any combination of (groupId, artifactId, version) + if (! result && dep.isMaven) { + val mavenDep = dep as AetherDependency + val artifact = mavenDep.artifact + result = artifacts.any { + val match1 = it.groupId == null || match(it.groupId, artifact.groupId) + val match2 = it.artifactId == null || match(it.artifactId, artifact.artifactId) + val match3 = it.version == null || match(it.version, artifact.version) + match1 && match2 && match3 + } + } + return result } } From 78675419219088ee1939ad58e3ab40fd69a8a253 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 15:32:16 -0700 Subject: [PATCH 091/532] Log --- .../src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt index 252baf08..e272e3d5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDependencyManager.kt @@ -3,6 +3,7 @@ package com.beust.kobalt.api import com.beust.kobalt.maven.aether.Filters.EXCLUDE_OPTIONAL_FILTER import com.beust.kobalt.maven.aether.KobaltMavenResolver import com.beust.kobalt.maven.aether.Scope +import com.beust.kobalt.misc.kobaltLog import org.eclipse.aether.graph.DependencyFilter import org.eclipse.aether.graph.DependencyNode @@ -77,7 +78,7 @@ interface IDependencyManager { } if (! accept) { - println(" FOUND EXCLUDED DEP: " + p0) + kobaltLog(2, "Excluding $p0") } if (accept) EXCLUDE_OPTIONAL_FILTER.accept(p0, p1) From f4b57167b072fe74dfaa7dd077f2b0a503ae03d0 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 15:56:27 -0700 Subject: [PATCH 092/532] Exclusion tests. --- .../com/beust/kobalt/internal/ExcludeTest.kt | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt index a772e428..41865745 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ExcludeTest.kt @@ -24,8 +24,8 @@ class ExcludeTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor arrayOf(EXCLUDED_DEPENDENCY) ) - @Test(dataProvider = "dp") - fun excludeShouldWork(excludedDependency: String?) { + @Test(dataProvider = "dp", description = "Text exclusions that apply to the whole project") + fun globalExcludeShouldWork(excludedDependency: String?) { val projectText = """ dependencies { compile("org.apache.maven:maven-model:jar:3.3.9") @@ -44,7 +44,43 @@ class ExcludeTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor } else { assertThat(allIds).contains(EXCLUDED_DEPENDENCY) } + } + @DataProvider + fun dp2() = arrayOf>( + arrayOf(null, 8, ""), + arrayOf("{ exclude(\".*org.apache.*\") }", 4, "org.apache"), + arrayOf("{ exclude(groupId = \"org.apache.*\") }", 4, "org.apache"), + arrayOf("{ exclude(artifactId = \".*core.*\") }", 7, "core"), + arrayOf("{ exclude(artifactId = \"httpcore\", version = \"4.3.3\") }", 7, "httpcore"), + arrayOf("{ exclude(version = \"4.3.3\") }", 7, "httpcore"), + arrayOf("{ exclude(artifactId = \"commons.codec\") }", 7, "commons-codec") + ) + + @Test(dataProvider = "dp2", description = "Text exclusions tied to a specific dependency") + fun localExcludeShouldWork(excludedDependency: String?, expectedCount: Int, excludedString: String) { + val projectText = """ + dependencies { + compile("org.eclipse.jgit:org.eclipse.jgit:4.5.0.201609210915-r") + """ + + (if (excludedDependency != null) """$excludedDependency""" else "") + + """ + } + """ + + val project = compileSingleProject(projectText) + val allIds = dependencyManager.calculateDependencies(project, Kobalt.context!!, + scopes = listOf(Scope.COMPILE)) + .map { it.id } + + assertThat(allIds.size).isEqualTo(expectedCount) + if (excludedDependency != null) { + if (allIds.any { it.contains(excludedString) }) { + throw AssertionError("id's should not contain any string \"$excludedString\": $allIds") + } + } else { + assertThat(allIds.filter { it.contains("org.apache") }.size).isEqualTo(2) + } } } From 0b318520ee23680461915e65aab5ee70abf91b78 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 16:06:04 -0700 Subject: [PATCH 093/532] 1.0.18. --- 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 aea11e8a..f92e14d5 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.17 \ No newline at end of file +kobalt.version=1.0.18 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index c0ad399b..bb9154b7 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.17 +kobalt.version=1.0.18 From 38beb02c2ff9616afe884b1713c4f4254bb74986 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 20 Mar 2017 18:33:07 -0700 Subject: [PATCH 094/532] Fixed jGit complaining and not tagging if setAnnotated(false) --- .../src/main/kotlin/com/beust/kobalt/misc/Git.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt index 0507130b..f4c4161f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt @@ -31,7 +31,12 @@ class Git @Inject constructor() { .findGitDir() .build() val git = org.eclipse.jgit.api.Git(repo) - val ref = git.tag().setAnnotated(annotated).setName(version).setMessage(message).call() + // jGit library will complain and not tag if setAnnotated(false) + var ref = if (annotated) { + git.tag().setAnnotated(annotated).setName(version).setMessage(message).call() + } else { + git.tag().setName(version).setMessage(message).call() + } git.push().setPushTags().call() true } catch(ex: Exception) { From 648bb383adbcc2ffbc84d5ed09881a2f6f57a9dd Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 20 Mar 2017 19:09:53 -0700 Subject: [PATCH 095/532] Indent. --- .../com/beust/kobalt/plugin/application/ApplicationPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 69a61ceb..17e7aacf 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -117,7 +117,7 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor Date: Mon, 20 Mar 2017 19:13:07 -0700 Subject: [PATCH 096/532] Enabled. --- kobalt/src/Build.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index be7d1d31..7f46d9d2 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -221,7 +221,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { } autoGitTag { - auto = true + enabled = true } } From de6b7afb61ecf25da0a3bd697074c1822edc0537 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 09:28:33 -0700 Subject: [PATCH 097/532] Remove javaProject/kotlinProject. --- .../com/beust/kobalt/plugin/java/JavaPlugin.kt | 11 ----------- .../beust/kobalt/plugin/kotlin/KotlinPlugin.kt | 15 --------------- 2 files changed, 26 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt index b0df157a..9f6108d2 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt @@ -5,7 +5,6 @@ import com.beust.kobalt.Variant import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.internal.BaseJvmPlugin -import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.misc.warn import java.io.File import javax.inject.Inject @@ -68,16 +67,6 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler, override va } -@Directive -fun javaProject(vararg projects: Project, init: Project.() -> Unit): Project { - return Project().apply { - warn("javaProject{} is deprecated, please use project{}") - init() - (Kobalt.findPlugin(JvmCompilerPlugin.PLUGIN_NAME) as JvmCompilerPlugin) - .addDependentProjects(this, projects.toList()) - } -} - class JavaConfig(val project: Project) { val compilerArgs = arrayListOf() fun args(vararg options: String) = compilerArgs.addAll(options) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 8f16a3d4..220be8a7 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -5,13 +5,11 @@ import com.beust.kobalt.Variant import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.internal.BaseJvmPlugin -import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.KotlinJarFiles import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.misc.KobaltExecutors -import com.beust.kobalt.misc.warn import javax.inject.Inject import javax.inject.Singleton @@ -131,19 +129,6 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen } } -/** - * @param projects: the list of projects that need to be built before this one. - */ -@Directive -fun kotlinProject(vararg projects: Project, init: Project.() -> Unit): Project { - return Project().apply { - warn("kotlinProject{} is deprecated, please use project{}") - init() - (Kobalt.findPlugin(JvmCompilerPlugin.PLUGIN_NAME) as JvmCompilerPlugin) - .addDependentProjects(this, projects.toList()) - } -} - class KotlinConfig(val project: Project) { val args = arrayListOf() fun args(vararg options: String) = args.addAll(options) From dbb06d0e79aa525ce8d1afa97d86bbc7f3689b15 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 10:06:17 -0700 Subject: [PATCH 098/532] Added test dependent projects. --- .../src/main/kotlin/com/beust/kobalt/api/Project.kt | 7 ++++++- .../com/beust/kobalt/internal/ParallelProjectRunner.kt | 2 +- .../com/beust/kobalt/internal/SequentialProjectRunner.kt | 2 +- .../main/kotlin/com/beust/kobalt/internal/TaskManager.kt | 4 ++-- .../kotlin/com/beust/kobalt/maven/DependencyManager.kt | 9 ++++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index e6796a9a..ddd58d36 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -26,6 +26,7 @@ open class Project( @Directive open var url: String? = null, @Directive open var pom: Model? = null, @Directive open var dependsOn: ArrayList = arrayListOf(), + @Directive open var testsDependOnProjects: ArrayList = arrayListOf(), @Directive open var packageName: String? = group) : IBuildConfig, IDependencyHolder by DependencyHolder() { @@ -33,13 +34,15 @@ open class Project( this.project = this } + fun allProjectDependedOn() = project.dependsOn + project.testsDependOnProjects + class ProjectExtra(project: Project) { var isDirty = false /** * @return true if any of the projects we depend on is dirty. */ - fun dependsOnDirtyProjects(project: Project) = project.dependsOn.any { it.projectExtra.isDirty } + fun dependsOnDirtyProjects(project: Project) = project.allProjectDependedOn().any { it.projectExtra.isDirty } } /** @@ -96,6 +99,8 @@ open class Project( val testDependencies : ArrayList = arrayListOf() val testProvidedDependencies : ArrayList = arrayListOf() + fun testsDependOnProjects(vararg projects: Project) = testsDependOnProjects.addAll(projects) + /** Used to disambiguate various name properties */ @Directive val projectName: String get() = name 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 7041c402..6a703a20 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 @@ -94,7 +94,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap().apply { projects.forEach { project -> addNode(ProjectTask(project, args.dryRun)) - project.dependsOn.forEach { + project.allProjectDependedOn().forEach { addEdge(ProjectTask(project, args.dryRun), ProjectTask(it, args.dryRun)) } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SequentialProjectRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SequentialProjectRunner.kt index 1f13626c..ec99b723 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SequentialProjectRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SequentialProjectRunner.kt @@ -39,7 +39,7 @@ class SequentialProjectRunner(val tasksByNames: (Project) -> ListMultimap 0) { klog(2, "Marking project $projectName as skipped") diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index 2139326c..541231fa 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -145,7 +145,7 @@ class TaskManager @Inject constructor(val args: Args, val topological = Topological().apply { projects.forEach { project -> addNode(project) - project.dependsOn.forEach { + project.allProjectDependedOn().forEach { addEdge(project, it) } } @@ -160,7 +160,7 @@ class TaskManager @Inject constructor(val args: Args, return result } else { val rootProject = projects.find { it.name == ti.project }!! - val allProjects = DynamicGraph.transitiveClosure(rootProject, { p -> p.dependsOn }) + val allProjects = DynamicGraph.transitiveClosure(rootProject, Project::allProjectDependedOn) val sortedProjects = sortProjectsTopologically(allProjects) val sortedMaps = sortedProjects.map { TaskInfo(it.name, "compile")} val result = sortedMaps.subList(0, sortedMaps.size - 1) + listOf(ti) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 14ae2c3d..b48822b0 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -228,13 +228,20 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, } } + val isTest = scopes.contains(Scope.TEST) + project.dependsOn.forEach { p -> maybeAddClassDir(KFiles.joinDir(p.directory, p.classesDir(context))) - val isTest = scopes.contains(Scope.TEST) if (isTest) maybeAddClassDir(KFiles.makeOutputTestDir(project).path) val otherDependencies = calculateDependencies(p, context, dependencyFilter, scopes) result.addAll(otherDependencies) + } + if (isTest) { + project.testsDependOnProjects.forEach { p -> + val otherDependencies = calculateDependencies(p, context, dependencyFilter, scopes) + result.addAll(otherDependencies) + } } return result } From c43967bec9cd688e5c439bc6713d18c1b05fcb7b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 12:05:28 -0700 Subject: [PATCH 099/532] Preserve dependency order. --- .../main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 15cd7fc3..7732774d 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 @@ -92,7 +92,7 @@ open class JvmCompilerPlugin @Inject constructor( scopes = listOf(Scope.TEST)) val compileDependencies = dependencyManager.calculateDependencies(project, context, scopes = listOf(Scope.COMPILE)) - val allDependencies = (compileDependencies + testDependencies).toHashSet() + val allDependencies = (testDependencies + compileDependencies).distinct() return testContributor.run(project, context, configName, allDependencies.toList()) } else { context.logger.log(project.name, 2, From a4282b299ab2ddbd98f56010975424fb97a7d538 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 13:14:25 -0700 Subject: [PATCH 100/532] 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 = From da3ad60423cc318256f38662eda244a201c2325e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 13:19:43 -0700 Subject: [PATCH 101/532] 1.0.19. --- 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 f92e14d5..51854da6 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.18 \ No newline at end of file +kobalt.version=1.0.19 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index bb9154b7..751c66c4 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.18 +kobalt.version=1.0.19 From 34185a6b2ad4716e2c3c54d96ea96d4c6679be15 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 14:38:43 -0700 Subject: [PATCH 102/532] Exclude tests that crash on TeamCity. --- .../com/beust/kobalt/misc/MavenResolverTest.kt | 2 +- src/test/resources/testng.xml | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/misc/MavenResolverTest.kt b/src/test/kotlin/com/beust/kobalt/misc/MavenResolverTest.kt index 45bccdcb..a0b4be9f 100644 --- a/src/test/kotlin/com/beust/kobalt/misc/MavenResolverTest.kt +++ b/src/test/kotlin/com/beust/kobalt/misc/MavenResolverTest.kt @@ -45,7 +45,7 @@ class MavenResolverTest { assertThat(result[0].artifact.version).isEqualTo(expectedVersion) } - @Test(dataProvider = "rangeProvider") + @Test(dataProvider = "rangeProvider", groups = arrayOf("mavenResolverBug")) fun kobaltRangeVersion(id: String, expectedVersion: String) { val artifact = resolver.resolveToArtifact(id) assertThat(artifact.version).isEqualTo(expectedVersion) diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml index 9d62b0ba..f37b9b23 100644 --- a/src/test/resources/testng.xml +++ b/src/test/resources/testng.xml @@ -1,12 +1,15 @@ - - - - - - - + + + + + + + + + + From b68ec2805066d21ef79141d4547fa472ce6052a6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 16:32:20 -0700 Subject: [PATCH 103/532] Colors. --- kobalt/src/Build.kt | 3 +- .../main/kotlin/com/beust/kobalt/AsciiArt.kt | 28 ++-- .../com/beust/kobalt/internal/TestNgRunner.kt | 128 +++++++++++++++++- 3 files changed, 143 insertions(+), 16 deletions(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 7f46d9d2..261f5b6e 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -110,7 +110,8 @@ val kobaltPluginApi = project { "org.eclipse.jgit:org.eclipse.jgit:4.5.0.201609210915-r", "org.slf4j:slf4j-simple:${Versions.slf4j}", *mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"), - "org.apache.maven:maven-aether-provider:3.3.9" + "org.apache.maven:maven-aether-provider:3.3.9", + "org.testng.testng-remote:testng-remote:1.3.0" ) exclude(*aether("impl", "spi", "util", "api")) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt index 6247caeb..e138fabc 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt @@ -17,16 +17,16 @@ class AsciiArt { companion object { private val BANNERS = arrayOf( " __ __ __ __ __ \n" + - " / //_/ ____ / /_ ____ _ / / / /_\n" + - " / ,< / __ \\ / __ \\ / __ `/ / / / __/\n" + - " / /| | / /_/ / / /_/ // /_/ / / / / /_ \n" + - " /_/ |_| \\____/ /_.___/ \\__,_/ /_/ \\__/ ", + " / //_/ ____ / /_ ____ _ / / / /_\n" + + " / ,< / __ \\ / __ \\ / __ `/ / / / __/\n" + + " / /| | / /_/ / / /_/ // /_/ / / / / /_ \n" + + " /_/ |_| \\____/ /_.___/ \\__,_/ /_/ \\__/ ", " _ __ _ _ _ \n" + - " | |/ / ___ | |__ __ _ | | | |_ \n" + - " | ' / / _ \\ | '_ \\ / _` | | | | __|\n" + - " | . \\ | (_) | | |_) | | (_| | | | | |_ \n" + - " |_|\\_\\ \\___/ |_.__/ \\__,_| |_| \\__| " + " | |/ / ___ | |__ __ _ | | | |_ \n" + + " | ' / / _ \\ | '_ \\ / _` | | | | __|\n" + + " | . \\ | (_) | | |_) | | (_| | | | | |_ \n" + + " |_|\\_\\ \\___/ |_.__/ \\__,_| |_| \\__| " ) val banner : String get() = BANNERS[Random().nextInt(BANNERS.size)] @@ -85,7 +85,7 @@ class AsciiArt { } fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, indent: Int = 0) - = logBox(listOf(s), bl, br, indent) + = logBox(listOf(s), bl, br, indent) fun fill(n: Int) = buildString { repeat(n, { append(" ")})}.toString() @@ -105,7 +105,7 @@ class AsciiArt { const val CYAN = "\u001B[36m" const val WHITE = "\u001B[37m" - private fun wrap(s: CharSequence, color: String) = color + s + RESET + fun wrap(s: CharSequence, color: String) = color + s + RESET private fun blue(s: CharSequence) = wrap(s, BLUE) private fun red(s: CharSequence) = wrap(s, RED) private fun yellow(s: CharSequence) = wrap(s, YELLOW) @@ -141,10 +141,10 @@ class AsciiTable { fun build() : String { val formattedHeaders = - headers.mapIndexed { index, s -> - val s2 = col(widths[index], s) - s2 - }.joinToString(vb) + headers.mapIndexed { index, s -> + val s2 = col(widths[index], s) + s2 + }.joinToString(vb) val result = StringBuffer().apply { append(AsciiArt.logBox(formattedHeaders, AsciiArt.bottomLeft2, AsciiArt.bottomRight2)) append("\n") diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index f43be88c..5f288204 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -1,12 +1,22 @@ package com.beust.kobalt.internal +import com.beust.kobalt.AsciiArt import com.beust.kobalt.TestConfig import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project +import com.beust.kobalt.maven.aether.AetherDependency import com.beust.kobalt.misc.KFiles +import com.beust.kobalt.misc.Versions +import com.beust.kobalt.misc.runCommand import com.beust.kobalt.misc.warn +import org.testng.remote.RemoteArgs +import org.testng.remote.strprotocol.JsonMessageSender +import org.testng.remote.strprotocol.MessageHelper +import org.testng.remote.strprotocol.MessageHub +import org.testng.remote.strprotocol.TestResultMessage import java.io.File +import java.io.IOException class TestNgRunner : GenericTestRunner() { @@ -39,7 +49,7 @@ class TestNgRunner : GenericTestRunner() { add("-testclass") add(testClasses.joinToString(",")) } else { - if (! testConfig.isDefault) warn("Couldn't find any test classes for ${project.name}") + if (!testConfig.isDefault) warn("Couldn't find any test classes for ${project.name}") // else do nothing: since the user didn't specify an explicit test{} directive, not finding // any test sources is not a problem } @@ -48,4 +58,120 @@ class TestNgRunner : GenericTestRunner() { addAll(testConfig.testArgs) } } + + val VERSION_6_10 = 600100000L + + override fun runTests(project: Project, context: KobaltContext, classpath: List, + configName: String): Boolean { + + val testngDependency = (project.testDependencies.filter { it.id.contains("testng") } + .firstOrNull() as AetherDependency).version + val testngDependencyVersion = Versions.toLongVersion(testngDependency) + val result = + if (testngDependencyVersion >= VERSION_6_10) { + displayPrettyColors(project, context, classpath) + } else { + super.runTests(project, context, classpath, configName) + } + return result + } + + fun displayPrettyColors(project: Project, context: KobaltContext, classpath: List) + : Boolean { + val port = 2345 + + val jf = context.dependencyManager.create("org.testng.testng-remote:testng-remote:1.3.0") + val tr = context.dependencyManager.create("org.testng.testng-remote:testng-remote6_10:1.3.0") + val testng = context.dependencyManager.create("org.testng:testng:6.10") + val dep1 = context.dependencyManager.transitiveClosure(listOf(jf, tr, testng)) + + val v = Versions.toLongVersion("6.10") + val cp = (classpath + dep1).map { it.jarFile.get() } + .joinToString(File.pathSeparator) + val passedArgs = listOf( + "-classpath", + cp, + "org.testng.remote.RemoteTestNG", + "-serport", port.toString(), + "-version", "6.10", + "-dontexit", + RemoteArgs.PROTOCOL, + "json", + "src/test/resources/testng.xml") + + Thread { + val exitCode = runCommand { + command = "java" + directory = File(project.directory) + args = passedArgs + } + }.start() + + // Thread { + // val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", + // "-version", "6.10", + // "src/test/resources/testng.xml") + // RemoteTestNG.main(args2) + // }.start() + + val mh = MessageHub(JsonMessageSender("localhost", port, true)) + mh.setDebug(true) + mh.initReceiver() + val passed = arrayListOf() + + data class FailedTest(val method: String, val cls: String, val stackTrace: String) + + val failed = arrayListOf() + var skipped = arrayListOf() + + fun d(n: Int, color: String) + = AsciiArt.wrap(String.format("%4d", n), color) + + fun red(s: String) = AsciiArt.wrap(s, AsciiArt.RED) + fun green(s: String) = AsciiArt.wrap(s, AsciiArt.GREEN) + fun yellow(s: String) = AsciiArt.wrap(s, AsciiArt.YELLOW) + + try { + var message = mh.receiveMessage() + println("") + println(green("PASSED") + " | " + red("FAILED") + " | " + yellow("SKIPPED")) + while (message != null) { + message = mh.receiveMessage() + if (message is TestResultMessage) { + when (message.result) { + MessageHelper.PASSED_TEST -> passed.add(message.name) + MessageHelper.FAILED_TEST -> failed.add(FailedTest(message.testClass, + message.method, message.stackTrace)) + MessageHelper.SKIPPED_TEST -> skipped.add(message.name) + } + } + print("\r " + d(passed.size, AsciiArt.GREEN) + + " | " + d(failed.size, AsciiArt.RED) + + " | " + d(skipped.size, AsciiArt.YELLOW)) + // Thread.sleep(500) + // print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size)) + // Thread.sleep(200) + } + } catch(ex: IOException) { + println("Exception: ${ex.message}") + } + println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size) + failed.forEach { + val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n")) + println(" " + it.cls + "." + it.method + "\n " + top) + } + return failed.isEmpty() && skipped.isEmpty() + } +} + +fun main(args: Array) { + fun d(n: Int, color: String) + = AsciiArt.wrap(String.format("%4d", n), color) + + println("PASSED | FAILED | SKIPPED") + repeat(20) { i -> + print("\r " + d(i, AsciiArt.GREEN) + " | " + d(i * 2, AsciiArt.RED) + " | " + d(i, AsciiArt.YELLOW)) + Thread.sleep(500) + } + println("") } From 64df5ea8dfce8b398c1bb36141a0278204d4eee8 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 16:34:46 -0700 Subject: [PATCH 104/532] Forgot the repo. --- kobalt/src/Build.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 261f5b6e..08006bbe 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -1,7 +1,6 @@ -import com.beust.kobalt.TaskResult +import com.beust.kobalt.* import com.beust.kobalt.api.Project import com.beust.kobalt.api.annotation.Task -import com.beust.kobalt.homeDir import com.beust.kobalt.plugin.application.application import com.beust.kobalt.plugin.java.javaCompiler import com.beust.kobalt.plugin.kotlin.kotlinCompiler @@ -9,8 +8,6 @@ import com.beust.kobalt.plugin.packaging.assemble import com.beust.kobalt.plugin.publish.autoGitTag import com.beust.kobalt.plugin.publish.bintray import com.beust.kobalt.plugin.publish.github -import com.beust.kobalt.project -import com.beust.kobalt.test import org.apache.maven.model.Developer import org.apache.maven.model.License import org.apache.maven.model.Model @@ -20,6 +17,10 @@ import java.nio.file.Files import java.nio.file.Paths import java.nio.file.StandardCopyOption +val bs = buildScript { + repos("http://dl.bintray.com/cbeust/maven") +} + object Versions { val okhttp = "3.2.0" val okio = "1.6.0" From f486bfbd93d7c0c09120d23197d1512d4a55807b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 16:49:26 -0700 Subject: [PATCH 105/532] Refactor. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 5f288204..19612c1c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -69,8 +69,10 @@ class TestNgRunner : GenericTestRunner() { val testngDependencyVersion = Versions.toLongVersion(testngDependency) val result = if (testngDependencyVersion >= VERSION_6_10) { + context.logger.log(project.name, 1, "Modern TestNG, displaying colors") displayPrettyColors(project, context, classpath) } else { + context.logger.log(project.name, 1, "Older TestNG ($testngDependencyVersion), using the old runner") super.runTests(project, context, classpath, configName) } return result @@ -80,13 +82,15 @@ class TestNgRunner : GenericTestRunner() { : Boolean { val port = 2345 - val jf = context.dependencyManager.create("org.testng.testng-remote:testng-remote:1.3.0") - val tr = context.dependencyManager.create("org.testng.testng-remote:testng-remote6_10:1.3.0") - val testng = context.dependencyManager.create("org.testng:testng:6.10") - val dep1 = context.dependencyManager.transitiveClosure(listOf(jf, tr, testng)) + val dep = with(context.dependencyManager) { + val jf = create("org.testng.testng-remote:testng-remote:1.3.0") + val tr = create("org.testng.testng-remote:testng-remote6_10:1.3.0") + val testng = create("org.testng:testng:6.10") + transitiveClosure(listOf(jf, tr, testng)) + } val v = Versions.toLongVersion("6.10") - val cp = (classpath + dep1).map { it.jarFile.get() } + val cp = (classpath + dep).map { it.jarFile.get() } .joinToString(File.pathSeparator) val passedArgs = listOf( "-classpath", From 25df7bed387315a7b4ae470268f9fbb85ee54309 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 16:55:59 -0700 Subject: [PATCH 106/532] Logs. --- .../src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt | 2 ++ .../src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index a4796e83..866eb8d4 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -98,6 +98,8 @@ abstract class GenericTestRunner: ITestRunnerContributor { configName: String) : Boolean { var result = false + context.logger.log(project.name, 1, "Running default TestNG runner") + val testConfig = project.testConfigs.firstOrNull { it.name == configName } if (testConfig != null) { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 19612c1c..e8ea2291 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -64,6 +64,8 @@ class TestNgRunner : GenericTestRunner() { override fun runTests(project: Project, context: KobaltContext, classpath: List, configName: String): Boolean { + context.logger.log(project.name, 1, "Running enhanced TestNG runner") + val testngDependency = (project.testDependencies.filter { it.id.contains("testng") } .firstOrNull() as AetherDependency).version val testngDependencyVersion = Versions.toLongVersion(testngDependency) From 47bdbf04eef6752ae96133979f5b55fb7a7895f6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 23:48:03 -0700 Subject: [PATCH 107/532] Distinct. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 2 +- .../kotlin/com/beust/kobalt/misc/Versions.kt | 39 ++++++++++++++++++- .../com/beust/kobalt/internal/VersionTest.kt | 38 ++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index e8ea2291..0e1724d2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -92,7 +92,7 @@ class TestNgRunner : GenericTestRunner() { } val v = Versions.toLongVersion("6.10") - val cp = (classpath + dep).map { it.jarFile.get() } + val cp = (classpath + dep).distinct().map { it.jarFile.get() } .joinToString(File.pathSeparator) val passedArgs = listOf( "-classpath", diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt index f2141e4d..f915723f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt @@ -2,10 +2,47 @@ package com.beust.kobalt.misc import com.beust.kobalt.maven.MavenId import com.google.common.base.CharMatcher +import java.lang.Character +import java.lang.IllegalStateException +import java.lang.Integer +import java.lang.Math +import java.lang.NumberFormatException import java.math.BigInteger import java.util.* -public class Versions { +/** + * Allow to compare string versions. + */ +class StringVersion(val version: String) { + val array = version.split('.') + + enum class Compare { LT, EQ, GT } + + fun compareTo(other: String) : Compare { + val s1 = arrayListOf().apply { addAll(version.split('.')) } + val s2 = arrayListOf().apply { addAll(other.split('.')) } + val max = Math.max(s1.size, s2.size) + val shorterList : ArrayList = if (s1.size == max) s2 else s1 + repeat(max - shorterList.size) { + shorterList.add("0") + } + + repeat(max) { index -> + try { + val v1 = Integer.parseInt(s1[index]) + val v2 = Integer.parseInt(s2[index]) + if (v1 < v2) return Compare.LT + else if (v1 > v2) return Compare.GT + } catch(ex: NumberFormatException) { + warn("Couldn't parse version $version or $other") + return Compare.LT + } + } + return Compare.EQ + } +} + +class Versions { companion object { /** * Turn "6.9.4" into 600090004 diff --git a/src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt b/src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt index 7a6e12b5..ab275e7f 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt @@ -1,10 +1,12 @@ package com.beust.kobalt.internal +import com.beust.kobalt.misc.StringVersion import com.beust.kobalt.misc.Versions import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.DataProvider import org.testng.annotations.Test + /** * Make sure we parse version numbers correctly. */ @@ -22,4 +24,40 @@ class VersionTest { fun versionConversionShouldWork(version: String, expected: Long) { assertThat(Versions.toLongVersion(version)).isEqualTo(expected) } + + @DataProvider + fun versionsEqual() : Array> + = arrayOf( + arrayOf("1", "1"), + arrayOf("1.0", "1"), + arrayOf("1.0.0", "1"), + arrayOf("1.0", "1.0.0") + ) + + @Test(dataProvider = "versionsEqual") + fun versionComparisonsEqual(v1: String, v2: String) { + assertThat(StringVersion(v1).compareTo(v2)).isEqualTo(StringVersion.Compare.EQ) + assertThat(StringVersion(v2).compareTo(v1)).isEqualTo(StringVersion.Compare.EQ) + } + + @DataProvider + fun versionsNotEqual() : Array> + = arrayOf( + arrayOf("1", "1.2.3", StringVersion.Compare.LT), + arrayOf("1.2", "1.2.3", StringVersion.Compare.LT), + arrayOf("1.2.2", "1.2.3", StringVersion.Compare.LT), + arrayOf("1.2.4", "1.2.3", StringVersion.Compare.GT), + arrayOf("1", "1.2.3.4", StringVersion.Compare.LT), + arrayOf("1.2", "1.2.3.4", StringVersion.Compare.LT), + arrayOf("1.2.3", "1.2.3.4", StringVersion.Compare.LT), + arrayOf("1.2.3.3", "1.2.3.4", StringVersion.Compare.LT), + arrayOf("1.2.3.5", "1.2.3.4", StringVersion.Compare.GT) + ) + + @Test(dataProvider = "versionsNotEqual") + fun versionComparisonsNotEqual(v1: String, v2: String, expected: StringVersion.Compare) { + assertThat(StringVersion(v1).compareTo(v2)).isEqualTo(expected) + assertThat(StringVersion(v2).compareTo(v1)).isEqualTo( + if (expected == StringVersion.Compare.LT) StringVersion.Compare.GT else StringVersion.Compare.LT) + } } From 850e826d7f86e3249410874dd307b9c63b58312d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 23:48:12 -0700 Subject: [PATCH 108/532] Forgot a dependency. --- kobalt/src/Build.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 08006bbe..a7767c10 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -112,7 +112,8 @@ val kobaltPluginApi = project { "org.slf4j:slf4j-simple:${Versions.slf4j}", *mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"), "org.apache.maven:maven-aether-provider:3.3.9", - "org.testng.testng-remote:testng-remote:1.3.0" + "org.testng.testng-remote:testng-remote:1.3.0", + "org.testng:testng:6.10" ) exclude(*aether("impl", "spi", "util", "api")) } From 71d4cce9996854b685c202ecb75aab72fce249a4 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 21 Mar 2017 23:55:00 -0700 Subject: [PATCH 109/532] 1.0.20. --- 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 51854da6..1ae06062 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.19 \ No newline at end of file +kobalt.version=1.0.20 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 751c66c4..e061eabf 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.19 +kobalt.version=1.0.20 From c7714a5286215f769c419aef1200f4b9227196fc Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 22 Mar 2017 09:26:24 -0700 Subject: [PATCH 110/532] Better StringVersion. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 7 +- .../com/beust/kobalt/maven/LocalRepo.kt | 40 +---------- .../kobalt/maven/aether/AetherDependency.kt | 5 +- .../com/beust/kobalt/misc/CheckVersions.kt | 2 +- .../com/beust/kobalt/misc/StringVersion.kt | 46 ++++++++++++ .../kotlin/com/beust/kobalt/misc/Versions.kt | 71 +------------------ .../com/beust/kobalt/app/UpdateKobalt.kt | 4 +- .../kobalt/app/remote/RemoteDependencyData.kt | 4 +- .../kobalt/internal/StringVersionTest.kt | 56 +++++++++++++++ .../com/beust/kobalt/internal/VersionTest.kt | 63 ---------------- .../com/beust/kobalt/maven/DependencyTest.kt | 10 +-- 11 files changed, 119 insertions(+), 189 deletions(-) create mode 100644 modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/StringVersion.kt create mode 100644 src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt delete mode 100644 src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 0e1724d2..10648b27 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -7,7 +7,7 @@ import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.maven.aether.AetherDependency import com.beust.kobalt.misc.KFiles -import com.beust.kobalt.misc.Versions +import com.beust.kobalt.misc.StringVersion import com.beust.kobalt.misc.runCommand import com.beust.kobalt.misc.warn import org.testng.remote.RemoteArgs @@ -59,7 +59,7 @@ class TestNgRunner : GenericTestRunner() { } } - val VERSION_6_10 = 600100000L + val VERSION_6_10 = StringVersion("6.10") override fun runTests(project: Project, context: KobaltContext, classpath: List, configName: String): Boolean { @@ -68,7 +68,7 @@ class TestNgRunner : GenericTestRunner() { val testngDependency = (project.testDependencies.filter { it.id.contains("testng") } .firstOrNull() as AetherDependency).version - val testngDependencyVersion = Versions.toLongVersion(testngDependency) + val testngDependencyVersion = StringVersion(testngDependency) val result = if (testngDependencyVersion >= VERSION_6_10) { context.logger.log(project.name, 1, "Modern TestNG, displaying colors") @@ -91,7 +91,6 @@ class TestNgRunner : GenericTestRunner() { transitiveClosure(listOf(jf, tr, testng)) } - val v = Versions.toLongVersion("6.10") val cp = (classpath + dep).distinct().map { it.jarFile.get() } .joinToString(File.pathSeparator) val passedArgs = listOf( diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt index 21d36172..35f8c50a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt @@ -1,11 +1,8 @@ package com.beust.kobalt.maven import com.beust.kobalt.internal.KobaltSettings -import com.beust.kobalt.misc.KFiles -import com.beust.kobalt.misc.Versions import com.google.inject.Inject import java.io.File -import java.util.* import javax.inject.Singleton @Singleton @@ -13,42 +10,7 @@ open class LocalRepo @Inject constructor(val kobaltSettings: KobaltSettings) { val localRepo: File get() = kobaltSettings.localCache - fun existsPom(d: LocalDep, v: String) : Boolean { - return File(d.toAbsolutePomFile(v)).exists() - } - - fun existsJar(d: LocalDep, v: String) : Boolean { - return File(d.toAbsoluteJarFilePath(v)).exists() - } - - /** - * If the dependency is local, return the correct version for it - */ - fun findLocalVersion(groupId: String, artifactId: String, packaging: String? = null) : String? { - // No version: look at all the directories under group/artifactId, pick the latest and see - // if it contains a maven and jar file - val dir = toFullPath(KFiles.joinDir(groupId.replace(".", File.separator), artifactId)) - val files = File(dir).listFiles() - - if (files != null) { - val directories = files.filter { it.isDirectory } - if (directories.size > 0) { - Collections.sort(directories, { f1, f2 -> - val v1 = Versions.toLongVersion(f1.name) - val v2 = Versions.toLongVersion(f2.name) - v2.compareTo(v1) // we want the most recent at position 0 - }) - val result = directories[0].name - val newDep = LocalDep(MavenId.create(groupId, artifactId, packaging, null, result), this) - if (existsPom(newDep, result) && existsJar(newDep, result)) { - return result - } - } - } - return null - } - - fun toFullPath(path: String) = File(localRepo, path).absolutePath + fun toFullPath(path: String): String = File(localRepo, path).absolutePath } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt index 5cd532fe..f7de93a2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/AetherDependency.kt @@ -7,7 +7,7 @@ import com.beust.kobalt.maven.CompletedFuture import com.beust.kobalt.maven.LocalDep import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.MavenId -import com.beust.kobalt.misc.Versions +import com.beust.kobalt.misc.StringVersion import com.beust.kobalt.misc.warn import org.eclipse.aether.artifact.Artifact import java.io.File @@ -69,8 +69,7 @@ class AetherDependency(val artifact: Artifact, override val optional: Boolean = override val excluded = arrayListOf() override fun compareTo(other: AetherDependency): Int { - return Versions.toLongVersion(artifact.version).compareTo(Versions.toLongVersion( - other.artifact.version)) + return StringVersion(artifact.version).compareTo(StringVersion(other.artifact.version)) } override fun hashCode() = id.hashCode() diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index f046322d..f6c6a49e 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -34,7 +34,7 @@ class CheckVersions @Inject constructor(val depManager: DependencyManager, versions?.highestVersion.toString() } if (highest != dep.id - && Versions.toLongVersion(highest) > Versions.toLongVersion(dep.version)) { + && StringVersion(highest) > StringVersion(dep.version)) { newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest) } } catch(e: KobaltException) { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/StringVersion.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/StringVersion.kt new file mode 100644 index 00000000..fc620554 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/StringVersion.kt @@ -0,0 +1,46 @@ +package com.beust.kobalt.misc + +import java.lang.Long +import java.lang.NumberFormatException +import java.util.* + +/** + * Compare string versions, e.g. "1.2.0", "0.9", etc... + */ +class StringVersion(val version: String) : Comparable { + override fun compareTo(other: StringVersion): Int { + val s1 = arrayListOf().apply { addAll(version.split('.')) } + val s2 = arrayListOf().apply { addAll(other.version.split('.')) } + + // Normalize both strings, so they have the same length, e.g. 1 -> 1.0.0 + val max = Math.max(s1.size, s2.size) + val shorterList : ArrayList = if (s1.size == max) s2 else s1 + repeat(max - shorterList.size) { + shorterList.add("0") + } + + // Compare each section + repeat(max) { index -> + try { + fun parse(s: String) = Long.parseLong(s.filter(Char::isDigit)) + + val v1 = parse(s1[index]) + val v2 = parse(s2[index]) + if (v1 < v2) return -1 + else if (v1 > v2) return 1 + } catch(ex: NumberFormatException) { + warn("Couldn't parse version $version or $other") + return -1 + } + } + return 0 + } + + override fun equals(other: Any?) = + if (other is StringVersion) this.compareTo(other) == 0 + else false + + override fun hashCode() = version.hashCode() + + override fun toString() = version +} diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt index f915723f..205c2ced 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt @@ -1,79 +1,10 @@ package com.beust.kobalt.misc import com.beust.kobalt.maven.MavenId -import com.google.common.base.CharMatcher -import java.lang.Character -import java.lang.IllegalStateException -import java.lang.Integer -import java.lang.Math -import java.lang.NumberFormatException +import java.lang.* import java.math.BigInteger import java.util.* -/** - * Allow to compare string versions. - */ -class StringVersion(val version: String) { - val array = version.split('.') - - enum class Compare { LT, EQ, GT } - - fun compareTo(other: String) : Compare { - val s1 = arrayListOf().apply { addAll(version.split('.')) } - val s2 = arrayListOf().apply { addAll(other.split('.')) } - val max = Math.max(s1.size, s2.size) - val shorterList : ArrayList = if (s1.size == max) s2 else s1 - repeat(max - shorterList.size) { - shorterList.add("0") - } - - repeat(max) { index -> - try { - val v1 = Integer.parseInt(s1[index]) - val v2 = Integer.parseInt(s2[index]) - if (v1 < v2) return Compare.LT - else if (v1 > v2) return Compare.GT - } catch(ex: NumberFormatException) { - warn("Couldn't parse version $version or $other") - return Compare.LT - } - } - return Compare.EQ - } -} - -class Versions { - companion object { - /** - * Turn "6.9.4" into 600090004 - */ - fun toLongVersion(version: String) : Long { - val count = version.countChar('.') - val normalizedVersion = - if (count == 2) version else if (count == 1) version + ".0" - else version + ".0.0" - - fun parseLong(s: String, radix: Int) : Long { - try { - return java.lang.Long.parseLong(s, radix) - } catch(ex: NumberFormatException) { - warn("Couldn't parse version \"$version\"") - return 0L - } - } - - return normalizedVersion - .split('.') - .take(3) - .map { - val s = CharMatcher.inRange('0', '9').or(CharMatcher.`is`('.')).retainFrom(it) - parseLong(s, 10) - } - .fold(0L, { n, s -> s + n * 10000 }) - } - } -} - class Version(val version: String, val snapshotTimestamp: String? = null): Comparable { companion object { diff --git a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index 838d37f1..b4528270 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -39,8 +39,8 @@ class UpdateKobalt @Inject constructor(val github: GithubApi2, val wrapperProper try { val latestVersionString = latestVersionFuture.get() - val latestVersion = Versions.toLongVersion(latestVersionString) - val current = Versions.toLongVersion(Kobalt.version) + val latestVersion = StringVersion(latestVersionString) + val current = StringVersion(Kobalt.version) val distFile = File(KFiles.distributionsDir) if (latestVersion > current) { if (distFile.exists()) { diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt index 73aca2c5..68bb5914 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt @@ -12,7 +12,7 @@ import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors -import com.beust.kobalt.misc.Versions +import com.beust.kobalt.misc.StringVersion import com.beust.kobalt.misc.log import com.google.inject.Inject import java.io.File @@ -90,7 +90,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v val currentLatest = latestVersions[shortId] if (currentLatest == null) latestVersions[shortId] = mid.version!! else mid.version?.let { v -> - if (Versions.toLongVersion(currentLatest) < Versions.toLongVersion(v)) { + if (StringVersion(currentLatest) < StringVersion(v)) { latestVersions[shortId] = v } } diff --git a/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt b/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt new file mode 100644 index 00000000..fa5596e1 --- /dev/null +++ b/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt @@ -0,0 +1,56 @@ +package com.beust.kobalt.internal + +import com.beust.kobalt.misc.StringVersion +import org.assertj.core.api.Assertions.assertThat +import org.testng.annotations.DataProvider +import org.testng.annotations.Test + + +/** + * Make sure we parse version numbers correctly. + */ +class StringVersionTest { + + @DataProvider + fun versionsEqual() : Array> + = arrayOf( + arrayOf("1.0", "1"), + arrayOf("1", "1"), + arrayOf("1.0.0", "1"), + arrayOf("1.0", "1.0.0") + ) + + @Test(dataProvider = "versionsEqual") + fun versionComparisonsEqual(v1: String, v2: String) { + val sv1 = StringVersion(v1) + val sv2 = StringVersion(v2) + assertThat(sv1).isEqualTo(sv2) + assertThat(sv2).isEqualTo(sv1) + } + + @DataProvider + fun versionsNotEqual() : Array> + = arrayOf( + arrayOf("0.9", "1"), + arrayOf("0.9.2", "1"), + arrayOf("1", "1.2.3"), + arrayOf("1.2", "1.2.3"), + arrayOf("1.2.2", "1.2.3"), + arrayOf("1.2.3", "1.2.4"), + arrayOf("1", "1.2.3.4"), + arrayOf("1.2", "1.2.3.4"), + arrayOf("1.2.3", "1.2.3.4"), + arrayOf("1.2.3.3", "1.2.3.4"), + arrayOf("1.2.3.4", "1.2.3.5"), + arrayOf("4.5.0.201609210915-r", "4.5.0.201609210916-r") + ) + + @Test(dataProvider = "versionsNotEqual") + fun versionComparisonsNotEqual(v1: String, v2: String) { + val sv1 = StringVersion(v1) + val sv2 = StringVersion(v2) + assertThat(sv1).isLessThan(sv2) + assertThat(sv2).isGreaterThan(sv1) + assertThat(sv1).isNotEqualTo(sv2) + } +} diff --git a/src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt b/src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt deleted file mode 100644 index ab275e7f..00000000 --- a/src/test/kotlin/com/beust/kobalt/internal/VersionTest.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.beust.kobalt.internal - -import com.beust.kobalt.misc.StringVersion -import com.beust.kobalt.misc.Versions -import org.assertj.core.api.Assertions.assertThat -import org.testng.annotations.DataProvider -import org.testng.annotations.Test - - -/** - * Make sure we parse version numbers correctly. - */ -class VersionTest { - - @DataProvider - fun dp() : Array> - = arrayOf( - arrayOf("0.938", 9380000), - arrayOf("1.2", 100020000L), - arrayOf("1.2.3", 100020003L) - ) - - @Test(dataProvider = "dp") - fun versionConversionShouldWork(version: String, expected: Long) { - assertThat(Versions.toLongVersion(version)).isEqualTo(expected) - } - - @DataProvider - fun versionsEqual() : Array> - = arrayOf( - arrayOf("1", "1"), - arrayOf("1.0", "1"), - arrayOf("1.0.0", "1"), - arrayOf("1.0", "1.0.0") - ) - - @Test(dataProvider = "versionsEqual") - fun versionComparisonsEqual(v1: String, v2: String) { - assertThat(StringVersion(v1).compareTo(v2)).isEqualTo(StringVersion.Compare.EQ) - assertThat(StringVersion(v2).compareTo(v1)).isEqualTo(StringVersion.Compare.EQ) - } - - @DataProvider - fun versionsNotEqual() : Array> - = arrayOf( - arrayOf("1", "1.2.3", StringVersion.Compare.LT), - arrayOf("1.2", "1.2.3", StringVersion.Compare.LT), - arrayOf("1.2.2", "1.2.3", StringVersion.Compare.LT), - arrayOf("1.2.4", "1.2.3", StringVersion.Compare.GT), - arrayOf("1", "1.2.3.4", StringVersion.Compare.LT), - arrayOf("1.2", "1.2.3.4", StringVersion.Compare.LT), - arrayOf("1.2.3", "1.2.3.4", StringVersion.Compare.LT), - arrayOf("1.2.3.3", "1.2.3.4", StringVersion.Compare.LT), - arrayOf("1.2.3.5", "1.2.3.4", StringVersion.Compare.GT) - ) - - @Test(dataProvider = "versionsNotEqual") - fun versionComparisonsNotEqual(v1: String, v2: String, expected: StringVersion.Compare) { - assertThat(StringVersion(v1).compareTo(v2)).isEqualTo(expected) - assertThat(StringVersion(v2).compareTo(v1)).isEqualTo( - if (expected == StringVersion.Compare.LT) StringVersion.Compare.GT else StringVersion.Compare.LT) - } -} diff --git a/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt index f52f9518..9cbf3ce1 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt @@ -2,7 +2,7 @@ package com.beust.kobalt.maven import com.beust.kobalt.TestModule import com.beust.kobalt.misc.KobaltExecutors -import com.beust.kobalt.misc.Versions +import com.beust.kobalt.misc.StringVersion import org.testng.Assert import org.testng.annotations.* import java.util.concurrent.ExecutorService @@ -40,10 +40,10 @@ class DependencyTest @Inject constructor(val executors: KobaltExecutors) { @Test(dataProvider = "dpVersions") fun versionSorting(k: String, v: String) { - val dep1 = Versions.toLongVersion(k) - val dep2 = Versions.toLongVersion(v) - Assert.assertTrue(dep1.compareTo(dep2) < 0) - Assert.assertTrue(dep2.compareTo(dep1) > 0) + val dep1 = StringVersion(k) + val dep2 = StringVersion(v) + Assert.assertTrue(dep1 < dep2) + Assert.assertTrue(dep2 > dep1) } } From 3b83d8d5d9aa6c5b2cc2c82883e8439e357e56de Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 22 Mar 2017 09:36:43 -0700 Subject: [PATCH 111/532] More remote runners. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 10648b27..fe99ba82 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -68,25 +68,38 @@ class TestNgRunner : GenericTestRunner() { val testngDependency = (project.testDependencies.filter { it.id.contains("testng") } .firstOrNull() as AetherDependency).version - val testngDependencyVersion = StringVersion(testngDependency) + val remoteRunnerVersion = findRemoteRunnerVersion(testngDependency) val result = - if (testngDependencyVersion >= VERSION_6_10) { + if (remoteRunnerVersion != null) { context.logger.log(project.name, 1, "Modern TestNG, displaying colors") - displayPrettyColors(project, context, classpath) + displayPrettyColors(project, context, classpath, remoteRunnerVersion) } else { - context.logger.log(project.name, 1, "Older TestNG ($testngDependencyVersion), using the old runner") + context.logger.log(project.name, 1, "Older TestNG ($testngDependency), using the old runner") super.runTests(project, context, classpath, configName) } return result } - fun displayPrettyColors(project: Project, context: KobaltContext, classpath: List) + private fun findRemoteRunnerVersion(testngVersion: String) : String? { + val tng = StringVersion(testngVersion) + val result = + if (tng >= VERSION_6_10) "testng-remote6_10" + else if (tng >= StringVersion("6.9.10")) "testng-remote6_9_10" + else if (tng >= StringVersion("6.9.7")) "testng-remote6_9_7" + else if (tng >= StringVersion("6.5.1")) "testng-remote6_5_0" + else if (tng >= StringVersion("6.0")) "testng-remote6_0" + else null + return result + } + + fun displayPrettyColors(project: Project, context: KobaltContext, classpath: List, + remoteRunnerVersion: String?) : Boolean { val port = 2345 val dep = with(context.dependencyManager) { val jf = create("org.testng.testng-remote:testng-remote:1.3.0") - val tr = create("org.testng.testng-remote:testng-remote6_10:1.3.0") + val tr = create("org.testng.testng-remote:$remoteRunnerVersion:1.3.0") val testng = create("org.testng:testng:6.10") transitiveClosure(listOf(jf, tr, testng)) } @@ -105,7 +118,7 @@ class TestNgRunner : GenericTestRunner() { "src/test/resources/testng.xml") Thread { - val exitCode = runCommand { + runCommand { command = "java" directory = File(project.directory) args = passedArgs @@ -127,7 +140,7 @@ class TestNgRunner : GenericTestRunner() { data class FailedTest(val method: String, val cls: String, val stackTrace: String) val failed = arrayListOf() - var skipped = arrayListOf() + val skipped = arrayListOf() fun d(n: Int, color: String) = AsciiArt.wrap(String.format("%4d", n), color) @@ -153,9 +166,6 @@ class TestNgRunner : GenericTestRunner() { print("\r " + d(passed.size, AsciiArt.GREEN) + " | " + d(failed.size, AsciiArt.RED) + " | " + d(skipped.size, AsciiArt.YELLOW)) - // Thread.sleep(500) - // print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size)) - // Thread.sleep(200) } } catch(ex: IOException) { println("Exception: ${ex.message}") From 6c16c59aa63858952a875c15ccde2a83dd156faa Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 22 Mar 2017 10:37:52 -0700 Subject: [PATCH 112/532] Disable new runner for now. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 76 +++++++++++-------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index fe99ba82..f381117d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -26,7 +26,7 @@ class TestNgRunner : GenericTestRunner() { override val annotationPackage = "org.testng" - fun defaultOutput(project: Project) = KFiles.joinDir(KFiles.KOBALT_BUILD_DIR, project.buildDirectory, "test-output") + fun defaultOutput(project: Project) = KFiles.joinDir(project.buildDirectory, "test-output") override fun args(project: Project, context: KobaltContext, classpath: List, testConfig: TestConfig) = arrayListOf().apply { @@ -61,61 +61,73 @@ class TestNgRunner : GenericTestRunner() { val VERSION_6_10 = StringVersion("6.10") - override fun runTests(project: Project, context: KobaltContext, classpath: List, + fun _runTests(project: Project, context: KobaltContext, classpath: List, configName: String): Boolean { - context.logger.log(project.name, 1, "Running enhanced TestNG runner") + val testConfig = project.testConfigs.firstOrNull { it.name == configName } - val testngDependency = (project.testDependencies.filter { it.id.contains("testng") } - .firstOrNull() as AetherDependency).version - val remoteRunnerVersion = findRemoteRunnerVersion(testngDependency) - val result = - if (remoteRunnerVersion != null) { + if (testConfig != null) { + context.logger.log(project.name, 1, "Running enhanced TestNG runner") + + val testngDependency = (project.testDependencies.filter { it.id.contains("testng") } + .firstOrNull() as AetherDependency).version + val versions = findRemoteRunnerVersion(testngDependency) + val result = + if (versions != null) { context.logger.log(project.name, 1, "Modern TestNG, displaying colors") - displayPrettyColors(project, context, classpath, remoteRunnerVersion) + displayPrettyColors(project, context, classpath, testConfig, versions) } else { context.logger.log(project.name, 1, "Older TestNG ($testngDependency), using the old runner") super.runTests(project, context, classpath, configName) } - return result + return result + } else { + return true + } } - private fun findRemoteRunnerVersion(testngVersion: String) : String? { + private fun findRemoteRunnerVersion(testngVersion: String) : Pair? { val tng = StringVersion(testngVersion) val result = - if (tng >= VERSION_6_10) "testng-remote6_10" - else if (tng >= StringVersion("6.9.10")) "testng-remote6_9_10" - else if (tng >= StringVersion("6.9.7")) "testng-remote6_9_7" - else if (tng >= StringVersion("6.5.1")) "testng-remote6_5_0" - else if (tng >= StringVersion("6.0")) "testng-remote6_0" + if (tng >= VERSION_6_10) Pair(testngVersion, "testng-remote6_10") + else if (tng >= StringVersion("6.9.10")) Pair("6.9.10", "testng-remote6_9_10") + else if (tng >= StringVersion("6.9.7")) Pair("6.9.7", "testng-remote6_9_7") + else if (tng >= StringVersion("6.5.1")) Pair("6.5.1", "testng-remote6_5_0") + else if (tng >= StringVersion("6.0")) Pair("6.0", "testng-remote6_0") else null return result } - fun displayPrettyColors(project: Project, context: KobaltContext, classpath: List, - remoteRunnerVersion: String?) - : Boolean { + private fun displayPrettyColors(project: Project, context: KobaltContext, + classpath: List, testConfig: TestConfig, versions: Pair): Boolean { val port = 2345 + val testngVersion = versions.first + val remoteRunnerVersion = versions.second val dep = with(context.dependencyManager) { val jf = create("org.testng.testng-remote:testng-remote:1.3.0") val tr = create("org.testng.testng-remote:$remoteRunnerVersion:1.3.0") val testng = create("org.testng:testng:6.10") - transitiveClosure(listOf(jf, tr, testng)) + transitiveClosure(listOf(jf, tr /*, testng */)) } val cp = (classpath + dep).distinct().map { it.jarFile.get() } .joinToString(File.pathSeparator) - val passedArgs = listOf( - "-classpath", - cp, + val calculatedArgs = args(project, context, classpath, testConfig) + + val jvmArgs = arrayListOf("-classpath", cp) + if (testConfig.jvmArgs.any()) { + jvmArgs.addAll(testConfig.jvmArgs) + } + val remoteArgs = listOf( "org.testng.remote.RemoteTestNG", "-serport", port.toString(), - "-version", "6.10", + "-version", testngVersion, "-dontexit", RemoteArgs.PROTOCOL, - "json", - "src/test/resources/testng.xml") + "json") + + val passedArgs = jvmArgs + remoteArgs + calculatedArgs Thread { runCommand { @@ -125,12 +137,12 @@ class TestNgRunner : GenericTestRunner() { } }.start() - // Thread { - // val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", - // "-version", "6.10", - // "src/test/resources/testng.xml") - // RemoteTestNG.main(args2) - // }.start() +// Thread { +// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", +// "-version", "6.10", +// "src/test/resources/testng.xml") +// RemoteTestNG.main(args2) +// }.start() val mh = MessageHub(JsonMessageSender("localhost", port, true)) mh.setDebug(true) From 873aea5d5ff6aa6f04fcdf691e1dff16f60750f3 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 22 Mar 2017 14:12:07 -0700 Subject: [PATCH 113/532] Refactor. --- .../com/beust/kobalt/internal/TestNgRunner.kt | 92 ++++++++++--------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index f381117d..5d29d19e 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -62,6 +62,7 @@ class TestNgRunner : GenericTestRunner() { val VERSION_6_10 = StringVersion("6.10") fun _runTests(project: Project, context: KobaltContext, classpath: List, +// override fun runTests(project: Project, context: KobaltContext, classpath: List, configName: String): Boolean { val testConfig = project.testConfigs.firstOrNull { it.name == configName } @@ -72,8 +73,9 @@ class TestNgRunner : GenericTestRunner() { val testngDependency = (project.testDependencies.filter { it.id.contains("testng") } .firstOrNull() as AetherDependency).version val versions = findRemoteRunnerVersion(testngDependency) + val useOldRunner = System.getProperty("testng.oldRunner") != null val result = - if (versions != null) { + if (versions != null && ! useOldRunner) { context.logger.log(project.name, 1, "Modern TestNG, displaying colors") displayPrettyColors(project, context, classpath, testConfig, versions) } else { @@ -101,48 +103,7 @@ class TestNgRunner : GenericTestRunner() { private fun displayPrettyColors(project: Project, context: KobaltContext, classpath: List, testConfig: TestConfig, versions: Pair): Boolean { val port = 2345 - - val testngVersion = versions.first - val remoteRunnerVersion = versions.second - val dep = with(context.dependencyManager) { - val jf = create("org.testng.testng-remote:testng-remote:1.3.0") - val tr = create("org.testng.testng-remote:$remoteRunnerVersion:1.3.0") - val testng = create("org.testng:testng:6.10") - transitiveClosure(listOf(jf, tr /*, testng */)) - } - - val cp = (classpath + dep).distinct().map { it.jarFile.get() } - .joinToString(File.pathSeparator) - val calculatedArgs = args(project, context, classpath, testConfig) - - val jvmArgs = arrayListOf("-classpath", cp) - if (testConfig.jvmArgs.any()) { - jvmArgs.addAll(testConfig.jvmArgs) - } - val remoteArgs = listOf( - "org.testng.remote.RemoteTestNG", - "-serport", port.toString(), - "-version", testngVersion, - "-dontexit", - RemoteArgs.PROTOCOL, - "json") - - val passedArgs = jvmArgs + remoteArgs + calculatedArgs - - Thread { - runCommand { - command = "java" - directory = File(project.directory) - args = passedArgs - } - }.start() - -// Thread { -// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", -// "-version", "6.10", -// "src/test/resources/testng.xml") -// RemoteTestNG.main(args2) -// }.start() +// launchRemoteServer(project, context, classpath, testConfig, versions, port) val mh = MessageHub(JsonMessageSender("localhost", port, true)) mh.setDebug(true) @@ -189,6 +150,51 @@ class TestNgRunner : GenericTestRunner() { } return failed.isEmpty() && skipped.isEmpty() } + + fun launchRemoteServer(project: Project, context: KobaltContext, classpath: List, + testConfig: TestConfig, versions: Pair, port: Int) { + val testngVersion = versions.first + val remoteRunnerVersion = versions.second + val dep = with(context.dependencyManager) { + val jf = create("org.testng.testng-remote:testng-remote:1.3.0") + val tr = create("org.testng.testng-remote:$remoteRunnerVersion:1.3.0") + val testng = create("org.testng:testng:6.10") + transitiveClosure(kotlin.collections.listOf(jf, tr /*, testng */)) + } + + val cp = (classpath + dep).distinct().map { it.jarFile.get() } + .joinToString(File.pathSeparator) + val calculatedArgs = args(project, context, classpath, testConfig) + + val jvmArgs = arrayListOf("-classpath", cp) + if (testConfig.jvmArgs.any()) { + jvmArgs.addAll(testConfig.jvmArgs) + } + val remoteArgs = listOf( + "org.testng.remote.RemoteTestNG", + "-serport", port.toString(), + "-version", testngVersion, + "-dontexit", + RemoteArgs.PROTOCOL, + "json") + + val passedArgs = jvmArgs + remoteArgs + calculatedArgs + + Thread { + runCommand { + command = "java" + directory = File(project.directory) + args = passedArgs + } + }.start() + +// Thread { +// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json", +// "-version", "6.10", +// "src/test/resources/testng.xml") +// RemoteTestNG.main(args2) +// }.start() + } } fun main(args: Array) { From ed34482aace8656b095d0c1e9269a97fd4713258 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 22 Mar 2017 14:12:36 -0700 Subject: [PATCH 114/532] 1.0.21. --- 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 1ae06062..4d001d40 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.20 \ No newline at end of file +kobalt.version=1.0.21 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index e061eabf..6e4fe8f8 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.20 +kobalt.version=1.0.21 From 18e61fc7a3073697184043cc274e7fac3eaba41b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 22 Mar 2017 22:22:30 -0700 Subject: [PATCH 115/532] Fix tests for Windows. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 6 +++++- src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt | 3 +-- .../kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 8967a4d7..14566168 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -86,4 +86,8 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { return compilerFactory!!.create(listOf(thisBuildFile), pluginInfo).compileBuildFiles(args, forceRecompile = true) } -} \ No newline at end of file + + fun createTemporaryProjectDirectory() = Files.createTempDirectory("kobaltTest").toFile().path + .replace("\\", "/") + +} diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index a9ebb362..960e5965 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -11,7 +11,6 @@ import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.DataProvider import org.testng.annotations.Guice import org.testng.annotations.Test -import java.nio.file.Files import java.util.* @Guice(modules = arrayOf(TestModule::class)) @@ -19,7 +18,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor private fun runTestWithProfile(enabled: Boolean) : Project { val projectVal = "p" + Math.abs(Random().nextInt()) - val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path + val projectDirectory = createTemporaryProjectDirectory() fun buildFileString(): String { return """ diff --git a/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt index 77cf8953..a6f0e9f3 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt @@ -13,7 +13,6 @@ import org.assertj.core.api.Assertions.assertThat import org.eclipse.aether.util.filter.AndDependencyFilter import org.testng.annotations.Guice import org.testng.annotations.Test -import java.nio.file.Files @Guice(modules = arrayOf(TestModule::class)) class DependencyManagerTest @Inject constructor(val dependencyManager: DependencyManager, @@ -107,7 +106,7 @@ class DependencyManagerTest @Inject constructor(val dependencyManager: Dependenc } private fun findDependentProject(): Project { - val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path + val projectDirectory = createTemporaryProjectDirectory() val sharedBuildFile = """ import com.beust.kobalt.* From d318f0a7b4e4b49b01991439bd7a5632c6e0d1ef Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 23 Mar 2017 01:36:22 -0700 Subject: [PATCH 116/532] Properly handle symlink --- dist/kobaltw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/kobaltw b/dist/kobaltw index a8df4bb9..2b50c906 100755 --- a/dist/kobaltw +++ b/dist/kobaltw @@ -1,2 +1,2 @@ #!/usr/bin/env sh -java -jar "`dirname "$0"`/../kobalt/wrapper/kobalt-wrapper.jar" $* \ No newline at end of file +java -jar "`dirname "$(readlink -f "$0")"`/../kobalt/wrapper/kobalt-wrapper.jar" $* From 400a73b51b2e042eedb63c123721083e31ee867d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 23 Mar 2017 10:19:42 -0700 Subject: [PATCH 117/532] Test StringVersion sorting. --- .../kotlin/com/beust/kobalt/internal/StringVersionTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt b/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt index fa5596e1..a37534f8 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt @@ -4,6 +4,7 @@ import com.beust.kobalt.misc.StringVersion import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.DataProvider import org.testng.annotations.Test +import java.util.* /** @@ -53,4 +54,11 @@ class StringVersionTest { assertThat(sv2).isGreaterThan(sv1) assertThat(sv1).isNotEqualTo(sv2) } + + @Test + fun sortVersions() { + val versions = listOf("1", "1.2", "0.9", "1.1", "1.1.1", "1.0.2").map(::StringVersion) + Collections.sort(versions) + assertThat(versions.map { it.version }).isEqualTo(listOf("0.9", "1", "1.0.2", "1.1", "1.1.1", "1.2")) + } } From cf4013af892fa6731f05f61a19f17333f0ec3bb6 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 23 Mar 2017 11:08:52 -0700 Subject: [PATCH 118/532] Fix for GYGWIN --- dist/kobaltw | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dist/kobaltw b/dist/kobaltw index 2b50c906..4f39dc35 100755 --- a/dist/kobaltw +++ b/dist/kobaltw @@ -1,2 +1,7 @@ #!/usr/bin/env sh -java -jar "`dirname "$(readlink -f "$0")"`/../kobalt/wrapper/kobalt-wrapper.jar" $* + +DIRNAME=`dirname $(readlink -f "$0")` +if [[ "$(uname)" == "CYGWIN"* ]]; then + DIRNAME=`cygpath -d "$DIRNAME"` +fi +java -jar "${DIRNAME}/../kobalt/wrapper/kobalt-wrapper.jar" $* \ No newline at end of file From 469419fe2ed40c3a04ae8c165ffa1c39dc165521 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 23 Mar 2017 12:23:02 -0700 Subject: [PATCH 119/532] Fix zip test. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 01cbd9a7..7fc19c4b 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -43,7 +43,7 @@ class VerifyKobaltZipTest : KobaltTest() { } else if (entry.name.endsWith("kobalt-wrapper.jar")) { val ins = zipFile.getInputStream(entry) foundWrapperJar = true - assertExistsInJar(JarInputStream(ins), "kobalt.properties") + assertExistsInJar(jarContents(JarInputStream(ins)), "kobalt.properties") } entry = stream.nextEntry } @@ -73,26 +73,28 @@ class VerifyKobaltZipTest : KobaltTest() { private fun verifyMainJarFile(ins: InputStream) { JarInputStream(ins).let { jar -> - assertExistsInJar(jar, "com/beust/kobalt/MainKt.class", + val setContent = jarContents(jar) + assertExistsInJar(setContent, "com/beust/kobalt/MainKt.class", "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", "com/beust/kobalt/wrapper/Main.class") - assertDoesNotExistInJar(jar, "BuildKt.class") + assertDoesNotExistInJar(setContent, "BuildKt.class") } } - private fun assertExistsInJar(ins: JarInputStream, vararg fileNames: String) - = assertExistence(ins, true, *fileNames) + private fun assertExistsInJar(content: Set, vararg fileNames: String) + = assertExistence(content, true, *fileNames) - private fun assertDoesNotExistInJar(ins: JarInputStream, vararg fileNames: String) - = assertExistence(ins, false, *fileNames) + private fun assertDoesNotExistInJar(content: Set, vararg fileNames: String) + = assertExistence(content, false, *fileNames) - private fun assertExistence(ins: JarInputStream, verifyExistence: Boolean, vararg fileNames: String) { - with(jarContents(ins)) { + private fun assertExistence(content: Set, verifyExistence: Boolean, vararg fileNames: String) { + with(content) { fileNames.forEach { fileName -> if (verifyExistence) { Assert.assertTrue(contains(fileName), "Couldn't find $fileName") } else { - Assert.assertFalse(contains(fileName), "Couldn't find $fileName") + val exists = content.contains(fileName) + Assert.assertFalse(exists, "The jar file should not contain $fileName") } } } @@ -102,7 +104,7 @@ class VerifyKobaltZipTest : KobaltTest() { val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val file = File(sourceJarPath) if (file.exists()) { - assertExistsInJar(JarInputStream(FileInputStream(file)), *fileNames) + assertExistsInJar(jarContents(JarInputStream(FileInputStream(file))), *fileNames) } else { kobaltLog(1, "Couldn't find $file, skipping test") } From f788761e4cc42e29ef132bb4bde3fd2a1a78ac9b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 23 Mar 2017 14:34:39 -0700 Subject: [PATCH 120/532] Better zip file test. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 86 ++++++++++++------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 7fc19c4b..2a604339 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -2,16 +2,19 @@ package com.beust.kobalt import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog -import org.testng.Assert import org.testng.annotations.Test import java.io.File import java.io.FileInputStream import java.io.FileReader import java.io.InputStream import java.util.* +import java.util.jar.JarEntry import java.util.jar.JarFile import java.util.jar.JarInputStream +/** + * Make sure the distribution zip file contains all the right files and no bad files. + */ class VerifyKobaltZipTest : KobaltTest() { @Test fun verifySourceJarFile() { @@ -43,7 +46,7 @@ class VerifyKobaltZipTest : KobaltTest() { } else if (entry.name.endsWith("kobalt-wrapper.jar")) { val ins = zipFile.getInputStream(entry) foundWrapperJar = true - assertExistsInJar(jarContents(JarInputStream(ins)), "kobalt.properties") + assertExistence(ins, listOf("kobalt.properties")) } entry = stream.nextEntry } @@ -72,31 +75,35 @@ class VerifyKobaltZipTest : KobaltTest() { } private fun verifyMainJarFile(ins: InputStream) { - JarInputStream(ins).let { jar -> - val setContent = jarContents(jar) - assertExistsInJar(setContent, "com/beust/kobalt/MainKt.class", + assertExistence(ins, + listOf("com/beust/kobalt/MainKt.class", "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", - "com/beust/kobalt/wrapper/Main.class") - assertDoesNotExistInJar(setContent, "BuildKt.class") - } + "com/beust/kobalt/wrapper/Main.class"), + listOf("BuildKt.class")) } - private fun assertExistsInJar(content: Set, vararg fileNames: String) - = assertExistence(content, true, *fileNames) + private fun assertExistence(ins: InputStream, + included: List, + excluded: List = emptyList(), + toName: (JarEntry) -> String = JarEntry::toString) { + val seq = toSequence(ins) + val foundItems = hashSetOf() + seq.forEach { entry -> + val entryName = toName(entry) - private fun assertDoesNotExistInJar(content: Set, vararg fileNames: String) - = assertExistence(content, false, *fileNames) - - private fun assertExistence(content: Set, verifyExistence: Boolean, vararg fileNames: String) { - with(content) { - fileNames.forEach { fileName -> - if (verifyExistence) { - Assert.assertTrue(contains(fileName), "Couldn't find $fileName") - } else { - val exists = content.contains(fileName) - Assert.assertFalse(exists, "The jar file should not contain $fileName") - } + if (included.contains(entryName)) { + foundItems.add(entryName) } + + if (excluded.any { entryName.contains(it) }) { + throw AssertionError(entryName + " should not be in the jar file") + } + } + + if (foundItems != included.toSet()) { + val missing = arrayListOf().apply { addAll(included) } + missing.removeAll(foundItems) + throw AssertionError("Didn't find a few items: " + missing) } } @@ -104,19 +111,38 @@ class VerifyKobaltZipTest : KobaltTest() { val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val file = File(sourceJarPath) if (file.exists()) { - assertExistsInJar(jarContents(JarInputStream(FileInputStream(file))), *fileNames) + assertExistence(FileInputStream(file), arrayListOf().apply { addAll(fileNames) }) } else { kobaltLog(1, "Couldn't find $file, skipping test") } } - private fun jarContents(stream: JarInputStream) : Set { - val result = hashSetOf() - var entry = stream.nextEntry - while (entry != null) { - result.add(entry.name) - entry = stream.nextEntry + private fun toSequence(ins: InputStream) = Sequence { JarInputStreamIterator(JarInputStream(ins)) } +} + +/** + * I don't want to hold the whole content of the jar file in memory to run tests on its content, + * so this iterator allows me to create a sequence out of it, so each entry in the jar file can + * be verified lazily + */ +class JarInputStreamIterator(val ins: JarInputStream) : Iterator { + var next: JarEntry? = null + + override fun next(): JarEntry { + if (next != null) { + next?.let { + val result = it + next = null + return result + } + } else { + return ins.nextJarEntry } - return result + throw IllegalArgumentException("Should never happen") + } + + override fun hasNext(): Boolean { + if (next == null) next = ins.nextJarEntry + return next != null } } From 43346a256d5d302522bd52a53c02b10f8ae2ef20 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 12:26:25 -0700 Subject: [PATCH 121/532] Better sequence. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 2a604339..ba3a61c4 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -117,32 +117,7 @@ class VerifyKobaltZipTest : KobaltTest() { } } - private fun toSequence(ins: InputStream) = Sequence { JarInputStreamIterator(JarInputStream(ins)) } -} - -/** - * I don't want to hold the whole content of the jar file in memory to run tests on its content, - * so this iterator allows me to create a sequence out of it, so each entry in the jar file can - * be verified lazily - */ -class JarInputStreamIterator(val ins: JarInputStream) : Iterator { - var next: JarEntry? = null - - override fun next(): JarEntry { - if (next != null) { - next?.let { - val result = it - next = null - return result - } - } else { - return ins.nextJarEntry - } - throw IllegalArgumentException("Should never happen") - } - - override fun hasNext(): Boolean { - if (next == null) next = ins.nextJarEntry - return next != null - } + fun JarInputStream.asSequence() = generateSequence { nextJarEntry } + + private fun toSequence(ins: InputStream): Sequence = JarInputStream(ins).asSequence() } From eaaa6fbcef80aad9f95df9a685eff98483125a44 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:31:33 -0700 Subject: [PATCH 122/532] =?UTF-8?q?Fix=20the=20=E2=80=9Cempty=20source?= =?UTF-8?q?=E2=80=9D=20bug=20in=20KobaltServer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The plug-in needs to send the root of the project, but for now, calculating it from the path of the build file. --- .../com/beust/kobalt/app/remote/RemoteDependencyData.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt index 68bb5914..5d2011f0 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt @@ -125,6 +125,8 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v .map { toDependencyData2("testCompile", it)} } + val projectRoot = File(buildFilePath).parentFile.parentFile.parentFile + val allTasks = hashSetOf() projectResult.projects.withIndex().forEach { wi -> val project = wi.value @@ -136,7 +138,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v // Separate resource from source directories fun partition(project: Project, dirs: Collection) - = dirs.filter { File(project.directory, it).exists() } + = dirs.filter { File(KFiles.joinDir(projectRoot.absolutePath, project.directory, it)).exists() } .partition { KFiles.isResource(it) } val sources = partition(project, project.sourceDirectories) val tests = partition(project, project.sourceDirectoriesTest) From 9aa1f68af6ad6f050398f830b5a0677128eb10cd Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:33:08 -0700 Subject: [PATCH 123/532] 1.0.22. --- 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 4d001d40..6cf5e248 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.21 \ No newline at end of file +kobalt.version=1.0.22 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 6e4fe8f8..776d6a58 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.21 +kobalt.version=1.0.22 From 3476a9b0c6157f308c12a3920922febaac738f94 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:47:55 -0700 Subject: [PATCH 124/532] Rename for consistency. --- .../src/main/kotlin/com/beust/kobalt/api/Project.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index ddd58d36..de544638 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -26,7 +26,7 @@ open class Project( @Directive open var url: String? = null, @Directive open var pom: Model? = null, @Directive open var dependsOn: ArrayList = arrayListOf(), - @Directive open var testsDependOnProjects: ArrayList = arrayListOf(), + @Directive open var testsDependOn: ArrayList = arrayListOf(), @Directive open var packageName: String? = group) : IBuildConfig, IDependencyHolder by DependencyHolder() { @@ -34,7 +34,7 @@ open class Project( this.project = this } - fun allProjectDependedOn() = project.dependsOn + project.testsDependOnProjects + fun allProjectDependedOn() = project.dependsOn + project.testsDependOn class ProjectExtra(project: Project) { var isDirty = false @@ -99,7 +99,7 @@ open class Project( val testDependencies : ArrayList = arrayListOf() val testProvidedDependencies : ArrayList = arrayListOf() - fun testsDependOnProjects(vararg projects: Project) = testsDependOnProjects.addAll(projects) + fun testsDependOn(vararg projects: Project) = testsDependOn.addAll(projects) /** Used to disambiguate various name properties */ @Directive From 0bdc071dcfede83afce791e0b0e97d4491248b71 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:52:41 -0700 Subject: [PATCH 125/532] Added dependsOn(). --- .../src/main/kotlin/com/beust/kobalt/api/Project.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index de544638..306a61b6 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -100,6 +100,7 @@ open class Project( val testProvidedDependencies : ArrayList = arrayListOf() fun testsDependOn(vararg projects: Project) = testsDependOn.addAll(projects) + fun dependsOn(vararg projects: Project) = dependsOn.addAll(projects) /** Used to disambiguate various name properties */ @Directive From 583c489632baf6ee83b1c5c1c52ec8fa0ad0a688 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:52:55 -0700 Subject: [PATCH 126/532] 1.0.23. --- 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 6cf5e248..8d6fc4fb 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.22 \ No newline at end of file +kobalt.version=1.0.23 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 776d6a58..e93caf93 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.22 +kobalt.version=1.0.23 From 37200ffcf2dffd064ce841b26cb34abb7f4905b7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:54:45 -0700 Subject: [PATCH 127/532] Build fix. --- .../src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index b48822b0..081f9846 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -238,7 +238,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, } if (isTest) { - project.testsDependOnProjects.forEach { p -> + project.testsDependOn.forEach { p -> val otherDependencies = calculateDependencies(p, context, dependencyFilter, scopes) result.addAll(otherDependencies) } From 335e99b1674108af3451186d9a8a4a893bfa51fd Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 14:14:59 -0700 Subject: [PATCH 128/532] Better location for the error. --- .../main/kotlin/com/beust/kobalt/maven/PomGenerator.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt index 6d666726..79c5e4b8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt @@ -23,6 +23,10 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) { * Generate the POM file and save it. */ fun generateAndSave() { + requireNotNull(project.version, { "version is mandatory on project ${project.name}" }) + requireNotNull(project.group, { "group is mandatory on project ${project.name}" }) + requireNotNull(project.artifactId, { "artifactId is mandatory on project ${project.name}" }) + val buildDir = KFiles.makeDir(project.directory, project.buildDirectory) val outputDir = KFiles.makeDir(buildDir.path, "libs") val NO_CLASSIFIER = null @@ -38,10 +42,6 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) { * @return the text content of the POM file. */ fun generate() : String { - requireNotNull(project.version, { "version mandatory on project ${project.name}" }) - requireNotNull(project.group, { "group mandatory on project ${project.name}" }) - requireNotNull(project.artifactId, { "artifactId mandatory on project ${project.name}" }) - val pom = (project.pom ?: Model()).apply { // Make sure the pom has reasonable default values if (name == null) name = project.name From e49fd94392434697eae9cca8d63dfe74a50d88a0 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 15:16:50 -0700 Subject: [PATCH 129/532] =?UTF-8?q?You=20don=E2=80=99t=20belong=20here.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 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 4d4ec96f..67b666a6 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 @@ -50,9 +50,8 @@ open class NewRunCommand(val info: RunCommandInfo) { // val DEFAULT_SUCCESS_VERBOSE = { output: List -> kobaltLog(2, "Success:\n " + output.joinToString // ("\n"))} // val defaultSuccess = DEFAULT_SUCCESS - val DEFAULT_ERROR = { - output: List -> - kotlin.error(output.joinToString("\n ")) + val DEFAULT_ERROR = { output: List -> + kobaltError(output.joinToString("\n ")) } } From b2d6b9a2e3372a101efd1d10fd93d518b248ba9f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 15:17:06 -0700 Subject: [PATCH 130/532] New line. --- src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt index 6a47c897..439e090f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt @@ -93,7 +93,7 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL return if (result) { TaskResult(true, "Compilation succeeded") } else { - val message = "Compilation errors, command:\n$command" + errorMessage + val message = "Compilation errors, command:\n$command\n" + errorMessage logk(1, message) TaskResult(false, message) } From 3acf5dc2ad35ccbd6b1b2a8326b00af777250a80 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 24 Mar 2017 18:27:44 -0700 Subject: [PATCH 131/532] Install launcher(s) if not found. --- .../main/java/com/beust/kobalt/wrapper/Main.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java index 931f8452..e2e22e42 100644 --- a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java +++ b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java @@ -219,6 +219,20 @@ public class Main { log(2, " Couldn't find $VERSION_TEXT, overwriting the installed wrapper"); installWrapperFiles(version, wrapperVersion); } + + // + // Install the launcher if not already found. + // + File kobaltw = new File(KOBALTW); + File kobaltw_bat = new File(KOBALTW_BAT); + + if (!kobaltw.exists()) { + generateKobaltW(kobaltw.toPath()); + } + + if (!kobaltw_bat.exists()) { + generateKobaltWBat(kobaltw_bat.toPath()); + } } return kobaltJarFile; From 03f957f001af132a8fc52b37cd1befb3e1183ee4 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 24 Mar 2017 20:54:02 -0700 Subject: [PATCH 132/532] Fixed variable name. --- .../src/main/java/com/beust/kobalt/wrapper/Main.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java index e2e22e42..a9a30385 100644 --- a/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java +++ b/modules/wrapper/src/main/java/com/beust/kobalt/wrapper/Main.java @@ -221,17 +221,17 @@ public class Main { } // - // Install the launcher if not already found. + // Install the launcher(s) if not already found. // File kobaltw = new File(KOBALTW); - File kobaltw_bat = new File(KOBALTW_BAT); + File kobaltwBat = new File(KOBALTW_BAT); if (!kobaltw.exists()) { generateKobaltW(kobaltw.toPath()); } - if (!kobaltw_bat.exists()) { - generateKobaltWBat(kobaltw_bat.toPath()); + if (!kobaltwBat.exists()) { + generateKobaltWBat(kobaltwBat.toPath()); } } From 771f90332cc4ff090a135635355a243e37377302 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 23:42:08 -0700 Subject: [PATCH 133/532] Reformat. --- .../src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index aba91a24..7ed5d21f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -119,7 +119,8 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager // depending on the compiler's ability, sourceFiles can actually contain a list of directories // instead of individual source files. val projectDirectory = File(project.directory) - val sourceFiles = if (compiler.canCompileDirectories) { + val sourceFiles = + if (compiler.canCompileDirectories) { allSourceDirectories.map { File(projectDirectory, it.path).path } } else { files.findRecursively(projectDirectory, allSourceDirectories, From 4e4c5a7d9e923d525a448e814e074de7698cc078 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 23:42:41 -0700 Subject: [PATCH 134/532] Put the javac command in a file. Also introduce fixSlashes(). --- .../src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt | 2 +- .../src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 3 +++ .../kotlin/com/beust/kobalt/app/remote/KobaltClient.kt | 3 ++- .../kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt | 9 ++++++--- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 6 +++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt index 807a6aba..ff282ae0 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt @@ -65,7 +65,7 @@ class JarUtils { entry = stream.nextEntry } } else { - val entryFileName = file.to(foundFile.path).path.replace("\\", "/") + val entryFileName = KFiles.fixSlashes(file.to(foundFile.path)) val entry = JarEntry(entryFileName) entry.time = localFile.lastModified() addEntry(FileInputStream(localFile), entry, outputStream, onError) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 83f6cc32..152dbc31 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -115,6 +115,9 @@ class KFiles { */ fun joinFileAndMakeDir(vararg ts: String) = joinDir(joinAndMakeDir(ts.slice(0..ts.size - 2)), ts[ts.size - 1]) + fun fixSlashes(f: File) = KFiles.fixSlashes(f.path) + fun fixSlashes(s: String) = s.replace('\\', '/') + fun makeDir(dir: String, s: String? = null) = (if (s != null) File(dir, s) else File(dir)).apply { mkdirs() } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt index 1c83413c..0a969c1d 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt @@ -8,6 +8,7 @@ import com.beust.kobalt.homeDir import com.beust.kobalt.internal.GraphUtil import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.maven.aether.Exceptions +import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.warn import com.google.gson.Gson import com.google.inject.Guice @@ -31,7 +32,7 @@ class KobaltClient : Runnable { val client = OkHttpClient() val port = KobaltServer.port ?: 1240 val url = "ws://localhost:$port/v1/getDependencyGraph" - val buildFile = homeDir("kotlin/kobalt/kobalt/src/Build.kt").replace("\\", "/") + val buildFile = KFiles.fixSlashes(homeDir("kotlin/kobalt/kobalt/src/Build.kt")) val request = Request.Builder() // .url("ws://echo.websocket.org") .url("$url?buildFile=$buildFile") diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt index 439e090f..01b7c90d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt @@ -15,6 +15,7 @@ import com.google.inject.Inject import com.google.inject.Singleton import java.io.File import java.io.PrintWriter +import java.nio.file.Files import javax.tools.DiagnosticCollector import javax.tools.JavaFileObject import javax.tools.ToolProvider @@ -77,11 +78,13 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL allArgs.addAll(info.compilerArgs) allArgs.addAll(info.sourceFiles.filter { File(it).isFile }) - val pb = ProcessBuilder(allArgs) + val dir = Files.createTempDirectory("kobalt").toFile() + val atFile = File(dir, "javac-" + project?.name + ".txt") + atFile.writeText(KFiles.fixSlashes(allArgs.subList(1, allArgs.size).joinToString(" "))) + val pb = ProcessBuilder(executable.absolutePath, "@" + KFiles.fixSlashes(atFile)) pb.inheritIO() - val line = allArgs.joinToString(" ") logk(1, " Java compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file")) - logk(2, " Java compiling $line") + logk(2, " Java compiling file: " + KFiles.fixSlashes(atFile)) command = allArgs.joinToString(" ") + " " + info.sourceFiles.joinToString(" ") val process = pb.start() diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 14566168..97a08242 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -7,6 +7,7 @@ import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.KobaltPluginXml import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile +import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.log import org.testng.annotations.BeforeClass import java.io.File @@ -27,7 +28,7 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { */ fun compileSingleProject(projectText: String, args: Args = Args()) : Project { val projectName = "p" + Math.abs(Random().nextInt()) - val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path.replace("\\", "/") + val projectDirectory = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile()) val buildFileText= """ import com.beust.kobalt.* import com.beust.kobalt.api.* @@ -87,7 +88,6 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { forceRecompile = true) } - fun createTemporaryProjectDirectory() = Files.createTempDirectory("kobaltTest").toFile().path - .replace("\\", "/") + fun createTemporaryProjectDirectory() = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile()) } From 8a8b5f638dc1181e4d8cb858f91dd15f5895b147 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 07:14:10 -0700 Subject: [PATCH 135/532] Make --server work even if there is no Build.kt. Fixes https://github.com/cbeust/kobalt-intellij-plugin/issues/69. --- src/main/kotlin/com/beust/kobalt/Main.kt | 10 +++------- .../kotlin/com/beust/kobalt/app/remote/KobaltServer.kt | 4 +--- .../kotlin/com/beust/kobalt/app/remote/SparkServer.kt | 7 +------ 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index b209c147..f2d44f0f 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -152,6 +152,9 @@ private class Main @Inject constructor( } else if (args.update) { // --update updateKobalt.updateKobalt() + } else if (args.serverMode) { + // --server + val port = serverFactory.create(args.force, args.port, { cleanUp() }).call() } else { // // Everything below requires to parse the build file first @@ -165,13 +168,6 @@ private class Main @Inject constructor( if (args.listTemplates) { // --listTemplates Templates().displayTemplates(pluginInfo) - } else if (args.serverMode) { - // --server - val port = serverFactory.create(args.force, args.port, - { buildFile -> projectFinder.initForBuildFile(BuildFile(Paths.get(buildFile), - buildFile), args) }, - { cleanUp() }) - .call() } else if (args.projectInfo) { // --projectInfo allProjects.forEach { diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt index 7e91af25..2e068829 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt @@ -26,13 +26,11 @@ import javax.annotation.Nullable * To enable websocket debugging, uncomment the "debug" tag in logback.xml. */ class KobaltServer @Inject constructor(@Assisted val force: Boolean, @Assisted @Nullable val givenPort: Int?, - @Assisted val initCallback: (String) -> List, @Assisted val cleanUpCallback: () -> Unit, val pluginInfo : PluginInfo) : Callable { interface IFactory { fun create(force: Boolean, givenPort: Int? = null, - initCallback: (String) -> List, cleanUpCallback: () -> Unit) : KobaltServer } @@ -78,7 +76,7 @@ class KobaltServer @Inject constructor(@Assisted val force: Boolean, @Assisted @ kobaltLog(1, "KobaltServer listening on port $port") // OldServer(initCallback, cleanUpCallback).run(port) // JerseyServer(initCallback, cleanUpCallback).run(port) - SparkServer(initCallback, cleanUpCallback, pluginInfo).run(port) + SparkServer(cleanUpCallback, pluginInfo).run(port) // WasabiServer(initCallback, cleanUpCallback).run(port) } } catch(ex: Exception) { diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/SparkServer.kt b/src/main/kotlin/com/beust/kobalt/app/remote/SparkServer.kt index cd028f6e..5aaf90fb 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/SparkServer.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/SparkServer.kt @@ -3,7 +3,6 @@ package com.beust.kobalt.app.remote import com.beust.kobalt.Args import com.beust.kobalt.api.ITemplate import com.beust.kobalt.api.Kobalt -import com.beust.kobalt.api.Project import com.beust.kobalt.app.ProjectFinder import com.beust.kobalt.app.Templates import com.beust.kobalt.internal.PluginInfo @@ -23,16 +22,13 @@ import spark.Spark import java.nio.file.Paths import java.util.concurrent.Executors -class SparkServer(val initCallback: (String) -> List, val cleanUpCallback: () -> Unit, - val pluginInfo : PluginInfo) : KobaltServer.IServer { +class SparkServer(val cleanUpCallback: () -> Unit, val pluginInfo : PluginInfo) : KobaltServer.IServer { companion object { - lateinit var initCallback: (String) -> List lateinit var cleanUpCallback: () -> Unit } init { - SparkServer.initCallback = initCallback SparkServer.cleanUpCallback = cleanUpCallback } @@ -72,7 +68,6 @@ class SparkServer(val initCallback: (String) -> List, val cleanUpCallba // (replaced by /v1 which uses WebSockets jsonRoute("/v0/getDependencies", Route { request, response -> val buildFile = request.queryParams("buildFile") - initCallback(buildFile) val result = if (buildFile != null) { try { From 86c166ff769840f80ec2e63d81080ab1005dbc45 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 12:45:59 -0700 Subject: [PATCH 136/532] New profile syntax: val debug by profile() --- .../kotlin/com/beust/kobalt/Directives.kt | 19 ++++++++++- .../com/beust/kobalt/misc/BlockExtractor.kt | 2 +- .../com/beust/kobalt/app/BuildFileCompiler.kt | 14 +++++--- .../beust/kobalt/app/BuildScriptJarFile.kt | 20 ------------ .../com/beust/kobalt/app/ParsedBuildFile.kt | 32 ++++++++++++------- .../com/beust/kobalt/internal/ProfileTest.kt | 2 +- 6 files changed, 50 insertions(+), 39 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Directives.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Directives.kt index f665f5d2..93d9434c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Directives.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Directives.kt @@ -4,6 +4,8 @@ import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Project import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.internal.JvmCompilerPlugin +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty @Directive fun project(vararg projects: Project, init: Project.() -> Unit): Project { @@ -19,4 +21,19 @@ fun buildScript(init: BuildScriptConfig.() -> Unit): BuildScriptConfig { val buildScriptConfig = BuildScriptConfig().apply { init() } BUILD_SCRIPT_CONFIG = buildScriptConfig return buildScriptConfig -} \ No newline at end of file +} + +@Directive +fun profile(): ReadWriteProperty { + val result = object: ReadWriteProperty { + var value: Boolean = false + override operator fun getValue(thisRef: Nothing?, property: KProperty<*>): Boolean { + return value + } + + override operator fun setValue(thisRef: Nothing?, property: KProperty<*>, value: Boolean) { + this.value = value + } + } + return result +} diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt index 7e30198f..c2bdc557 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/BlockExtractor.kt @@ -56,7 +56,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char) startLine = currentLineNumber foundKeyword = true count = 1 - result.append(topLines.joinToString("\n")) + result.append(topLines.joinToString("\n")).append("\n") result.append(line).append("\n") } else { val allowedImports = listOf("com.beust", "java") diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 730cb304..68cabd40 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -111,7 +111,8 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil KFiles.saveFile(modifiedBuildFile, parsedBuildFile.buildScriptCode) val taskResult = maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path), "Modified ${Constants.BUILD_FILE_NAME}", buildFile.realPath), - buildScriptJarFile, pluginUrls, context.internalContext.forceRecompile) + buildScriptJarFile, pluginUrls, context.internalContext.forceRecompile, + parsedBuildFile.containsProfiles) if (taskResult.success) { projects.addAll(buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context)) } else { @@ -130,7 +131,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil } private fun maybeCompileBuildFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File, - pluginUrls: List, forceRecompile: Boolean) : TaskResult { + pluginUrls: List, forceRecompile: Boolean, containsProfiles: Boolean) : TaskResult { kobaltLog(2, "Running build file ${buildFile.name} jar: $buildScriptJarFile") // If the user specifed --profiles, always recompile the build file since we don't know if @@ -140,12 +141,15 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil // to have a side file that describes which profiles the current buildScript.jar was // compiled with. val bs = BuildScriptJarFile(buildScriptJarFile) - val same = bs.sameProfiles(args.profiles) - if (same && ! forceRecompile && buildScriptUtil.isUpToDate(buildFile, buildScriptJarFile)) { + if (! containsProfiles && !forceRecompile && buildScriptUtil.isUpToDate(buildFile, buildScriptJarFile)) { kobaltLog(2, " Build file $buildScriptJarFile is up to date") return TaskResult() } else { - kobaltLog(2, " Need to recompile ${buildFile.name}") + val reason = + if (containsProfiles) "it contains profiles" + else if (forceRecompile) "forceRecompile is true" + else "it is not up to date" + kobaltLog(2, " Need to recompile ${buildFile.name} because $reason") buildScriptJarFile.deleteRecursively() val buildFileClasspath = Kobalt.buildFileClasspath.map { it.jarFile.get() }.map { it.absolutePath } diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildScriptJarFile.kt b/src/main/kotlin/com/beust/kobalt/app/BuildScriptJarFile.kt index 49610569..c34ce817 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildScriptJarFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildScriptJarFile.kt @@ -22,25 +22,5 @@ class BuildScriptJarFile(val jarFile: File) { file.delete() } } - - /** - * @{profiles} is a comma-separated list of profiles, or null - */ - fun sameProfiles(profiles: String?) : Boolean { - if (! file.exists()) { - return profiles == null - } else { - val fileContent = file.readText().trim() - if (fileContent.isEmpty() && profiles == null) { - return true - } else if (profiles != null) { - val savedProfiles = fileContent.split(" ").sorted() - val expected = profiles.split(",").sorted() - return savedProfiles == expected - } else { - return fileContent.isEmpty() - } - } - } } diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index cf9afc94..05f805ef 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -8,7 +8,6 @@ import com.beust.kobalt.api.Project import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.internal.build.VersionFile import com.beust.kobalt.maven.DependencyManager -import com.beust.kobalt.maven.aether.Filters.EXCLUDE_OPTIONAL_FILTER import com.beust.kobalt.misc.BlockExtractor import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog @@ -29,6 +28,8 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val val projects = arrayListOf() val activeProfiles = arrayListOf() + var containsProfiles = false + private val preBuildScript = arrayListOf( "import com.beust.kobalt.*", "import com.beust.kobalt.api.*") @@ -48,13 +49,19 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val * val profile = true, otherwise return the same line */ fun correctProfileLine(line: String): String { - (context.profiles as List).forEach { - if (line.matches(Regex("[ \\t]*val[ \\t]+$it[ \\t]*=.*"))) { - with("val $it = true") { - kobaltLog(2, "Activating profile $it in build file") - activeProfiles.add(it) - profileLines.add(this) - return this + (context.profiles as List).forEach { profile -> + val re = Regex(".*va[rl][ \\t]+([a-zA-Z0-9_]+)[ \\t]*.*profile\\(\\).*") + val matcher = re.matchEntire(line) + if (matcher != null && matcher.groups.size > 0) { + containsProfiles = true + val variable = matcher.groups[1]?.value + if (profile == variable) { + with("val $variable = true") { + kobaltLog(2, "Activating profile $profile in build file") + activeProfiles.add(profile) + profileLines.add(this) + return this + } } } } @@ -102,20 +109,23 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val // val pluginSourceFile = KFiles.createTempBuildFileInTempDirectory(deleteOnExit = true) pluginSourceFile.writeText(preBuildScriptCode, Charset.defaultCharset()) - kobaltLog(2, "Saved ${pluginSourceFile.absolutePath}") + kobaltLog(2, "Saved " + KFiles.fixSlashes(pluginSourceFile.absolutePath)) // // Compile to preBuildScript.jar // val buildScriptJar = KFiles.findBuildScriptLocation(buildFile, "preBuildScript.jar") val buildScriptJarFile = File(buildScriptJar) - if (! buildScriptUtil.isUpToDate(buildFile, File(buildScriptJar))) { + + // Because of profiles, it's not possible to find out if a preBuildScript.jar is up to date + // or not so recompile it every time. +// if (! buildScriptUtil.isUpToDate(buildFile, File(buildScriptJar))) { buildScriptJarFile.parentFile.mkdirs() generateJarFile(context, BuildFile(Paths.get(pluginSourceFile.path), "Plugins", Paths.get(buildScriptJar)), buildScriptJarFile, buildFile) VersionFile.generateVersionFile(buildScriptJarFile.parentFile) Kobalt.context!!.internalContext.buildFileOutOfDate = true - } +// } // // Run preBuildScript.jar to initialize plugins and repos diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index 960e5965..19e4f052 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -24,7 +24,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor return """ import com.beust.kobalt.* import com.beust.kobalt.api.* - val profile = false + val profile by profile() val $projectVal = project { name = if (profile) "profileOn" else "profileOff" directory = "$projectDirectory" From 6974e6cdb2c0832e599417c10dd9d63bdf9dacff Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 13:09:20 -0700 Subject: [PATCH 137/532] Backward compatibility. --- .../com/beust/kobalt/app/ParsedBuildFile.kt | 23 ++++++++++++++++--- .../com/beust/kobalt/internal/ProfileTest.kt | 14 ++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index 05f805ef..de6fa8fc 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -11,6 +11,7 @@ import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.BlockExtractor import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog +import com.beust.kobalt.misc.warn import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate import java.io.File import java.net.URL @@ -51,11 +52,27 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val fun correctProfileLine(line: String): String { (context.profiles as List).forEach { profile -> val re = Regex(".*va[rl][ \\t]+([a-zA-Z0-9_]+)[ \\t]*.*profile\\(\\).*") + val oldRe = Regex(".*va[rl][ \\t]+([a-zA-Z0-9_]+)[ \\t]*=[ \\t]*[tf][ra][ul][es].*") val matcher = re.matchEntire(line) - if (matcher != null && matcher.groups.size > 0) { + val oldMatcher = oldRe.matchEntire(line) + + fun profileMatch(matcher: MatchResult?) : Pair { + val variable = if (matcher != null) matcher.groups[1]?.value else null + return Pair(profile == variable, variable) + } + + if ((matcher != null && matcher.groups.size > 0) || (oldMatcher != null && oldMatcher.groups.size> 0)) { containsProfiles = true - val variable = matcher.groups[1]?.value - if (profile == variable) { + val match = profileMatch(matcher) + val oldMatch = profileMatch(oldMatcher) + if (match.first || oldMatch.first) { + val variable = if (match.first) match.second else oldMatch.second + + if (oldMatch.first) { + warn("Old profile syntax detected for \"$line\"," + + " please update to \"val $variable by profile()\"") + } + with("val $variable = true") { kobaltLog(2, "Activating profile $profile in build file") activeProfiles.add(profile) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index 19e4f052..2a77d3ee 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -16,7 +16,7 @@ import java.util.* @Guice(modules = arrayOf(TestModule::class)) class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactory) : BaseTest(compilerFactory) { - private fun runTestWithProfile(enabled: Boolean) : Project { + private fun runTestWithProfile(enabled: Boolean, oldSyntax: Boolean) : Project { val projectVal = "p" + Math.abs(Random().nextInt()) val projectDirectory = createTemporaryProjectDirectory() @@ -24,7 +24,9 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor return """ import com.beust.kobalt.* import com.beust.kobalt.api.* - val profile by profile() + val profile""" + + (if (oldSyntax) " = false\n" else " by profile()\n") + + """ val $projectVal = project { name = if (profile) "profileOn" else "profileOff" directory = "$projectDirectory" @@ -46,7 +48,13 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor @Test(dataProvider = "dp") fun profilesShouldWork(enabled: Boolean, expected: String) { Kobalt.init(TestModule()) - assertThat(runTestWithProfile(enabled).name).isEqualTo(expected) + assertThat(runTestWithProfile(enabled, oldSyntax = false).name).isEqualTo(expected) + } + + @Test(dataProvider = "dp") + fun profilesShouldWorkOldSyntax(enabled: Boolean, expected: String) { + Kobalt.init(TestModule()) + assertThat(runTestWithProfile(enabled, oldSyntax = true).name).isEqualTo(expected) } } From 152ff7e91bc1e5da7a8a459ab7bc47e14d237016 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 13:20:59 -0700 Subject: [PATCH 138/532] Rename. --- src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index 2a77d3ee..69324199 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -24,7 +24,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor return """ import com.beust.kobalt.* import com.beust.kobalt.api.* - val profile""" + + val debug""" + (if (oldSyntax) " = false\n" else " by profile()\n") + """ val $projectVal = project { From 35648cf740d7172f2a33392f4ea7b5aa9959664d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 13:21:05 -0700 Subject: [PATCH 139/532] 1.0.25. --- 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 8d6fc4fb..2369cc59 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.23 \ No newline at end of file +kobalt.version=1.0.25 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index e93caf93..5fad47e4 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.23 +kobalt.version=1.0.25 From e7d369408fa8c0bde6d6dd0ec828b7a27f16e6db Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 13:27:30 -0700 Subject: [PATCH 140/532] Fix test. --- src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index 69324199..a9f1e698 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -28,7 +28,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor (if (oldSyntax) " = false\n" else " by profile()\n") + """ val $projectVal = project { - name = if (profile) "profileOn" else "profileOff" + name = if (debug) "profileOn" else "profileOff" directory = "$projectDirectory" } """.trim() From ea7cecf59082692783418fb534e2a196c3a8ae58 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 13:30:03 -0700 Subject: [PATCH 141/532] Test fix. --- src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index a9f1e698..b36fd612 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -35,7 +35,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor } val args = Args() - if (enabled) args.profiles = "profile" + if (enabled) args.profiles = "debug" val results = compileBuildFile(projectDirectory, buildFileString(), args) return results.projects[0] } From abd84ca38607e8a2bfe8ffe1e26c24d871fc8898 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 14:25:02 -0700 Subject: [PATCH 142/532] Don't compile with kobaltBuild/classes on the classpath. --- .../src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index 7ed5d21f..cbc18dcf 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -70,7 +70,7 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager copyResources(project, context, SourceSet.of(isTest)) val fullClasspath = dependencyManager.calculateDependencies(project, context, - scopes = listOf(Scope.COMPILE, Scope.TEST)) + scopes = if (isTest) listOf(Scope.COMPILE, Scope.TEST) else listOf(Scope.COMPILE)) File(project.directory, buildDirectory.path).mkdirs() From 5c7d6a20cbea5fd753f9e7adfb13d9d371df45a3 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 14:25:18 -0700 Subject: [PATCH 143/532] 1.0.26. --- 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 2369cc59..a8eb7d5f 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.25 \ No newline at end of file +kobalt.version=1.0.26 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 5fad47e4..a8eb7d5f 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.25 +kobalt.version=1.0.26 From 043fc31c9f9b1071f37f507691161168603cf3bc Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 07:32:56 -0700 Subject: [PATCH 144/532] /v1/getDependencyGraph?projectRoot=... Deprecated buildFile=. --- .../kotlin/com/beust/kobalt/misc/KFiles.kt | 13 ++++++ src/main/kotlin/com/beust/kobalt/Main.kt | 15 +------ .../app/remote/GetDependencyGraphHandler.kt | 40 ++++++++++++++----- .../beust/kobalt/app/remote/KobaltClient.kt | 5 ++- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 152dbc31..e5a1d37d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -386,6 +386,19 @@ class KFiles { return false } } + + fun findBuildFile(projectRoot: String = "."): File { + val deprecatedLocation = File(Constants.BUILD_FILE_NAME) + val result: File = + if (deprecatedLocation.exists()) { + warn(Constants.BUILD_FILE_NAME + " is in a deprecated location, please move it to " + + Constants.BUILD_FILE_DIRECTORY) + deprecatedLocation + } else { + File(KFiles.joinDir(projectRoot, Constants.BUILD_FILE_DIRECTORY, Constants.BUILD_FILE_NAME)) + } + return result + } } fun findRecursively(directory: File, function: Function1): List { diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index f2d44f0f..063e9f7c 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -126,7 +126,7 @@ private class Main @Inject constructor( // val md5 = Md5.toMd5(file) // val md52 = MessageDigest.getInstance("MD5").digest(file.readBytes()).toHexString() var result = 0 - val p = if (args.buildFile != null) File(args.buildFile) else findBuildFile() + val p = if (args.buildFile != null) File(args.buildFile) else KFiles.findBuildFile() args.buildFile = p.absolutePath val buildFile = BuildFile(Paths.get(p.absolutePath), p.name) @@ -219,19 +219,6 @@ private class Main @Inject constructor( } } - private fun findBuildFile(): File { - val deprecatedLocation = File(Constants.BUILD_FILE_NAME) - val result: File = - if (deprecatedLocation.exists()) { - warn(Constants.BUILD_FILE_NAME + " is in a deprecated location, please move it to " - + Constants.BUILD_FILE_DIRECTORY) - deprecatedLocation - } else { - File(KFiles.joinDir(Constants.BUILD_FILE_DIRECTORY, Constants.BUILD_FILE_NAME)) - } - return result - } - private fun cleanUp() { pluginInfo.cleanUp() taskManager.cleanUp() diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt index fb8c2f1b..8c795154 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt @@ -6,6 +6,7 @@ import com.beust.kobalt.app.ProjectFinder import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent import com.beust.kobalt.maven.aether.Exceptions +import com.beust.kobalt.misc.KFiles import com.google.common.eventbus.EventBus import com.google.common.eventbus.Subscribe import com.google.gson.Gson @@ -22,6 +23,9 @@ class GetDependencyGraphHandler : WebSocketListener { // so I have to do dependency injections manually :-( val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java) + val PARAMETER_PROJECT_ROOT = "projectRoot" + val PARAMETER_BUILD_FILE = "buildFile" + var session: Session? = null override fun onWebSocketClose(code: Int, reason: String?) { @@ -39,15 +43,29 @@ class GetDependencyGraphHandler : WebSocketListener { errorMessage = errorMessage))) } + private fun findBuildFile(map: Map>) : String? { + val projectRoot = map[PARAMETER_PROJECT_ROOT] + val buildFile = map[PARAMETER_BUILD_FILE] + val result = + if (projectRoot != null) { + KFiles.findBuildFile(projectRoot[0]).absolutePath + } else if (buildFile != null) { + buildFile[0] + } else { + null + } + return result + } + override fun onWebSocketConnect(s: Session) { session = s - val buildFileParams = s.upgradeRequest.parameterMap["buildFile"] - if (buildFileParams != null) { - val buildFile = buildFileParams[0] + val buildFile = findBuildFile(s.upgradeRequest.parameterMap) - fun getInstance(cls: Class) : T = Kobalt.INJECTOR.getInstance(cls) + fun getInstance(cls: Class) : T = Kobalt.INJECTOR.getInstance(cls) - val result = if (buildFile != null) { + // Parse the request + val result = + if (buildFile != null) { // Track all the downloads that this dependency call might trigger and // send them as a progress message to the web socket val eventBus = getInstance(EventBus::class.java) @@ -76,8 +94,7 @@ class GetDependencyGraphHandler : WebSocketListener { }, useGraph = true) } catch(ex: Throwable) { Exceptions.printStackTrace(ex) - val errorMessage = ex.message - RemoteDependencyData.GetDependenciesData(errorMessage = errorMessage) + RemoteDependencyData.GetDependenciesData(errorMessage = ex.message) } finally { SparkServer.cleanUpCallback() eventBus.unregister(busListener) @@ -86,10 +103,11 @@ class GetDependencyGraphHandler : WebSocketListener { RemoteDependencyData.GetDependenciesData( errorMessage = "buildFile wasn't passed in the query parameter") } - sendWebsocketCommand(s.remote, RemoteDependencyData.GetDependenciesData.NAME, result, - errorMessage = result.errorMessage) - s.close() - } + + // Respond to the request + sendWebsocketCommand(s.remote, RemoteDependencyData.GetDependenciesData.NAME, result, + errorMessage = result.errorMessage) + s.close() } override fun onWebSocketText(message: String?) { diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt index 0a969c1d..a7c0a312 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt @@ -32,10 +32,11 @@ class KobaltClient : Runnable { val client = OkHttpClient() val port = KobaltServer.port ?: 1240 val url = "ws://localhost:$port/v1/getDependencyGraph" - val buildFile = KFiles.fixSlashes(homeDir("kotlin/kobalt/kobalt/src/Build.kt")) + val buildFile = KFiles.fixSlashes(homeDir("java/testng/kobalt/src/Build.kt")) + val projectRoot = KFiles.fixSlashes(homeDir("java/testng")) val request = Request.Builder() // .url("ws://echo.websocket.org") - .url("$url?buildFile=$buildFile") + .url("$url?projectRoot=$projectRoot&buildFile=$buildFile") .build() var webSocket: WebSocket? = null val ws = WebSocketCall.create(client, request).enqueue(object: WebSocketListener { From 01fc80c9048a6adbf7902f55b859c05b24a9eb01 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 07:36:10 -0700 Subject: [PATCH 145/532] 1.0.27. --- 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 a8eb7d5f..4c939cd1 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.26 +kobalt.version=1.0.27 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index a8eb7d5f..4c939cd1 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.26 +kobalt.version=1.0.27 From 8f99f81bc0cc9a77357fb8ecda6628b9e0d13603 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 09:57:54 -0700 Subject: [PATCH 146/532] Clean generated directory in AptPlugin. Fixes https://github.com/cbeust/kobalt/issues/357. --- .../com/beust/kobalt/plugin/apt/AptPlugin.kt | 70 +++++-------------- 1 file changed, 16 insertions(+), 54 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 168027ad..3a57d564 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -2,14 +2,12 @@ package com.beust.kobalt.plugin.apt import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive -import com.beust.kobalt.internal.ActorUtils -import com.beust.kobalt.internal.CompilerUtils import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.KFiles +import com.beust.kobalt.misc.warn import com.google.common.collect.ArrayListMultimap import com.google.inject.Inject import java.io.File -import java.nio.file.Files import java.util.* import javax.inject.Singleton @@ -21,25 +19,22 @@ import javax.inject.Singleton * (outputDir, etc...). */ @Singleton -class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, val compilerUtils: CompilerUtils) - : BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor, ITaskContributor { +class AptPlugin @Inject constructor(val dependencyManager: DependencyManager) + : BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor { // ISourceDirectoryContributor + private fun generatedDir(project: Project, outputDir: String) : File + = File(KFiles.joinDir(project.directory, KFiles.KOBALT_BUILD_DIR, outputDir)) + override fun sourceDirectoriesFor(project: Project, context: KobaltContext): List { val result = arrayListOf() aptConfigs[project.name]?.let { config -> - result.add(File( - KFiles.joinDir(project.directory, - KFiles.KOBALT_BUILD_DIR, - config.outputDir))) + result.add(generatedDir(project, config.outputDir)) } kaptConfigs[project.name]?.let { config -> - result.add(File( - KFiles.joinDir(project.directory, - KFiles.KOBALT_BUILD_DIR, - config.outputDir))) + result.add(generatedDir(project, config.outputDir)) } return result @@ -54,47 +49,14 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va override val name = PLUGIN_NAME override fun apply(project: Project, context: KobaltContext) { - } - - // ITaskContributor - override fun tasksFor(project: Project, context: KobaltContext) : List { -// val kapt = kaptConfigs[project.name] -// if (kapt != null) { -// return listOf(DynamicTask(this, "kapt", "Run kapt", project = project, -// reverseDependsOn = listOf(JvmCompilerPlugin.TASK_COMPILE), -// group = AnnotationDefault.GROUP, -// closure = { project -> -// runApt(project, context) -// TaskResult() -// })) -// } else { - return emptyList() -// } -// - } - - private fun runApt(project: Project, context: KobaltContext) { - val kapt = kaptConfigs[project.name] - if (kapt != null) { - - val sourceDir = Files.createTempDirectory("kobalt").toFile() - val javaFile = File(sourceDir, "A.java").apply { - appendText("class A {}") + listOf(aptConfigs[project.name]?.outputDir, aptConfigs[project.name]?.outputDir) + .filterNotNull() + .map { generatedDir(project, it) } + .forEach { + context.logger.log(project.name, 1, "Deleting " + it.absolutePath) + val success = it.deleteRecursively() + if (! success) warn(" Couldn't delete " + it.absolutePath) } - val compilerContributors = context.pluginInfo.compilerContributors - ActorUtils.selectAffinityActors(project, context, - context.pluginInfo.compilerContributors) - - val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context) }.sorted() - val javaCompiler = allCompilers.filter { it.sourceSuffixes.contains("java") }[0] - - val dependencies = dependencyManager.calculateDependencies(project, context) - val info = CompilerActionInfo(sourceDir.absolutePath, dependencies, - listOf(javaFile.absolutePath), listOf("java"), File(sourceDir, "generated"), - listOf(), listOf(), context.internalContext.forceRecompile) - - val results = compilerUtils.invokeCompiler(project, context, javaCompiler, info) - } } private fun generated(project: Project, context: KobaltContext, outputDir: String) = @@ -109,7 +71,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va val result = arrayListOf() fun addFlags(outputDir: String) { - aptDependencies[project.name]?.let { aptDependencies -> + aptDependencies[project.name]?.let { result.add("-s") result.add(generated(project, context, outputDir)) } From 93d3d8ad53c7a81f2edb56e37744a1074ea24011 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 09:58:11 -0700 Subject: [PATCH 147/532] 1.0.28. --- 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 4c939cd1..ee1cf7ac 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.27 +kobalt.version=1.0.28 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 4c939cd1..ee1cf7ac 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.27 +kobalt.version=1.0.28 From 67dd7e54e9ff2f8a0ad0ba67a5695a69b4bd52dc Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 10:18:27 -0700 Subject: [PATCH 148/532] Allow ParallelLogger to log from apply(). --- .../com/beust/kobalt/internal/ParallelLogger.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 7fda0eac..4062c91d 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 @@ -32,15 +32,17 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger { val newLine: Boolean) private val logLines = ConcurrentHashMap>() - private val runningProjects = ConcurrentLinkedQueue() + private val runningProjects = ConcurrentLinkedQueue() var startTime: Long? = null fun onProjectStarted(name: String) { if (startTime == null) { startTime = System.currentTimeMillis() } - runningProjects.add(name) - logLines[name] = arrayListOf() + if (! runningProjects.contains(name)) { + runningProjects.add(name) + logLines[name] = arrayListOf() + } if (currentName == null) { currentName = name } @@ -74,7 +76,7 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger { } val LOCK = Any() - var currentName: String? = null + var currentName: CharSequence? = null set(newName) { field = newName } @@ -119,6 +121,9 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger { if (args.sequential) { kobaltLog(level, message, newLine) } else { + if (! runningProjects.contains(tag)) { + runningProjects.add(tag) + } addLogLine(tag, LogLine(tag, level, message, Type.LOG, newLine)) } } From 2a7775529de6ff84cec5d62f0d82197d56bf023a Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 10:18:36 -0700 Subject: [PATCH 149/532] Fix log line. --- src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 3a57d564..b90c9f5a 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -51,11 +51,14 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager) override fun apply(project: Project, context: KobaltContext) { listOf(aptConfigs[project.name]?.outputDir, aptConfigs[project.name]?.outputDir) .filterNotNull() + .distinct() .map { generatedDir(project, it) } .forEach { - context.logger.log(project.name, 1, "Deleting " + it.absolutePath) - val success = it.deleteRecursively() - if (! success) warn(" Couldn't delete " + it.absolutePath) + it.normalize().absolutePath.let { path -> + context.logger.log(project.name, 1, " Deleting " + path) + val success = it.deleteRecursively() + if (!success) warn(" Couldn't delete " + path) + } } } From 981bbbacb65dce802b6f8dd52f72a921d4927884 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 10:18:45 -0700 Subject: [PATCH 150/532] Normalize. --- .../src/main/kotlin/com/beust/kobalt/misc/KFiles.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index e5a1d37d..e1e9a709 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -115,8 +115,8 @@ class KFiles { */ fun joinFileAndMakeDir(vararg ts: String) = joinDir(joinAndMakeDir(ts.slice(0..ts.size - 2)), ts[ts.size - 1]) - fun fixSlashes(f: File) = KFiles.fixSlashes(f.path) - fun fixSlashes(s: String) = s.replace('\\', '/') + fun fixSlashes(f: File) = f.normalize().path.replace('\\', '/') + fun fixSlashes(s: String) = fixSlashes(File(s)) fun makeDir(dir: String, s: String? = null) = (if (s != null) File(dir, s) else File(dir)).apply { mkdirs() } From f9206efaa0607e02084d9b99912397d4da8cb00e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 10:45:10 -0700 Subject: [PATCH 151/532] Improve --checkVersions. --- .../com/beust/kobalt/misc/CheckVersions.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index f6c6a49e..657bc6f7 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -6,6 +6,7 @@ import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.MavenId import com.beust.kobalt.maven.aether.AetherDependency import com.beust.kobalt.maven.aether.KobaltMavenResolver +import java.util.* import javax.inject.Inject /** @@ -28,13 +29,21 @@ class CheckVersions @Inject constructor(val depManager: DependencyManager, val artifact = (latestDep as AetherDependency).artifact val versions = resolver.resolveVersion(artifact) val releases = versions?.versions?.filter { !it.toString().contains("SNAP")} - val highest = if (releases != null && releases.any()) { - releases.last().toString() + val highestRelease = + if (releases != null) { + val strings = releases.map { it.toString() } + val c = strings.contains("1.0.8") + val sv = releases.map { StringVersion(it.toString()) } + Collections.sort(sv, Collections.reverseOrder()) + if (sv.any()) sv[0] else null } else { - versions?.highestVersion.toString() + null } + + val highest = highestRelease ?: versions?.highestVersion.toString() + if (highest != dep.id - && StringVersion(highest) > StringVersion(dep.version)) { + && StringVersion(highest.toString()) > StringVersion(dep.version)) { newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest) } } catch(e: KobaltException) { From 1d6a0ba1cac08efa470a2e3791afa1fef6db8f15 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 11:43:22 -0700 Subject: [PATCH 152/532] Refactor. --- src/main/kotlin/com/beust/kobalt/Main.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 063e9f7c..1978ae09 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -236,11 +236,7 @@ private class Main @Inject constructor( tasksByPlugins.keySet().forEach { name -> sb.append("\n " + AsciiArt.horizontalDoubleLine + " $name " + AsciiArt.horizontalDoubleLine + "\n") - tasksByPlugins[name].distinctBy { - it.name - }.sortedBy { - it.name - }.forEach { task -> + tasksByPlugins[name].distinctBy(PluginTask::name).sortedBy(PluginTask::name).forEach { task -> sb.append(" ${task.name}\t\t${task.doc}\n") } } From c6ce58fdbd34a9f5b733762f47d8f29c37d057f9 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 11:46:11 -0700 Subject: [PATCH 153/532] Make sure Versions.class is not in the jar file. --- src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index ba3a61c4..3f80c5cb 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -79,7 +79,7 @@ class VerifyKobaltZipTest : KobaltTest() { listOf("com/beust/kobalt/MainKt.class", "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", "com/beust/kobalt/wrapper/Main.class"), - listOf("BuildKt.class")) + listOf("BuildKt.class", "Versions.class")) } private fun assertExistence(ins: InputStream, @@ -95,7 +95,7 @@ class VerifyKobaltZipTest : KobaltTest() { foundItems.add(entryName) } - if (excluded.any { entryName.contains(it) }) { + if (excluded.any { entryName == it }) { throw AssertionError(entryName + " should not be in the jar file") } } From f7673cba46c343e6021a9b48e8f698348a5c0429 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 11:46:25 -0700 Subject: [PATCH 154/532] 1.0.29. --- 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 ee1cf7ac..7344bf9c 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.28 +kobalt.version=1.0.29 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index ee1cf7ac..7344bf9c 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.28 +kobalt.version=1.0.29 From fae512f639f3e867ee55bde78f8948031b08070f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 26 Mar 2017 12:21:48 -0700 Subject: [PATCH 155/532] Updated to testng 6.11 --- kobalt/src/Build.kt | 5 +++-- .../main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt | 2 +- src/main/resources/templates/build.mustache | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index a7767c10..b6a58554 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -31,6 +31,7 @@ object Versions { val slf4j = "1.7.3" val kotlin = "1.1.1" val aether = "1.0.2.v20150114" + val testng = "6.11" } fun mavenResolver(vararg m: String) @@ -113,7 +114,7 @@ val kobaltPluginApi = project { *mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"), "org.apache.maven:maven-aether-provider:3.3.9", "org.testng.testng-remote:testng-remote:1.3.0", - "org.testng:testng:6.10" + "org.testng:testng:${Versions.testng}" ) exclude(*aether("impl", "spi", "util", "api")) } @@ -183,7 +184,7 @@ val kobaltApp = project(kobaltPluginApi, wrapper) { } dependenciesTest { - compile("org.testng:testng:6.10", + compile("org.testng:testng:${Versions.testng}", "org.assertj:assertj-core:3.4.1", *mavenResolver("util") ) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 5d29d19e..83c67671 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -158,7 +158,7 @@ class TestNgRunner : GenericTestRunner() { val dep = with(context.dependencyManager) { val jf = create("org.testng.testng-remote:testng-remote:1.3.0") val tr = create("org.testng.testng-remote:$remoteRunnerVersion:1.3.0") - val testng = create("org.testng:testng:6.10") + val testng = create("org.testng:testng:6.11") transitiveClosure(kotlin.collections.listOf(jf, tr /*, testng */)) } diff --git a/src/main/resources/templates/build.mustache b/src/main/resources/templates/build.mustache index 73db711a..07a7dc96 100644 --- a/src/main/resources/templates/build.mustache +++ b/src/main/resources/templates/build.mustache @@ -38,7 +38,7 @@ val p = {{directive}} { } dependenciesTest { - compile("org.testng:testng:6.10") + compile("org.testng:testng:6.11") {{#testDependencies}} compile("{{groupId}}:{{artifactId}}:{{version}}") {{/testDependencies}} From fd5f77d9223c7c80b613b48931a020e2646a0348 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 12:44:45 -0700 Subject: [PATCH 156/532] CheckVersions fix attempt. --- .../com/beust/kobalt/ResolveDependency.kt | 2 +- .../maven/aether/KobaltMavenResolver.kt | 2 +- .../com/beust/kobalt/misc/CheckVersions.kt | 25 ++++++------------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt index 7c848461..a14f993c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt @@ -34,7 +34,7 @@ class ResolveDependency @Inject constructor( private fun latestMavenArtifact(group: String, artifactId: String, extension: String = "jar"): DependencyNode { val artifact = DefaultArtifact(group, artifactId, extension, "(0,]") - val resolved = aether.resolveVersion(artifact) + val resolved = aether.resolveRange(artifact) if (resolved != null) { val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.extension, resolved.highestVersion.toString()) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 0320d456..4e8cfae2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -74,7 +74,7 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, directDependencies(id, scope) } - fun resolveVersion(artifact: Artifact): VersionRangeResult? { + fun resolveRange(artifact: Artifact): VersionRangeResult? { val request = VersionRangeRequest(artifact, kobaltRepositories, null) val result = system.resolveVersionRange(session, request) return result diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index 657bc6f7..d15e8056 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -6,7 +6,6 @@ import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.MavenId import com.beust.kobalt.maven.aether.AetherDependency import com.beust.kobalt.maven.aether.KobaltMavenResolver -import java.util.* import javax.inject.Inject /** @@ -27,24 +26,14 @@ class CheckVersions @Inject constructor(val depManager: DependencyManager, try { val latestDep = depManager.create(dep.shortId, false, project.directory) val artifact = (latestDep as AetherDependency).artifact - val versions = resolver.resolveVersion(artifact) - val releases = versions?.versions?.filter { !it.toString().contains("SNAP")} - val highestRelease = - if (releases != null) { - val strings = releases.map { it.toString() } - val c = strings.contains("1.0.8") - val sv = releases.map { StringVersion(it.toString()) } - Collections.sort(sv, Collections.reverseOrder()) - if (sv.any()) sv[0] else null - } else { - null + val rangeResult = resolver.resolveRange(artifact) + + if (rangeResult != null) { + val highest = rangeResult.highestVersion?.toString() + if (highest != null && highest != dep.id + && StringVersion(highest) > StringVersion(dep.version)) { + newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest) } - - val highest = highestRelease ?: versions?.highestVersion.toString() - - if (highest != dep.id - && StringVersion(highest.toString()) > StringVersion(dep.version)) { - newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest) } } catch(e: KobaltException) { kobaltLog(1, " Cannot resolve ${dep.shortId}. ignoring") From 74a5a677c1db9d8045f14c006b6f8160ca95bd9d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 12:45:00 -0700 Subject: [PATCH 157/532] 1.0.30. --- 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 7344bf9c..9f0a84b5 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.29 +kobalt.version=1.0.30 diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 7344bf9c..9f0a84b5 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.29 +kobalt.version=1.0.30 From a578b70c8bc48632ac5e42184b64454c3103a465 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 17:10:50 -0700 Subject: [PATCH 158/532] First pass at better option management. --- .../main/kotlin/com/beust/kobalt/Options.kt | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Options.kt diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Options.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Options.kt new file mode 100644 index 00000000..73203bd8 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Options.kt @@ -0,0 +1,69 @@ +package com.beust.kobalt + +import com.beust.jcommander.JCommander +import com.beust.kobalt.app.ProjectGenerator +import com.beust.kobalt.app.UpdateKobalt +import com.beust.kobalt.app.remote.KobaltServer +import com.beust.kobalt.internal.PluginInfo +import com.beust.kobalt.internal.TaskManager +import com.beust.kobalt.internal.build.BuildFile +import com.beust.kobalt.misc.KFiles +import com.google.inject.Inject +import java.io.File +import java.nio.file.Paths + +open class Option(open val enabled: () -> Boolean, open val action: () -> Unit, + open val requireBuildFile: Boolean = true) +class OptionalBuildOption(override val enabled: () -> Boolean, override val action: () -> Unit) + : Option(enabled, action, false) + +class Options @Inject constructor( + val projectGenerator: ProjectGenerator, + val pluginInfo: PluginInfo, + val serverFactory: KobaltServer.IFactory, + val updateKobalt: UpdateKobalt, + val taskManager: TaskManager + ) { + + fun run(jc: JCommander, args: Args, argv: Array) { + val p = if (args.buildFile != null) File(args.buildFile) else KFiles.findBuildFile() + val buildFile = BuildFile(Paths.get(p.absolutePath), p.name) + var pluginClassLoader = javaClass.classLoader + val options = arrayListOf