From b21d867ec25bbd046976a24fcd31be8236ddfefe Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 18 Mar 2017 23:09:04 -0700 Subject: [PATCH 001/458] 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 002/458] 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 003/458] 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 004/458] 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 005/458] 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 006/458] 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 007/458] 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 008/458] 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 009/458] 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 010/458] 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 011/458] 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 012/458] 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 013/458] 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 014/458] 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 015/458] 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 016/458] 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 017/458] 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 018/458] 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 019/458] 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 020/458] 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 021/458] 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 022/458] 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 023/458] 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 024/458] 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 025/458] 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 026/458] 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 027/458] 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 028/458] 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 029/458] 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 030/458] 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 031/458] 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 032/458] 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 033/458] 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 034/458] 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 035/458] 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 036/458] 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 037/458] 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 038/458] 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 039/458] 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 040/458] 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 041/458] 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 042/458] 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 043/458] 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 044/458] 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 045/458] 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 046/458] 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 047/458] 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 048/458] =?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 049/458] 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 050/458] 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 051/458] 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 052/458] 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 053/458] 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 054/458] 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 055/458] =?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 056/458] 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 057/458] 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 058/458] 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 059/458] 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 060/458] 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 061/458] 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 062/458] 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 063/458] 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 064/458] 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 065/458] 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 066/458] 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 067/458] 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 068/458] 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 069/458] 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 070/458] /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 071/458] 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 072/458] 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 073/458] 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 074/458] 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 075/458] 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 076/458] 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 077/458] 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 078/458] 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 079/458] 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 080/458] 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 081/458] 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 082/458] 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 083/458] 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 084/458] 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