diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 4d001d40..8d6fc4fb 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.23 \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index ddd58d36..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 @@ -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,8 @@ 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) + fun dependsOn(vararg projects: Project) = dependsOn.addAll(projects) /** Used to disambiguate various name properties */ @Directive 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) } 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 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 ")) } } 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) 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) } diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 6e4fe8f8..e93caf93 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.21 +kobalt.version=1.0.23 diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 01cbd9a7..ba3a61c4 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(JarInputStream(ins), "kobalt.properties") + assertExistence(ins, listOf("kobalt.properties")) } entry = stream.nextEntry } @@ -72,29 +75,35 @@ class VerifyKobaltZipTest : KobaltTest() { } private fun verifyMainJarFile(ins: InputStream) { - JarInputStream(ins).let { jar -> - assertExistsInJar(jar, "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(jar, "BuildKt.class") - } + "com/beust/kobalt/wrapper/Main.class"), + listOf("BuildKt.class")) } - private fun assertExistsInJar(ins: JarInputStream, vararg fileNames: String) - = assertExistence(ins, 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(ins: JarInputStream, vararg fileNames: String) - = assertExistence(ins, false, *fileNames) - - private fun assertExistence(ins: JarInputStream, verifyExistence: Boolean, vararg fileNames: String) { - with(jarContents(ins)) { - fileNames.forEach { fileName -> - if (verifyExistence) { - Assert.assertTrue(contains(fileName), "Couldn't find $fileName") - } else { - Assert.assertFalse(contains(fileName), "Couldn't find $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) } } @@ -102,19 +111,13 @@ class VerifyKobaltZipTest : KobaltTest() { val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val file = File(sourceJarPath) if (file.exists()) { - assertExistsInJar(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 - } - return result - } + fun JarInputStream.asSequence() = generateSequence { nextJarEntry } + + private fun toSequence(ins: InputStream): Sequence = JarInputStream(ins).asSequence() }