From d318f0a7b4e4b49b01991439bd7a5632c6e0d1ef Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 23 Mar 2017 01:36:22 -0700 Subject: [PATCH 001/407] 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 cf4013af892fa6731f05f61a19f17333f0ec3bb6 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 23 Mar 2017 11:08:52 -0700 Subject: [PATCH 002/407] 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 335e99b1674108af3451186d9a8a4a893bfa51fd Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 14:14:59 -0700 Subject: [PATCH 003/407] 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 004/407] =?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 005/407] 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 006/407] 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 007/407] 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 008/407] 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 009/407] 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 010/407] 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 011/407] 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 012/407] 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 013/407] 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 014/407] 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 015/407] 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 016/407] 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 017/407] 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 018/407] 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 019/407] /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 020/407] 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 021/407] 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 022/407] 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 023/407] 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 024/407] 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 025/407] 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 026/407] 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 027/407] 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 028/407] 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 029/407] 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 030/407] 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 031/407] 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 032/407] 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 033/407] 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