From 469419fe2ed40c3a04ae8c165ffa1c39dc165521 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 23 Mar 2017 12:23:02 -0700 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] =?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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 09/12] 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 10/12] 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 11/12] =?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 12/12] 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) }