1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-28 00:58:12 -07:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Erik C. Thauvin 2017-03-24 18:26:32 -07:00
commit c83d0b3710
9 changed files with 50 additions and 45 deletions

View file

@ -1 +1 @@
kobalt.version=1.0.21 kobalt.version=1.0.23

View file

@ -26,7 +26,7 @@ open class Project(
@Directive open var url: String? = null, @Directive open var url: String? = null,
@Directive open var pom: Model? = null, @Directive open var pom: Model? = null,
@Directive open var dependsOn: ArrayList<Project> = arrayListOf<Project>(), @Directive open var dependsOn: ArrayList<Project> = arrayListOf<Project>(),
@Directive open var testsDependOnProjects: ArrayList<Project> = arrayListOf<Project>(), @Directive open var testsDependOn: ArrayList<Project> = arrayListOf<Project>(),
@Directive open var packageName: String? = group) @Directive open var packageName: String? = group)
: IBuildConfig, IDependencyHolder by DependencyHolder() { : IBuildConfig, IDependencyHolder by DependencyHolder() {
@ -34,7 +34,7 @@ open class Project(
this.project = this this.project = this
} }
fun allProjectDependedOn() = project.dependsOn + project.testsDependOnProjects fun allProjectDependedOn() = project.dependsOn + project.testsDependOn
class ProjectExtra(project: Project) { class ProjectExtra(project: Project) {
var isDirty = false var isDirty = false
@ -99,7 +99,8 @@ open class Project(
val testDependencies : ArrayList<IClasspathDependency> = arrayListOf() val testDependencies : ArrayList<IClasspathDependency> = arrayListOf()
val testProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf() val testProvidedDependencies : ArrayList<IClasspathDependency> = 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 */ /** Used to disambiguate various name properties */
@Directive @Directive

View file

@ -238,7 +238,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
} }
if (isTest) { if (isTest) {
project.testsDependOnProjects.forEach { p -> project.testsDependOn.forEach { p ->
val otherDependencies = calculateDependencies(p, context, dependencyFilter, scopes) val otherDependencies = calculateDependencies(p, context, dependencyFilter, scopes)
result.addAll(otherDependencies) result.addAll(otherDependencies)
} }

View file

@ -23,6 +23,10 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) {
* Generate the POM file and save it. * Generate the POM file and save it.
*/ */
fun generateAndSave() { 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 buildDir = KFiles.makeDir(project.directory, project.buildDirectory)
val outputDir = KFiles.makeDir(buildDir.path, "libs") val outputDir = KFiles.makeDir(buildDir.path, "libs")
val NO_CLASSIFIER = null val NO_CLASSIFIER = null
@ -38,10 +42,6 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) {
* @return the text content of the POM file. * @return the text content of the POM file.
*/ */
fun generate() : String { 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 { val pom = (project.pom ?: Model()).apply {
// Make sure the pom has reasonable default values // Make sure the pom has reasonable default values
if (name == null) name = project.name if (name == null) name = project.name

View file

@ -50,9 +50,8 @@ open class NewRunCommand(val info: RunCommandInfo) {
// val DEFAULT_SUCCESS_VERBOSE = { output: List<String> -> kobaltLog(2, "Success:\n " + output.joinToString // val DEFAULT_SUCCESS_VERBOSE = { output: List<String> -> kobaltLog(2, "Success:\n " + output.joinToString
// ("\n"))} // ("\n"))}
// val defaultSuccess = DEFAULT_SUCCESS // val defaultSuccess = DEFAULT_SUCCESS
val DEFAULT_ERROR = { val DEFAULT_ERROR = { output: List<String> ->
output: List<String> -> kobaltError(output.joinToString("\n "))
kotlin.error(output.joinToString("\n "))
} }
} }

View file

@ -125,6 +125,8 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v
.map { toDependencyData2("testCompile", it)} .map { toDependencyData2("testCompile", it)}
} }
val projectRoot = File(buildFilePath).parentFile.parentFile.parentFile
val allTasks = hashSetOf<TaskData>() val allTasks = hashSetOf<TaskData>()
projectResult.projects.withIndex().forEach { wi -> projectResult.projects.withIndex().forEach { wi ->
val project = wi.value val project = wi.value
@ -136,7 +138,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v
// Separate resource from source directories // Separate resource from source directories
fun partition(project: Project, dirs: Collection<String>) fun partition(project: Project, dirs: Collection<String>)
= dirs.filter { File(project.directory, it).exists() } = dirs.filter { File(KFiles.joinDir(projectRoot.absolutePath, project.directory, it)).exists() }
.partition { KFiles.isResource(it) } .partition { KFiles.isResource(it) }
val sources = partition(project, project.sourceDirectories) val sources = partition(project, project.sourceDirectories)
val tests = partition(project, project.sourceDirectoriesTest) val tests = partition(project, project.sourceDirectoriesTest)

View file

@ -93,7 +93,7 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL
return if (result) { return if (result) {
TaskResult(true, "Compilation succeeded") TaskResult(true, "Compilation succeeded")
} else { } else {
val message = "Compilation errors, command:\n$command" + errorMessage val message = "Compilation errors, command:\n$command\n" + errorMessage
logk(1, message) logk(1, message)
TaskResult(false, message) TaskResult(false, message)
} }

View file

@ -1 +1 @@
kobalt.version=1.0.21 kobalt.version=1.0.23

View file

@ -2,16 +2,19 @@ package com.beust.kobalt
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.kobaltLog import com.beust.kobalt.misc.kobaltLog
import org.testng.Assert
import org.testng.annotations.Test import org.testng.annotations.Test
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.FileReader import java.io.FileReader
import java.io.InputStream import java.io.InputStream
import java.util.* import java.util.*
import java.util.jar.JarEntry
import java.util.jar.JarFile import java.util.jar.JarFile
import java.util.jar.JarInputStream import java.util.jar.JarInputStream
/**
* Make sure the distribution zip file contains all the right files and no bad files.
*/
class VerifyKobaltZipTest : KobaltTest() { class VerifyKobaltZipTest : KobaltTest() {
@Test @Test
fun verifySourceJarFile() { fun verifySourceJarFile() {
@ -43,7 +46,7 @@ class VerifyKobaltZipTest : KobaltTest() {
} else if (entry.name.endsWith("kobalt-wrapper.jar")) { } else if (entry.name.endsWith("kobalt-wrapper.jar")) {
val ins = zipFile.getInputStream(entry) val ins = zipFile.getInputStream(entry)
foundWrapperJar = true foundWrapperJar = true
assertExistsInJar(JarInputStream(ins), "kobalt.properties") assertExistence(ins, listOf("kobalt.properties"))
} }
entry = stream.nextEntry entry = stream.nextEntry
} }
@ -72,29 +75,35 @@ class VerifyKobaltZipTest : KobaltTest() {
} }
private fun verifyMainJarFile(ins: InputStream) { private fun verifyMainJarFile(ins: InputStream) {
JarInputStream(ins).let { jar -> assertExistence(ins,
assertExistsInJar(jar, "com/beust/kobalt/MainKt.class", listOf("com/beust/kobalt/MainKt.class",
"templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class", "templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class",
"com/beust/kobalt/wrapper/Main.class") "com/beust/kobalt/wrapper/Main.class"),
assertDoesNotExistInJar(jar, "BuildKt.class") listOf("BuildKt.class"))
}
private fun assertExistence(ins: InputStream,
included: List<String>,
excluded: List<String> = emptyList(),
toName: (JarEntry) -> String = JarEntry::toString) {
val seq = toSequence(ins)
val foundItems = hashSetOf<String>()
seq.forEach { entry ->
val entryName = toName(entry)
if (included.contains(entryName)) {
foundItems.add(entryName)
}
if (excluded.any { entryName.contains(it) }) {
throw AssertionError(entryName + " should not be in the jar file")
} }
} }
private fun assertExistsInJar(ins: JarInputStream, vararg fileNames: String) if (foundItems != included.toSet()) {
= assertExistence(ins, true, *fileNames) val missing = arrayListOf<String>().apply { addAll(included) }
missing.removeAll(foundItems)
private fun assertDoesNotExistInJar(ins: JarInputStream, vararg fileNames: String) throw AssertionError("Didn't find a few items: " + missing)
= 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")
}
}
} }
} }
@ -102,19 +111,13 @@ class VerifyKobaltZipTest : KobaltTest() {
val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName)
val file = File(sourceJarPath) val file = File(sourceJarPath)
if (file.exists()) { if (file.exists()) {
assertExistsInJar(JarInputStream(FileInputStream(file)), *fileNames) assertExistence(FileInputStream(file), arrayListOf<String>().apply { addAll(fileNames) })
} else { } else {
kobaltLog(1, "Couldn't find $file, skipping test") kobaltLog(1, "Couldn't find $file, skipping test")
} }
} }
private fun jarContents(stream: JarInputStream) : Set<String> { fun JarInputStream.asSequence() = generateSequence { nextJarEntry }
val result = hashSetOf<String>()
var entry = stream.nextEntry private fun toSequence(ins: InputStream): Sequence<JarEntry> = JarInputStream(ins).asSequence()
while (entry != null) {
result.add(entry.name)
entry = stream.nextEntry
}
return result
}
} }