From e7d369408fa8c0bde6d6dd0ec828b7a27f16e6db Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 25 Mar 2017 13:27:30 -0700 Subject: [PATCH 001/393] 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 002/393] 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 003/393] 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 004/393] 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 005/393] /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 006/393] 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 007/393] 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 008/393] 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 009/393] 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 010/393] 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 011/393] 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 012/393] 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 013/393] 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 014/393] 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 015/393] 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 016/393] 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 017/393] 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 018/393] 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 019/393] 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