From 18e61fc7a3073697184043cc274e7fac3eaba41b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 22 Mar 2017 22:22:30 -0700 Subject: [PATCH 001/418] Fix tests for Windows. --- src/test/kotlin/com/beust/kobalt/BaseTest.kt | 6 +++++- src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt | 3 +-- .../kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 8967a4d7..14566168 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -86,4 +86,8 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) { return compilerFactory!!.create(listOf(thisBuildFile), pluginInfo).compileBuildFiles(args, forceRecompile = true) } -} \ No newline at end of file + + fun createTemporaryProjectDirectory() = Files.createTempDirectory("kobaltTest").toFile().path + .replace("\\", "/") + +} diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index a9ebb362..960e5965 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -11,7 +11,6 @@ import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.DataProvider import org.testng.annotations.Guice import org.testng.annotations.Test -import java.nio.file.Files import java.util.* @Guice(modules = arrayOf(TestModule::class)) @@ -19,7 +18,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor private fun runTestWithProfile(enabled: Boolean) : Project { val projectVal = "p" + Math.abs(Random().nextInt()) - val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path + val projectDirectory = createTemporaryProjectDirectory() fun buildFileString(): String { return """ diff --git a/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt index 77cf8953..a6f0e9f3 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DependencyManagerTest.kt @@ -13,7 +13,6 @@ import org.assertj.core.api.Assertions.assertThat import org.eclipse.aether.util.filter.AndDependencyFilter import org.testng.annotations.Guice import org.testng.annotations.Test -import java.nio.file.Files @Guice(modules = arrayOf(TestModule::class)) class DependencyManagerTest @Inject constructor(val dependencyManager: DependencyManager, @@ -107,7 +106,7 @@ class DependencyManagerTest @Inject constructor(val dependencyManager: Dependenc } private fun findDependentProject(): Project { - val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path + val projectDirectory = createTemporaryProjectDirectory() val sharedBuildFile = """ import com.beust.kobalt.* From d318f0a7b4e4b49b01991439bd7a5632c6e0d1ef Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 23 Mar 2017 01:36:22 -0700 Subject: [PATCH 002/418] Properly handle symlink --- dist/kobaltw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/kobaltw b/dist/kobaltw index a8df4bb9..2b50c906 100755 --- a/dist/kobaltw +++ b/dist/kobaltw @@ -1,2 +1,2 @@ #!/usr/bin/env sh -java -jar "`dirname "$0"`/../kobalt/wrapper/kobalt-wrapper.jar" $* \ No newline at end of file +java -jar "`dirname "$(readlink -f "$0")"`/../kobalt/wrapper/kobalt-wrapper.jar" $* From 400a73b51b2e042eedb63c123721083e31ee867d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 23 Mar 2017 10:19:42 -0700 Subject: [PATCH 003/418] Test StringVersion sorting. --- .../kotlin/com/beust/kobalt/internal/StringVersionTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt b/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt index fa5596e1..a37534f8 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/StringVersionTest.kt @@ -4,6 +4,7 @@ import com.beust.kobalt.misc.StringVersion import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.DataProvider import org.testng.annotations.Test +import java.util.* /** @@ -53,4 +54,11 @@ class StringVersionTest { assertThat(sv2).isGreaterThan(sv1) assertThat(sv1).isNotEqualTo(sv2) } + + @Test + fun sortVersions() { + val versions = listOf("1", "1.2", "0.9", "1.1", "1.1.1", "1.0.2").map(::StringVersion) + Collections.sort(versions) + assertThat(versions.map { it.version }).isEqualTo(listOf("0.9", "1", "1.0.2", "1.1", "1.1.1", "1.2")) + } } From cf4013af892fa6731f05f61a19f17333f0ec3bb6 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 23 Mar 2017 11:08:52 -0700 Subject: [PATCH 004/418] Fix for GYGWIN --- dist/kobaltw | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dist/kobaltw b/dist/kobaltw index 2b50c906..4f39dc35 100755 --- a/dist/kobaltw +++ b/dist/kobaltw @@ -1,2 +1,7 @@ #!/usr/bin/env sh -java -jar "`dirname "$(readlink -f "$0")"`/../kobalt/wrapper/kobalt-wrapper.jar" $* + +DIRNAME=`dirname $(readlink -f "$0")` +if [[ "$(uname)" == "CYGWIN"* ]]; then + DIRNAME=`cygpath -d "$DIRNAME"` +fi +java -jar "${DIRNAME}/../kobalt/wrapper/kobalt-wrapper.jar" $* \ No newline at end of file From 469419fe2ed40c3a04ae8c165ffa1c39dc165521 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 23 Mar 2017 12:23:02 -0700 Subject: [PATCH 005/418] Fix zip test. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 01cbd9a7..7fc19c4b 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -43,7 +43,7 @@ class VerifyKobaltZipTest : KobaltTest() { } else if (entry.name.endsWith("kobalt-wrapper.jar")) { val ins = zipFile.getInputStream(entry) foundWrapperJar = true - assertExistsInJar(JarInputStream(ins), "kobalt.properties") + assertExistsInJar(jarContents(JarInputStream(ins)), "kobalt.properties") } entry = stream.nextEntry } @@ -73,26 +73,28 @@ class VerifyKobaltZipTest : KobaltTest() { private fun verifyMainJarFile(ins: InputStream) { JarInputStream(ins).let { jar -> - assertExistsInJar(jar, "com/beust/kobalt/MainKt.class", + val setContent = jarContents(jar) + assertExistsInJar(setContent, "com/beust/kobalt/MainKt.class", "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", "com/beust/kobalt/wrapper/Main.class") - assertDoesNotExistInJar(jar, "BuildKt.class") + assertDoesNotExistInJar(setContent, "BuildKt.class") } } - private fun assertExistsInJar(ins: JarInputStream, vararg fileNames: String) - = assertExistence(ins, true, *fileNames) + private fun assertExistsInJar(content: Set, vararg fileNames: String) + = assertExistence(content, true, *fileNames) - private fun assertDoesNotExistInJar(ins: JarInputStream, vararg fileNames: String) - = assertExistence(ins, false, *fileNames) + private fun assertDoesNotExistInJar(content: Set, vararg fileNames: String) + = assertExistence(content, false, *fileNames) - private fun assertExistence(ins: JarInputStream, verifyExistence: Boolean, vararg fileNames: String) { - with(jarContents(ins)) { + private fun assertExistence(content: Set, verifyExistence: Boolean, vararg fileNames: String) { + with(content) { fileNames.forEach { fileName -> if (verifyExistence) { Assert.assertTrue(contains(fileName), "Couldn't find $fileName") } else { - Assert.assertFalse(contains(fileName), "Couldn't find $fileName") + val exists = content.contains(fileName) + Assert.assertFalse(exists, "The jar file should not contain $fileName") } } } @@ -102,7 +104,7 @@ class VerifyKobaltZipTest : KobaltTest() { val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val file = File(sourceJarPath) if (file.exists()) { - assertExistsInJar(JarInputStream(FileInputStream(file)), *fileNames) + assertExistsInJar(jarContents(JarInputStream(FileInputStream(file))), *fileNames) } else { kobaltLog(1, "Couldn't find $file, skipping test") } From f788761e4cc42e29ef132bb4bde3fd2a1a78ac9b Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 23 Mar 2017 14:34:39 -0700 Subject: [PATCH 006/418] Better zip file test. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 86 ++++++++++++------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 7fc19c4b..2a604339 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -2,16 +2,19 @@ package com.beust.kobalt import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.kobaltLog -import org.testng.Assert import org.testng.annotations.Test import java.io.File import java.io.FileInputStream import java.io.FileReader import java.io.InputStream import java.util.* +import java.util.jar.JarEntry import java.util.jar.JarFile import java.util.jar.JarInputStream +/** + * Make sure the distribution zip file contains all the right files and no bad files. + */ class VerifyKobaltZipTest : KobaltTest() { @Test fun verifySourceJarFile() { @@ -43,7 +46,7 @@ class VerifyKobaltZipTest : KobaltTest() { } else if (entry.name.endsWith("kobalt-wrapper.jar")) { val ins = zipFile.getInputStream(entry) foundWrapperJar = true - assertExistsInJar(jarContents(JarInputStream(ins)), "kobalt.properties") + assertExistence(ins, listOf("kobalt.properties")) } entry = stream.nextEntry } @@ -72,31 +75,35 @@ class VerifyKobaltZipTest : KobaltTest() { } private fun verifyMainJarFile(ins: InputStream) { - JarInputStream(ins).let { jar -> - val setContent = jarContents(jar) - assertExistsInJar(setContent, "com/beust/kobalt/MainKt.class", + assertExistence(ins, + listOf("com/beust/kobalt/MainKt.class", "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", - "com/beust/kobalt/wrapper/Main.class") - assertDoesNotExistInJar(setContent, "BuildKt.class") - } + "com/beust/kobalt/wrapper/Main.class"), + listOf("BuildKt.class")) } - private fun assertExistsInJar(content: Set, vararg fileNames: String) - = assertExistence(content, true, *fileNames) + private fun assertExistence(ins: InputStream, + included: List, + excluded: List = emptyList(), + toName: (JarEntry) -> String = JarEntry::toString) { + val seq = toSequence(ins) + val foundItems = hashSetOf() + seq.forEach { entry -> + val entryName = toName(entry) - private fun assertDoesNotExistInJar(content: Set, vararg fileNames: String) - = assertExistence(content, false, *fileNames) - - private fun assertExistence(content: Set, verifyExistence: Boolean, vararg fileNames: String) { - with(content) { - fileNames.forEach { fileName -> - if (verifyExistence) { - Assert.assertTrue(contains(fileName), "Couldn't find $fileName") - } else { - val exists = content.contains(fileName) - Assert.assertFalse(exists, "The jar file should not contain $fileName") - } + if (included.contains(entryName)) { + foundItems.add(entryName) } + + if (excluded.any { entryName.contains(it) }) { + throw AssertionError(entryName + " should not be in the jar file") + } + } + + if (foundItems != included.toSet()) { + val missing = arrayListOf().apply { addAll(included) } + missing.removeAll(foundItems) + throw AssertionError("Didn't find a few items: " + missing) } } @@ -104,19 +111,38 @@ class VerifyKobaltZipTest : KobaltTest() { val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val file = File(sourceJarPath) if (file.exists()) { - assertExistsInJar(jarContents(JarInputStream(FileInputStream(file))), *fileNames) + assertExistence(FileInputStream(file), arrayListOf().apply { addAll(fileNames) }) } else { kobaltLog(1, "Couldn't find $file, skipping test") } } - private fun jarContents(stream: JarInputStream) : Set { - val result = hashSetOf() - var entry = stream.nextEntry - while (entry != null) { - result.add(entry.name) - entry = stream.nextEntry + private fun toSequence(ins: InputStream) = Sequence { JarInputStreamIterator(JarInputStream(ins)) } +} + +/** + * I don't want to hold the whole content of the jar file in memory to run tests on its content, + * so this iterator allows me to create a sequence out of it, so each entry in the jar file can + * be verified lazily + */ +class JarInputStreamIterator(val ins: JarInputStream) : Iterator { + var next: JarEntry? = null + + override fun next(): JarEntry { + if (next != null) { + next?.let { + val result = it + next = null + return result + } + } else { + return ins.nextJarEntry } - return result + throw IllegalArgumentException("Should never happen") + } + + override fun hasNext(): Boolean { + if (next == null) next = ins.nextJarEntry + return next != null } } From 43346a256d5d302522bd52a53c02b10f8ae2ef20 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 12:26:25 -0700 Subject: [PATCH 007/418] Better sequence. --- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 2a604339..ba3a61c4 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -117,32 +117,7 @@ class VerifyKobaltZipTest : KobaltTest() { } } - private fun toSequence(ins: InputStream) = Sequence { JarInputStreamIterator(JarInputStream(ins)) } -} - -/** - * I don't want to hold the whole content of the jar file in memory to run tests on its content, - * so this iterator allows me to create a sequence out of it, so each entry in the jar file can - * be verified lazily - */ -class JarInputStreamIterator(val ins: JarInputStream) : Iterator { - var next: JarEntry? = null - - override fun next(): JarEntry { - if (next != null) { - next?.let { - val result = it - next = null - return result - } - } else { - return ins.nextJarEntry - } - throw IllegalArgumentException("Should never happen") - } - - override fun hasNext(): Boolean { - if (next == null) next = ins.nextJarEntry - return next != null - } + fun JarInputStream.asSequence() = generateSequence { nextJarEntry } + + private fun toSequence(ins: InputStream): Sequence = JarInputStream(ins).asSequence() } From eaaa6fbcef80aad9f95df9a685eff98483125a44 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:31:33 -0700 Subject: [PATCH 008/418] =?UTF-8?q?Fix=20the=20=E2=80=9Cempty=20source?= =?UTF-8?q?=E2=80=9D=20bug=20in=20KobaltServer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The plug-in needs to send the root of the project, but for now, calculating it from the path of the build file. --- .../com/beust/kobalt/app/remote/RemoteDependencyData.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt index 68bb5914..5d2011f0 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt @@ -125,6 +125,8 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v .map { toDependencyData2("testCompile", it)} } + val projectRoot = File(buildFilePath).parentFile.parentFile.parentFile + val allTasks = hashSetOf() projectResult.projects.withIndex().forEach { wi -> val project = wi.value @@ -136,7 +138,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v // Separate resource from source directories fun partition(project: Project, dirs: Collection) - = dirs.filter { File(project.directory, it).exists() } + = dirs.filter { File(KFiles.joinDir(projectRoot.absolutePath, project.directory, it)).exists() } .partition { KFiles.isResource(it) } val sources = partition(project, project.sourceDirectories) val tests = partition(project, project.sourceDirectoriesTest) From 9aa1f68af6ad6f050398f830b5a0677128eb10cd Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:33:08 -0700 Subject: [PATCH 009/418] 1.0.22. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 4d001d40..6cf5e248 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.21 \ No newline at end of file +kobalt.version=1.0.22 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 6e4fe8f8..776d6a58 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.21 +kobalt.version=1.0.22 From 3476a9b0c6157f308c12a3920922febaac738f94 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:47:55 -0700 Subject: [PATCH 010/418] Rename for consistency. --- .../src/main/kotlin/com/beust/kobalt/api/Project.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index ddd58d36..de544638 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -26,7 +26,7 @@ open class Project( @Directive open var url: String? = null, @Directive open var pom: Model? = null, @Directive open var dependsOn: ArrayList = arrayListOf(), - @Directive open var testsDependOnProjects: ArrayList = arrayListOf(), + @Directive open var testsDependOn: ArrayList = arrayListOf(), @Directive open var packageName: String? = group) : IBuildConfig, IDependencyHolder by DependencyHolder() { @@ -34,7 +34,7 @@ open class Project( this.project = this } - fun allProjectDependedOn() = project.dependsOn + project.testsDependOnProjects + fun allProjectDependedOn() = project.dependsOn + project.testsDependOn class ProjectExtra(project: Project) { var isDirty = false @@ -99,7 +99,7 @@ open class Project( val testDependencies : ArrayList = arrayListOf() val testProvidedDependencies : ArrayList = arrayListOf() - fun testsDependOnProjects(vararg projects: Project) = testsDependOnProjects.addAll(projects) + fun testsDependOn(vararg projects: Project) = testsDependOn.addAll(projects) /** Used to disambiguate various name properties */ @Directive From 0bdc071dcfede83afce791e0b0e97d4491248b71 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:52:41 -0700 Subject: [PATCH 011/418] Added dependsOn(). --- .../src/main/kotlin/com/beust/kobalt/api/Project.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index de544638..306a61b6 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -100,6 +100,7 @@ open class Project( val testProvidedDependencies : ArrayList = arrayListOf() fun testsDependOn(vararg projects: Project) = testsDependOn.addAll(projects) + fun dependsOn(vararg projects: Project) = dependsOn.addAll(projects) /** Used to disambiguate various name properties */ @Directive From 583c489632baf6ee83b1c5c1c52ec8fa0ad0a688 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:52:55 -0700 Subject: [PATCH 012/418] 1.0.23. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 6cf5e248..8d6fc4fb 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.22 \ No newline at end of file +kobalt.version=1.0.23 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 776d6a58..e93caf93 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.22 +kobalt.version=1.0.23 From 37200ffcf2dffd064ce841b26cb34abb7f4905b7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 13:54:45 -0700 Subject: [PATCH 013/418] Build fix. --- .../src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index b48822b0..081f9846 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -238,7 +238,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, } if (isTest) { - project.testsDependOnProjects.forEach { p -> + project.testsDependOn.forEach { p -> val otherDependencies = calculateDependencies(p, context, dependencyFilter, scopes) result.addAll(otherDependencies) } From 335e99b1674108af3451186d9a8a4a893bfa51fd Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 24 Mar 2017 14:14:59 -0700 Subject: [PATCH 014/418] 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 015/418] =?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 016/418] 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 017/418] 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 018/418] 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 019/418] 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 020/418] 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 021/418] 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 022/418] 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 023/418] 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 024/418] 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 025/418] 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 026/418] 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 027/418] 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 028/418] 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 029/418] 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 030/418] /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 031/418] 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 032/418] 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 033/418] 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 034/418] 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 035/418] 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 036/418] 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 037/418] 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 038/418] 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 039/418] 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 040/418] 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 041/418] 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 042/418] 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 043/418] 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 044/418] 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