mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Merge branch 'master' of github.com:cbeust/kobalt
This commit is contained in:
commit
90df943ec3
35 changed files with 295 additions and 120 deletions
|
@ -120,8 +120,10 @@ val kobaltPluginApi = project {
|
||||||
"org.junit.platform:junit-platform-engine:${Versions.junitPlatform}",
|
"org.junit.platform:junit-platform-engine:${Versions.junitPlatform}",
|
||||||
"org.junit.platform:junit-platform-console:${Versions.junitPlatform}",
|
"org.junit.platform:junit-platform-console:${Versions.junitPlatform}",
|
||||||
"org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiter}",
|
"org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiter}",
|
||||||
"org.junit.vintage:junit-vintage-engine:${Versions.junitVintageVersion}"
|
"org.junit.vintage:junit-vintage-engine:${Versions.junitVintageVersion}",
|
||||||
|
|
||||||
|
"org.apache.commons:commons-compress:1.13",
|
||||||
|
"commons-io:commons-io:2.5"
|
||||||
)
|
)
|
||||||
exclude(*aether("impl", "spi", "util", "api"))
|
exclude(*aether("impl", "spi", "util", "api"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
kobalt.version=1.0.58
|
kobalt.version=1.0.60
|
||||||
|
|
|
@ -6,13 +6,12 @@ import com.beust.kobalt.archive.Archives
|
||||||
import com.beust.kobalt.archive.Zip
|
import com.beust.kobalt.archive.Zip
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.maven.aether.Scope
|
import com.beust.kobalt.maven.aether.Scope
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.kobaltLog
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.OutputStream
|
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.jar.JarOutputStream
|
|
||||||
import java.util.jar.Manifest
|
import java.util.jar.Manifest
|
||||||
|
|
||||||
class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) : ArchiveGenerator {
|
class JarGenerator @Inject constructor(val dependencyManager: DependencyManager) : ArchiveGenerator {
|
||||||
|
@ -155,10 +154,8 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) }
|
|
||||||
|
|
||||||
return Archives.generateArchive(project, context, zip.name, ".jar", includedFiles,
|
return Archives.generateArchive(project, context, zip.name, ".jar", includedFiles,
|
||||||
true /* expandJarFiles */, jarFactory)
|
true /* expandJarFiles */, manifest)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,3 +1,8 @@
|
||||||
package com.beust.kobalt
|
package com.beust.kobalt
|
||||||
|
|
||||||
open public class TaskResult(val success: Boolean = true, val errorMessage: String? = null)
|
class TestResult(val success: Boolean, val shortMessage: String? = null, val longMessage: String? = null)
|
||||||
|
|
||||||
|
open class TaskResult(val success: Boolean = true,
|
||||||
|
val testResult: TestResult? = null,
|
||||||
|
val errorMessage: String? = null
|
||||||
|
)
|
||||||
|
|
|
@ -13,6 +13,7 @@ interface IDependencyHolder {
|
||||||
val compileDependencies : ArrayList<IClasspathDependency>
|
val compileDependencies : ArrayList<IClasspathDependency>
|
||||||
val optionalDependencies : ArrayList<IClasspathDependency>
|
val optionalDependencies : ArrayList<IClasspathDependency>
|
||||||
val compileProvidedDependencies : ArrayList<IClasspathDependency>
|
val compileProvidedDependencies : ArrayList<IClasspathDependency>
|
||||||
|
val compileOnlyDependencies : ArrayList<IClasspathDependency>
|
||||||
val compileRuntimeDependencies : ArrayList<IClasspathDependency>
|
val compileRuntimeDependencies : ArrayList<IClasspathDependency>
|
||||||
val excludedDependencies : ArrayList<IClasspathDependency>
|
val excludedDependencies : ArrayList<IClasspathDependency>
|
||||||
val nativeDependencies : ArrayList<IClasspathDependency>
|
val nativeDependencies : ArrayList<IClasspathDependency>
|
||||||
|
@ -29,6 +30,7 @@ open class DependencyHolder : IDependencyHolder {
|
||||||
override val compileDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
override val compileDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
override val optionalDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
override val optionalDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
override val compileProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
override val compileProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
|
override val compileOnlyDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
override val compileRuntimeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
override val compileRuntimeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
override val excludedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
override val excludedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
override val nativeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
override val nativeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
|
@ -37,7 +39,7 @@ open class DependencyHolder : IDependencyHolder {
|
||||||
|
|
||||||
override fun dependencies(init: Dependencies.() -> Unit) : Dependencies {
|
override fun dependencies(init: Dependencies.() -> Unit) : Dependencies {
|
||||||
dependencies = Dependencies(project, compileDependencies, optionalDependencies, compileProvidedDependencies,
|
dependencies = Dependencies(project, compileDependencies, optionalDependencies, compileProvidedDependencies,
|
||||||
compileRuntimeDependencies, excludedDependencies, nativeDependencies)
|
compileOnlyDependencies, compileRuntimeDependencies, excludedDependencies, nativeDependencies)
|
||||||
dependencies!!.init()
|
dependencies!!.init()
|
||||||
return dependencies!!
|
return dependencies!!
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,12 @@ package com.beust.kobalt.api
|
||||||
* Plug-ins that listen to build events.
|
* Plug-ins that listen to build events.
|
||||||
*/
|
*/
|
||||||
interface IBuildListener : IListener {
|
interface IBuildListener : IListener {
|
||||||
|
|
||||||
|
class TaskEndInfo(val success: Boolean, val shortMessage: String? = null,
|
||||||
|
val longMessage: String? = null)
|
||||||
|
|
||||||
fun taskStart(project: Project, context: KobaltContext, taskName: String) {}
|
fun taskStart(project: Project, context: KobaltContext, taskName: String) {}
|
||||||
fun taskEnd(project: Project, context: KobaltContext, taskName: String, success: Boolean) {}
|
fun taskEnd(project: Project, context: KobaltContext, taskName: String, info: TaskEndInfo) {}
|
||||||
|
|
||||||
fun projectStart(project: Project, context: KobaltContext) {}
|
fun projectStart(project: Project, context: KobaltContext) {}
|
||||||
fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) {}
|
fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) {}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class DynamicTask(override val plugin: IPlugin, override val name: String, overr
|
||||||
|
|
||||||
override fun call(): TaskResult2<ITask> {
|
override fun call(): TaskResult2<ITask> {
|
||||||
val taskResult = closure.invoke(project)
|
val taskResult = closure.invoke(project)
|
||||||
return TaskResult2(taskResult.success, taskResult.errorMessage, this)
|
return TaskResult2(taskResult.success, errorMessage = taskResult.errorMessage, value = this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "[DynamicTask $name dependsOn=$dependsOn reverseDependsOn=$reverseDependsOn]"
|
override fun toString() = "[DynamicTask $name dependsOn=$dependsOn reverseDependsOn=$reverseDependsOn]"
|
||||||
|
|
|
@ -91,7 +91,8 @@ open class Project(
|
||||||
@Directive
|
@Directive
|
||||||
fun dependenciesTest(init: Dependencies.() -> Unit) : Dependencies {
|
fun dependenciesTest(init: Dependencies.() -> Unit) : Dependencies {
|
||||||
dependencies = Dependencies(this, testDependencies, arrayListOf(),
|
dependencies = Dependencies(this, testDependencies, arrayListOf(),
|
||||||
testProvidedDependencies, compileRuntimeDependencies, excludedDependencies, nativeDependencies)
|
testProvidedDependencies, compileOnlyDependencies, compileRuntimeDependencies,
|
||||||
|
excludedDependencies, nativeDependencies)
|
||||||
dependencies!!.init()
|
dependencies!!.init()
|
||||||
return dependencies!!
|
return dependencies!!
|
||||||
}
|
}
|
||||||
|
@ -154,6 +155,7 @@ class Dependencies(val project: Project,
|
||||||
val dependencies: ArrayList<IClasspathDependency>,
|
val dependencies: ArrayList<IClasspathDependency>,
|
||||||
val optionalDependencies: ArrayList<IClasspathDependency>,
|
val optionalDependencies: ArrayList<IClasspathDependency>,
|
||||||
val providedDependencies: ArrayList<IClasspathDependency>,
|
val providedDependencies: ArrayList<IClasspathDependency>,
|
||||||
|
val compileOnlyDependencies: ArrayList<IClasspathDependency>,
|
||||||
val runtimeDependencies: ArrayList<IClasspathDependency>,
|
val runtimeDependencies: ArrayList<IClasspathDependency>,
|
||||||
val excludedDependencies: ArrayList<IClasspathDependency>,
|
val excludedDependencies: ArrayList<IClasspathDependency>,
|
||||||
val nativeDependencies: ArrayList<IClasspathDependency>) {
|
val nativeDependencies: ArrayList<IClasspathDependency>) {
|
||||||
|
@ -244,6 +246,9 @@ class Dependencies(val project: Project,
|
||||||
addToDependencies(project, dependencies, arrayOf(dep), excludeConfig = excludeConfig)
|
addToDependencies(project, dependencies, arrayOf(dep), excludeConfig = excludeConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun compileOnly(vararg dep: String) = addToDependencies(project, compileOnlyDependencies, dep)
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
fun compileOptional(vararg dep: String) {
|
fun compileOptional(vararg dep: String) {
|
||||||
addToDependencies(project, optionalDependencies, dep, optional = true)
|
addToDependencies(project, optionalDependencies, dep, optional = true)
|
||||||
|
|
|
@ -8,10 +8,7 @@ import com.beust.kobalt.misc.JarUtils
|
||||||
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 java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.OutputStream
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.ZipOutputStream
|
|
||||||
|
|
||||||
class Archives {
|
class Archives {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -20,8 +17,6 @@ class Archives {
|
||||||
@ExportedProjectProperty(doc = "The name of the a jar file with a main() method", type = "String")
|
@ExportedProjectProperty(doc = "The name of the a jar file with a main() method", type = "String")
|
||||||
const val JAR_NAME_WITH_MAIN_CLASS = "jarNameWithMainClass"
|
const val JAR_NAME_WITH_MAIN_CLASS = "jarNameWithMainClass"
|
||||||
|
|
||||||
private val DEFAULT_STREAM_FACTORY = { os : OutputStream -> ZipOutputStream(os) }
|
|
||||||
|
|
||||||
fun defaultArchiveName(project: Project) = project.name + "-" + project.version
|
fun defaultArchiveName(project: Project) = project.name + "-" + project.version
|
||||||
|
|
||||||
fun generateArchive(project: Project,
|
fun generateArchive(project: Project,
|
||||||
|
@ -30,15 +25,15 @@ class Archives {
|
||||||
suffix: String,
|
suffix: String,
|
||||||
includedFiles: List<IncludedFile>,
|
includedFiles: List<IncludedFile>,
|
||||||
expandJarFiles : Boolean = false,
|
expandJarFiles : Boolean = false,
|
||||||
outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY) : File {
|
manifest: java.util.jar.Manifest? = null) : File {
|
||||||
val fullArchiveName = context.variant.archiveName(project, archiveName, suffix)
|
val fullArchiveName = context.variant.archiveName(project, archiveName, suffix)
|
||||||
val archiveDir = File(KFiles.libsDir(project))
|
val archiveDir = File(KFiles.libsDir(project))
|
||||||
val result = File(archiveDir.path, fullArchiveName)
|
val result = File(archiveDir.path, fullArchiveName)
|
||||||
context.logger.log(project.name, 3, "Creating $result")
|
context.logger.log(project.name, 3, "Creating $result")
|
||||||
if (! Features.USE_TIMESTAMPS || isOutdated(project.directory, includedFiles, result)) {
|
if (! Features.USE_TIMESTAMPS || isOutdated(project.directory, includedFiles, result)) {
|
||||||
try {
|
try {
|
||||||
outputStreamFactory(FileOutputStream(result)).use {
|
MetaArchive(result, manifest).use { metaArchive ->
|
||||||
JarUtils.addFiles(project.directory, includedFiles, it, expandJarFiles)
|
JarUtils.addFiles(project.directory, includedFiles, metaArchive, expandJarFiles)
|
||||||
context.logger.log(project.name, 2, "Added ${includedFiles.size} files to $result")
|
context.logger.log(project.name, 2, "Added ${includedFiles.size} files to $result")
|
||||||
context.logger.log(project.name, 1, " Created $result")
|
context.logger.log(project.name, 1, " Created $result")
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.beust.kobalt.archive
|
||||||
|
|
||||||
|
import com.beust.kobalt.Glob
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import org.apache.commons.compress.archivers.ArchiveEntry
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||||
|
import java.io.Closeable
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.nio.file.Files
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipFile as ApacheZipFile
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstraction of a zip/jar/war archive that automatically manages the addition of expanded jar files.
|
||||||
|
* Uses ZipArchiveOutputStream for fast inclusion of expanded jar files.
|
||||||
|
*/
|
||||||
|
class MetaArchive(outputFile: File, val manifest: java.util.jar.Manifest?) : Closeable {
|
||||||
|
private val zos = ZipArchiveOutputStream(outputFile).apply {
|
||||||
|
encoding = "UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addFile(file: File, path: String) {
|
||||||
|
FileInputStream(file).use { inputStream ->
|
||||||
|
val entry = zos.createArchiveEntry(file, path)
|
||||||
|
maybeAddEntry(entry) {
|
||||||
|
addEntry(entry, inputStream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addArchive(jarFile: File) {
|
||||||
|
ApacheZipFile(jarFile).use { jar ->
|
||||||
|
val jarEntries = jar.entries
|
||||||
|
for (entry in jarEntries) {
|
||||||
|
maybeAddEntry(entry) {
|
||||||
|
zos.addRawArchiveEntry(entry, jar.getRawInputStream(entry))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val DEFAULT_JAR_EXCLUDES =
|
||||||
|
Glob("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
|
||||||
|
|
||||||
|
private val seen = hashSetOf<String>()
|
||||||
|
|
||||||
|
private fun okToAdd(name: String): Boolean = ! seen.contains(name)
|
||||||
|
&& ! KFiles.isExcluded(name, DEFAULT_JAR_EXCLUDES)
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
if (manifest != null) {
|
||||||
|
Files.createTempFile("aaa", "bbb").toFile().let { manifestFile ->
|
||||||
|
FileOutputStream(manifestFile).use { fos ->
|
||||||
|
manifest.write(fos)
|
||||||
|
}
|
||||||
|
|
||||||
|
val entry = zos.createArchiveEntry(manifestFile, "META-INF/MANIFEST.MF")
|
||||||
|
addEntry(entry, FileInputStream(manifestFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zos.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addEntry(entry: ArchiveEntry, inputStream: FileInputStream) {
|
||||||
|
zos.putArchiveEntry(entry)
|
||||||
|
inputStream.use { ins ->
|
||||||
|
ins.copyTo(zos, 50 * 1024)
|
||||||
|
}
|
||||||
|
zos.closeArchiveEntry()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun maybeAddEntry(entry: ArchiveEntry, action:() -> Unit) {
|
||||||
|
if (okToAdd(entry.name)) {
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
seen.add(entry.name)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
|
import com.beust.kobalt.TestResult
|
||||||
|
import com.beust.kobalt.api.IBuildListener
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.ProjectBuildStatus
|
import com.beust.kobalt.api.ProjectBuildStatus
|
||||||
|
@ -25,9 +27,14 @@ abstract class BaseProjectRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun runBuildListenersForTask(project: Project, context: KobaltContext, taskName: String, start: Boolean,
|
fun runBuildListenersForTask(project: Project, context: KobaltContext, taskName: String, start: Boolean,
|
||||||
success: Boolean = false) {
|
success: Boolean = false, testResult: TestResult? = null) {
|
||||||
context.pluginInfo.buildListeners.forEach {
|
context.pluginInfo.buildListeners.forEach {
|
||||||
if (start) it.taskStart(project, context, taskName) else it.taskEnd(project, context, taskName, success)
|
if (start) {
|
||||||
|
it.taskStart(project, context, taskName)
|
||||||
|
} else {
|
||||||
|
val info = IBuildListener.TaskEndInfo(success, testResult?.shortMessage, testResult?.longMessage)
|
||||||
|
it.taskEnd(project, context, taskName, info)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@ import java.util.concurrent.ConcurrentHashMap
|
||||||
*/
|
*/
|
||||||
class BuildListeners : IBuildListener, IBuildReportContributor {
|
class BuildListeners : IBuildListener, IBuildReportContributor {
|
||||||
class ProfilerInfo(val taskName: String, val durationMillis: Long)
|
class ProfilerInfo(val taskName: String, val durationMillis: Long)
|
||||||
class ProjectInfo(val projectName: String, var durationMillis: Long = 0)
|
class ProjectInfo(val projectName: String, var durationMillis: Long = 0,
|
||||||
|
var shortMessage: String? = null, var longMessage: String? = null)
|
||||||
|
|
||||||
private val startTimes = ConcurrentHashMap<String, Long>()
|
private val startTimes = ConcurrentHashMap<String, Long>()
|
||||||
private val timings = arrayListOf<ProfilerInfo>()
|
private val timings = arrayListOf<ProfilerInfo>()
|
||||||
|
@ -29,18 +30,21 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IBuildListener
|
// IBuildListener
|
||||||
override fun taskEnd(project: Project, context: KobaltContext, taskName: String, success: Boolean) {
|
override fun taskEnd(project: Project, context: KobaltContext, taskName: String, info: IBuildListener.TaskEndInfo) {
|
||||||
|
val success = info.success
|
||||||
if (! success) hasFailures = true
|
if (! success) hasFailures = true
|
||||||
startTimes[taskName]?.let {
|
startTimes[taskName]?.let {
|
||||||
val taskTime = System.currentTimeMillis() - it
|
val taskTime = System.currentTimeMillis() - it
|
||||||
timings.add(ProfilerInfo(taskName, taskTime))
|
timings.add(ProfilerInfo(taskName, taskTime))
|
||||||
projectInfos[project.name]?.let {
|
projectInfos[project.name]?.let {
|
||||||
it.durationMillis += taskTime.toLong()
|
it.durationMillis += taskTime
|
||||||
|
if (info.shortMessage != null && it.shortMessage == null) it.shortMessage = info.shortMessage
|
||||||
|
if (info.longMessage != null && it.longMessage == null) it.longMessage = info.longMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val projectStatuses = arrayListOf<Pair<Project, ProjectBuildStatus>>()
|
private val projectStatuses = arrayListOf<Pair<Project, String>>()
|
||||||
|
|
||||||
// IBuildListener
|
// IBuildListener
|
||||||
override fun projectStart(project: Project, context: KobaltContext) {
|
override fun projectStart(project: Project, context: KobaltContext) {
|
||||||
|
@ -49,7 +53,9 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
|
||||||
|
|
||||||
// IBuildListener
|
// IBuildListener
|
||||||
override fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) {
|
override fun projectEnd(project: Project, context: KobaltContext, status: ProjectBuildStatus) {
|
||||||
projectStatuses.add(Pair(project, status))
|
val shortMessage = projectInfos[project.name]?.shortMessage
|
||||||
|
val statusText = status.toString() + (if (shortMessage != null) " ($shortMessage)" else "")
|
||||||
|
projectStatuses.add(Pair(project, statusText))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IBuildReportContributor
|
// IBuildReportContributor
|
||||||
|
@ -70,10 +76,15 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the longest short message so we can create a column long enough to contain it
|
||||||
|
val width = 12 + (projectInfos.values.map { it.shortMessage?.length ?: 0 }.maxBy { it } ?: 0)
|
||||||
|
|
||||||
fun col1(s: String) = String.format(" %1\$-30s", s)
|
fun col1(s: String) = String.format(" %1\$-30s", s)
|
||||||
fun col2(s: String) = String.format(" %1\$-13s", s)
|
fun col2(s: String) = String.format(" %1\$-${width}s", s)
|
||||||
fun col3(s: String) = String.format(" %1\$-8s", s)
|
fun col3(s: String) = String.format(" %1\$-8s", s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Only print the build report if there is more than one project and at least one of them failed
|
// Only print the build report if there is more than one project and at least one of them failed
|
||||||
if (timings.any()) {
|
if (timings.any()) {
|
||||||
// if (timings.size > 1 && hasFailures) {
|
// if (timings.size > 1 && hasFailures) {
|
||||||
|
@ -83,7 +94,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
|
||||||
table.append(AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2, indent = 10) + "\n")
|
table.append(AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2, indent = 10) + "\n")
|
||||||
projectStatuses.forEach { pair ->
|
projectStatuses.forEach { pair ->
|
||||||
val projectName = pair.first.name
|
val projectName = pair.first.name
|
||||||
val cl = listOf(col1(projectName), col2(pair.second.toString()),
|
val cl = listOf(col1(projectName), col2(pair.second),
|
||||||
col3(formatMillisLeft(projectInfos[projectName]!!.durationMillis, 8)))
|
col3(formatMillisLeft(projectInfos[projectName]!!.durationMillis, 8)))
|
||||||
.joinToString(AsciiArt.verticalBar)
|
.joinToString(AsciiArt.verticalBar)
|
||||||
table.append(" " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar + "\n")
|
table.append(" " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar + "\n")
|
||||||
|
|
|
@ -70,7 +70,12 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager
|
||||||
copyResources(project, context, SourceSet.of(isTest))
|
copyResources(project, context, SourceSet.of(isTest))
|
||||||
|
|
||||||
val fullClasspath = dependencyManager.calculateDependencies(project, context,
|
val fullClasspath = dependencyManager.calculateDependencies(project, context,
|
||||||
scopes = if (isTest) listOf(Scope.COMPILE, Scope.TEST) else listOf(Scope.COMPILE))
|
scopes = if (isTest) {
|
||||||
|
listOf(Scope.COMPILE, Scope.COMPILEONLY, Scope.TEST)
|
||||||
|
} else {
|
||||||
|
listOf(Scope.COMPILE, Scope.COMPILEONLY)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
File(project.directory, buildDirectory.path).mkdirs()
|
File(project.directory, buildDirectory.path).mkdirs()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ import java.lang.reflect.InvocationTargetException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.*
|
import java.util.concurrent.*
|
||||||
|
|
||||||
open class TaskResult2<T>(success: Boolean, errorMessage: String?, val value: T) : TaskResult(success, errorMessage) {
|
open class TaskResult2<T>(success: Boolean, testResult: TestResult? = null,
|
||||||
|
errorMessage: String? = null, val value: T) : TaskResult(success, testResult, errorMessage) {
|
||||||
override fun toString() = com.beust.kobalt.misc.toString("TaskResult", "value", value, "success", success)
|
override fun toString() = com.beust.kobalt.misc.toString("TaskResult", "value", value, "success", success)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +394,7 @@ fun main(argv: Array<String>) {
|
||||||
object: IWorker<String> {
|
object: IWorker<String> {
|
||||||
override fun call(): TaskResult2<String>? {
|
override fun call(): TaskResult2<String>? {
|
||||||
kobaltLog(1, " Running worker $it")
|
kobaltLog(1, " Running worker $it")
|
||||||
return TaskResult2(true, null, it)
|
return TaskResult2(true, value = it)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val priority: Int get() = 0
|
override val priority: Int get() = 0
|
||||||
|
|
|
@ -16,17 +16,23 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
||||||
abstract val mainClass: String
|
abstract val mainClass: String
|
||||||
abstract val annotationPackage: String
|
abstract val annotationPackage: String
|
||||||
abstract val runnerName: String
|
abstract val runnerName: String
|
||||||
|
open var shortMessage: String? = null
|
||||||
|
open var longMessage: String? = null
|
||||||
|
|
||||||
abstract fun args(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
abstract fun args(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
testConfig: TestConfig) : List<String>
|
testConfig: TestConfig) : List<String>
|
||||||
|
|
||||||
|
open fun onFinish(project: Project) {}
|
||||||
|
|
||||||
open val extraClasspath: List<String> = emptyList()
|
open val extraClasspath: List<String> = emptyList()
|
||||||
|
|
||||||
open fun filterTestClasses(classes: List<String>) : List<String> = classes
|
open fun filterTestClasses(classes: List<String>) : List<String> = classes
|
||||||
|
|
||||||
override fun run(project: Project, context: KobaltContext, configName: String,
|
override fun run(project: Project, context: KobaltContext, configName: String,
|
||||||
classpath: List<IClasspathDependency>)
|
classpath: List<IClasspathDependency>) : TaskResult {
|
||||||
= TaskResult(runTests(project, context, classpath, configName))
|
val tr = runTests(project, context, classpath, configName)
|
||||||
|
return TaskResult(tr.success, testResult = tr)
|
||||||
|
}
|
||||||
|
|
||||||
override fun affinity(project: Project, context: KobaltContext) : Int {
|
override fun affinity(project: Project, context: KobaltContext) : Int {
|
||||||
val result =
|
val result =
|
||||||
|
@ -99,7 +105,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
||||||
* @return true if all the tests passed
|
* @return true if all the tests passed
|
||||||
*/
|
*/
|
||||||
open fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
open fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
configName: String) : Boolean {
|
configName: String) : TestResult {
|
||||||
var result = false
|
var result = false
|
||||||
|
|
||||||
context.logger.log(project.name, 1, "Running tests with " + runnerName)
|
context.logger.log(project.name, 1, "Running tests with " + runnerName)
|
||||||
|
@ -140,7 +146,9 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
||||||
} else {
|
} else {
|
||||||
throw KobaltException("Couldn't find a test configuration named \"$configName\"")
|
throw KobaltException("Couldn't find a test configuration named \"$configName\"")
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
onFinish(project)
|
||||||
|
return TestResult(result, shortMessage, longMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -91,7 +91,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
dependencyFilter = dependencyManager.createDependencyFilter(project, project.testDependencies),
|
dependencyFilter = dependencyManager.createDependencyFilter(project, project.testDependencies),
|
||||||
scopes = listOf(Scope.TEST))
|
scopes = listOf(Scope.TEST))
|
||||||
val compileDependencies = dependencyManager.calculateDependencies(project, context,
|
val compileDependencies = dependencyManager.calculateDependencies(project, context,
|
||||||
scopes = listOf(Scope.COMPILE))
|
scopes = listOf(Scope.COMPILE, Scope.COMPILEONLY))
|
||||||
val allDependencies = (testDependencies + compileDependencies).distinct()
|
val allDependencies = (testDependencies + compileDependencies).distinct()
|
||||||
return testContributor.run(project, context, configName, allDependencies.toList())
|
return testContributor.run(project, context, configName, allDependencies.toList())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -54,12 +54,12 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
|
||||||
runBuildListenersForTask(project, context, task.name, start = true)
|
runBuildListenersForTask(project, context, task.name, start = true)
|
||||||
logger.log(project.name, 1,
|
logger.log(project.name, 1,
|
||||||
AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${project.name}:${task.name}"))
|
AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${project.name}:${task.name}"))
|
||||||
val thisResult = if (dryRun) TaskResult2(true, null, task) else task.call()
|
val thisResult = if (dryRun) TaskResult2(true, value = task) else task.call()
|
||||||
if (lastResult.success) {
|
if (lastResult.success) {
|
||||||
lastResult = thisResult
|
lastResult = thisResult
|
||||||
}
|
}
|
||||||
runBuildListenersForTask(project, context, task.name, start = false,
|
runBuildListenersForTask(project, context, task.name, start = false,
|
||||||
success = thisResult.success)
|
success = thisResult.success, testResult = thisResult.testResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
graph.freeNodes.forEach { graph.removeNode(it) }
|
graph.freeNodes.forEach { graph.removeNode(it) }
|
||||||
|
@ -69,7 +69,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
|
||||||
runBuildListenersForProject(project, context, false,
|
runBuildListenersForProject(project, context, false,
|
||||||
if (lastResult.success) ProjectBuildStatus.SUCCESS else ProjectBuildStatus.FAILED)
|
if (lastResult.success) ProjectBuildStatus.SUCCESS else ProjectBuildStatus.FAILED)
|
||||||
|
|
||||||
return TaskResult2(lastResult.success, lastResult.errorMessage, this)
|
return TaskResult2(lastResult.success, errorMessage = lastResult.errorMessage, value = this)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,8 @@ class TaskManager @Inject constructor(val args: Args,
|
||||||
object : BasePluginTask(plugin, name, description, group, project) {
|
object : BasePluginTask(plugin, name, description, group, project) {
|
||||||
override fun call(): TaskResult2<ITask> {
|
override fun call(): TaskResult2<ITask> {
|
||||||
val taskResult = task(project)
|
val taskResult = task(project)
|
||||||
return TaskResult2(taskResult.success, taskResult.errorMessage, this)
|
return TaskResult2(taskResult.success, errorMessage = taskResult.errorMessage, value = this,
|
||||||
|
testResult = taskResult.testResult)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
dependsOn.forEach { dependsOn(it, name) }
|
dependsOn.forEach { dependsOn(it, name) }
|
||||||
|
@ -321,7 +322,7 @@ class TaskWorker(val tasks: List<ITask>, val dryRun: Boolean, val pluginInfo: Pl
|
||||||
success = success and tr.success
|
success = success and tr.success
|
||||||
if (tr.errorMessage != null) errorMessages.add(tr.errorMessage)
|
if (tr.errorMessage != null) errorMessages.add(tr.errorMessage)
|
||||||
}
|
}
|
||||||
return TaskResult2(success, errorMessages.joinToString("\n"), tasks[0])
|
return TaskResult2(success, errorMessage = errorMessages.joinToString("\n"), value = tasks[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// override val timeOut : Long = 10000
|
// override val timeOut : Long = 10000
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.beust.kobalt.internal
|
||||||
|
|
||||||
import com.beust.kobalt.AsciiArt
|
import com.beust.kobalt.AsciiArt
|
||||||
import com.beust.kobalt.TestConfig
|
import com.beust.kobalt.TestConfig
|
||||||
|
import com.beust.kobalt.TestResult
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
@ -12,8 +13,12 @@ import org.testng.remote.strprotocol.JsonMessageSender
|
||||||
import org.testng.remote.strprotocol.MessageHelper
|
import org.testng.remote.strprotocol.MessageHelper
|
||||||
import org.testng.remote.strprotocol.MessageHub
|
import org.testng.remote.strprotocol.MessageHub
|
||||||
import org.testng.remote.strprotocol.TestResultMessage
|
import org.testng.remote.strprotocol.TestResultMessage
|
||||||
|
import org.w3c.dom.Attr
|
||||||
|
import org.xml.sax.InputSource
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileReader
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory
|
||||||
|
|
||||||
class TestNgRunner : GenericTestRunner() {
|
class TestNgRunner : GenericTestRunner() {
|
||||||
|
|
||||||
|
@ -60,11 +65,40 @@ class TestNgRunner : GenericTestRunner() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract test results from testng-results.xml and initialize shortMessage.
|
||||||
|
*/
|
||||||
|
override fun onFinish(project: Project) {
|
||||||
|
File(defaultOutput(project), "testng-results.xml").let { file ->
|
||||||
|
val ins = InputSource(FileReader(file))
|
||||||
|
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(ins)
|
||||||
|
|
||||||
|
val root = doc.documentElement
|
||||||
|
var failed = 0
|
||||||
|
var skipped = 0
|
||||||
|
var passed = 0
|
||||||
|
repeat(root.attributes.length) {
|
||||||
|
val attribute = root.attributes.item(it)
|
||||||
|
if (attribute is Attr) when (attribute.name) {
|
||||||
|
"failed" -> failed = Integer.parseInt(attribute.value)
|
||||||
|
"skipped" -> skipped = Integer.parseInt(attribute.value)
|
||||||
|
"passed" -> passed = Integer.parseInt(attribute.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed == 0) {
|
||||||
|
shortMessage = "$passed tests"
|
||||||
|
} else if (failed > 0) {
|
||||||
|
shortMessage = "$failed failed" + (if (skipped > 0) ", $skipped skipped" else "") + " tests"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val VERSION_6_10 = StringVersion("6.10")
|
val VERSION_6_10 = StringVersion("6.10")
|
||||||
|
|
||||||
fun _runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
fun _runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
// override fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
// override fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
configName: String): Boolean {
|
configName: String): TestResult {
|
||||||
|
|
||||||
val testConfig = project.testConfigs.firstOrNull { it.name == configName }
|
val testConfig = project.testConfigs.firstOrNull { it.name == configName }
|
||||||
|
|
||||||
|
@ -85,7 +119,7 @@ class TestNgRunner : GenericTestRunner() {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
} else {
|
} else {
|
||||||
return true
|
return TestResult(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +136,8 @@ class TestNgRunner : GenericTestRunner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayPrettyColors(project: Project, context: KobaltContext,
|
private fun displayPrettyColors(project: Project, context: KobaltContext,
|
||||||
classpath: List<IClasspathDependency>, testConfig: TestConfig, versions: Pair<String, String>): Boolean {
|
classpath: List<IClasspathDependency>, testConfig: TestConfig, versions: Pair<String, String>)
|
||||||
|
: TestResult {
|
||||||
val port = 2345
|
val port = 2345
|
||||||
// launchRemoteServer(project, context, classpath, testConfig, versions, port)
|
// launchRemoteServer(project, context, classpath, testConfig, versions, port)
|
||||||
|
|
||||||
|
@ -151,7 +186,7 @@ class TestNgRunner : GenericTestRunner() {
|
||||||
val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n"))
|
val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n"))
|
||||||
kobaltLog(1, " " + it.cls + "." + it.method + "\n " + top)
|
kobaltLog(1, " " + it.cls + "." + it.method + "\n " + top)
|
||||||
}
|
}
|
||||||
return failed.isEmpty() && skipped.isEmpty()
|
return TestResult(failed.isEmpty() && skipped.isEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchRemoteServer(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
fun launchRemoteServer(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
|
|
|
@ -108,6 +108,9 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
|
||||||
addAll(project.compileDependencies)
|
addAll(project.compileDependencies)
|
||||||
addAll(project.compileProvidedDependencies)
|
addAll(project.compileProvidedDependencies)
|
||||||
}
|
}
|
||||||
|
if (scopes.contains(Scope.COMPILEONLY)) {
|
||||||
|
addAll(project.compileOnlyDependencies)
|
||||||
|
}
|
||||||
if (scopes.contains(Scope.RUNTIME)) {
|
if (scopes.contains(Scope.RUNTIME)) {
|
||||||
addAll(project.compileRuntimeDependencies)
|
addAll(project.compileRuntimeDependencies)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ object Filters {
|
||||||
override fun accept(p0: DependencyNode, p1: MutableList<DependencyNode>): Boolean {
|
override fun accept(p0: DependencyNode, p1: MutableList<DependencyNode>): Boolean {
|
||||||
val result = p0.dependency != null && ! p0.dependency.optional
|
val result = p0.dependency != null && ! p0.dependency.optional
|
||||||
if (! result) {
|
if (! result) {
|
||||||
kobaltLog(2, "Excluding from optional filter: $p0")
|
kobaltLog(3, "Excluding from optional filter: $p0")
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,13 +38,27 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER) : Artifact
|
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER) : Artifact
|
||||||
= resolve(id, scope, filter).root.artifact
|
= resolve(id, scope, filter).root.artifact
|
||||||
|
|
||||||
fun resolve(id: String, scope: Scope? = null,
|
fun resolve(passedId: String, scope: Scope? = null,
|
||||||
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER,
|
filter: DependencyFilter = Filters.EXCLUDE_OPTIONAL_FILTER,
|
||||||
repos: List<String> = emptyList()): DependencyResult {
|
repos: List<String> = emptyList()): DependencyResult {
|
||||||
val dependencyRequest = DependencyRequest(createCollectRequest(id, scope, repos), filter)
|
val mavenId = MavenId.toMavenId(passedId)
|
||||||
|
val id =
|
||||||
|
if (isRangeVersion(mavenId)) {
|
||||||
|
val artifact = DefaultArtifact(mavenId)
|
||||||
|
val request = VersionRangeRequest(artifact, createRepos(repos), null)
|
||||||
|
val rr = system.resolveVersionRange(session, request)
|
||||||
|
val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.classifier,
|
||||||
|
artifact.extension, rr.highestVersion.toString())
|
||||||
|
artifactToId(newArtifact)
|
||||||
|
} else {
|
||||||
|
passedId
|
||||||
|
}
|
||||||
|
|
||||||
|
val collectRequest = createCollectRequest(id, scope, repos)
|
||||||
|
val dependencyRequest = DependencyRequest(collectRequest, filter)
|
||||||
val result = system.resolveDependencies(session, dependencyRequest)
|
val result = system.resolveDependencies(session, dependencyRequest)
|
||||||
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
// GraphUtil.displayGraph(listOf(result.root), { it -> it.children },
|
||||||
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
// { it: DependencyNode, indent: String -> println(indent + it.toString()) })
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +72,7 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
val rr = resolve(id, scope, filter)
|
val rr = resolve(id, scope, filter)
|
||||||
val children =
|
val children =
|
||||||
rr.root.children.filter {
|
rr.root.children.filter {
|
||||||
filter == null || filter.accept(DefaultDependencyNode(it.dependency), emptyList())
|
filter.accept(DefaultDependencyNode(it.dependency), emptyList())
|
||||||
}.filter {
|
}.filter {
|
||||||
it.dependency.scope != Scope.SYSTEM.scope
|
it.dependency.scope != Scope.SYSTEM.scope
|
||||||
}
|
}
|
||||||
|
@ -109,6 +123,9 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createRepos(repos: List<String>) : List<RemoteRepository>
|
||||||
|
= kobaltRepositories + repos.map { createRepo(HostConfig(it)) }
|
||||||
|
|
||||||
private fun createCollectRequest(id: String, scope: Scope? = null, repos: List<String> = emptyList())
|
private fun createCollectRequest(id: String, scope: Scope? = null, repos: List<String> = emptyList())
|
||||||
= CollectRequest().apply {
|
= CollectRequest().apply {
|
||||||
val allIds = arrayListOf(MavenId.toMavenId(id))
|
val allIds = arrayListOf(MavenId.toMavenId(id))
|
||||||
|
@ -116,6 +133,6 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||||
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
|
dependencies = allIds.map { Dependency(DefaultArtifact(it), scope?.scope) }
|
||||||
|
|
||||||
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
|
root = Dependency(DefaultArtifact(MavenId.toMavenId(id)), scope?.scope)
|
||||||
repositories = kobaltRepositories + repos.map { createRepo(HostConfig(it)) }
|
repositories = createRepos(repos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ sealed class Scope(val scope: String, val dependencyLambda: (Project) -> List<IC
|
||||||
|
|
||||||
object COMPILE : Scope(JavaScopes.COMPILE, Project::compileDependencies)
|
object COMPILE : Scope(JavaScopes.COMPILE, Project::compileDependencies)
|
||||||
object PROVIDED : Scope(JavaScopes.PROVIDED, Project::compileProvidedDependencies)
|
object PROVIDED : Scope(JavaScopes.PROVIDED, Project::compileProvidedDependencies)
|
||||||
|
object COMPILEONLY : Scope("compileOnly", Project::compileOnlyDependencies)
|
||||||
object SYSTEM : Scope(JavaScopes.SYSTEM, { project -> emptyList() })
|
object SYSTEM : Scope(JavaScopes.SYSTEM, { project -> emptyList() })
|
||||||
object RUNTIME : Scope(JavaScopes.RUNTIME, Project::compileRuntimeDependencies)
|
object RUNTIME : Scope(JavaScopes.RUNTIME, Project::compileRuntimeDependencies)
|
||||||
object TEST : Scope(JavaScopes.TEST, Project::testDependencies)
|
object TEST : Scope(JavaScopes.TEST, Project::testDependencies)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Git @Inject constructor() {
|
||||||
if (uploadResult.success && enabled) {
|
if (uploadResult.success && enabled) {
|
||||||
val tagSuccess = tagRelease(project, annotated, tag, message)
|
val tagSuccess = tagRelease(project, annotated, tag, message)
|
||||||
if (! tagSuccess) {
|
if (! tagSuccess) {
|
||||||
TaskResult(false, "Couldn't tag the project")
|
TaskResult(false, errorMessage = "Couldn't tag the project")
|
||||||
} else {
|
} else {
|
||||||
TaskResult()
|
TaskResult()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
import com.beust.kobalt.*
|
import com.beust.kobalt.From
|
||||||
|
import com.beust.kobalt.IFileSpec
|
||||||
|
import com.beust.kobalt.IncludedFile
|
||||||
|
import com.beust.kobalt.To
|
||||||
|
import com.beust.kobalt.archive.MetaArchive
|
||||||
import com.google.common.io.CharStreams
|
import com.google.common.io.CharStreams
|
||||||
import java.io.*
|
import java.io.File
|
||||||
import java.util.jar.JarEntry
|
import java.io.FileOutputStream
|
||||||
|
import java.io.InputStreamReader
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
import java.util.jar.JarInputStream
|
|
||||||
import java.util.zip.ZipEntry
|
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import java.util.zip.ZipOutputStream
|
|
||||||
|
|
||||||
class JarUtils {
|
class JarUtils {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -19,18 +21,15 @@ class JarUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addFiles(directory: String, files: List<IncludedFile>, target: ZipOutputStream,
|
fun addFiles(directory: String, files: List<IncludedFile>, metaArchive: MetaArchive,
|
||||||
expandJarFiles: Boolean,
|
expandJarFiles: Boolean,
|
||||||
onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
||||||
files.forEach {
|
files.forEach {
|
||||||
addSingleFile(directory, it, target, expandJarFiles, onError)
|
addSingleFile(directory, it, metaArchive, expandJarFiles, onError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val DEFAULT_JAR_EXCLUDES =
|
fun addSingleFile(directory: String, file: IncludedFile, metaArchive: MetaArchive,
|
||||||
Glob("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
|
|
||||||
|
|
||||||
fun addSingleFile(directory: String, file: IncludedFile, outputStream: ZipOutputStream,
|
|
||||||
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
||||||
val foundFiles = file.allFromFiles(directory)
|
val foundFiles = file.allFromFiles(directory)
|
||||||
foundFiles.forEach { foundFile ->
|
foundFiles.forEach { foundFile ->
|
||||||
|
@ -49,41 +48,21 @@ class JarUtils {
|
||||||
|
|
||||||
// Directory
|
// Directory
|
||||||
val includedFile = IncludedFile(From(""), To(""), listOf(IFileSpec.GlobSpec("**")))
|
val includedFile = IncludedFile(From(""), To(""), listOf(IFileSpec.GlobSpec("**")))
|
||||||
addSingleFile(localFile.path, includedFile, outputStream, expandJarFiles)
|
addSingleFile(localFile.path, includedFile, metaArchive, expandJarFiles)
|
||||||
} else {
|
} else {
|
||||||
if (file.expandJarFiles && foundFile.name.endsWith(".jar") && ! file.from.contains("resources")) {
|
|
||||||
kobaltLog(2, " Writing contents of jar file $foundFile")
|
|
||||||
JarInputStream(FileInputStream(localFile)).use { stream ->
|
|
||||||
var entry = stream.nextEntry
|
|
||||||
while (entry != null) {
|
|
||||||
if (!entry.isDirectory && !KFiles.isExcluded(entry.name, DEFAULT_JAR_EXCLUDES)) {
|
|
||||||
addEntry(stream, JarEntry(entry), outputStream, onError)
|
|
||||||
}
|
|
||||||
entry = stream.nextEntry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val entryFileName = KFiles.fixSlashes(file.to(foundFile.path))
|
|
||||||
val entry = JarEntry(entryFileName)
|
|
||||||
entry.time = localFile.lastModified()
|
|
||||||
FileInputStream(localFile).use { stream ->
|
|
||||||
addEntry(stream, entry, outputStream, onError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addEntry(inputStream: InputStream, entry: ZipEntry, outputStream: ZipOutputStream,
|
|
||||||
onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
|
||||||
try {
|
try {
|
||||||
outputStream.putNextEntry(entry)
|
if (file.expandJarFiles && foundFile.name.endsWith(".jar") && !file.from.contains("resources")) {
|
||||||
inputStream.copyTo(outputStream, 50 * 1024)
|
kobaltLog(2, " Writing contents of jar file $foundFile")
|
||||||
outputStream.closeEntry()
|
metaArchive.addArchive(foundFile)
|
||||||
|
} else {
|
||||||
|
metaArchive.addFile(File(directory, fromFile.path), foundFile.path)
|
||||||
|
}
|
||||||
} catch(ex: Exception) {
|
} catch(ex: Exception) {
|
||||||
onError(ex)
|
onError(ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun extractTextFile(zip : ZipFile, fileName: String) : String? {
|
fun extractTextFile(zip : ZipFile, fileName: String) : String? {
|
||||||
val enumEntries = zip.entries()
|
val enumEntries = zip.entries()
|
||||||
|
|
|
@ -345,6 +345,11 @@ public class Main {
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(entryPath.getParent());
|
Files.createDirectories(entryPath.getParent());
|
||||||
Files.copy(zipFile.getInputStream(entry), entryPath, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(zipFile.getInputStream(entry), entryPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
if (!isWindows() && entry.getName().endsWith(KOBALTW)) {
|
||||||
|
if (!entryPath.toFile().setExecutable(true)) {
|
||||||
|
log(1, "Couldn't make distribution " + KOBALTW + " executable");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (FileSystemException ex) {
|
} catch (FileSystemException ex) {
|
||||||
log(2, "Couldn't copy to " + entryPath);
|
log(2, "Couldn't copy to " + entryPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,11 +94,11 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (result) {
|
return if (result) {
|
||||||
TaskResult(true, "Compilation succeeded")
|
TaskResult(true, errorMessage = "Compilation succeeded")
|
||||||
} else {
|
} else {
|
||||||
val message = "Compilation errors, command:\n$command\n" + errorMessage
|
val message = "Compilation errors, command:\n$command\n" + errorMessage
|
||||||
logk(1, message)
|
logk(1, message)
|
||||||
TaskResult(false, message)
|
TaskResult(false, errorMessage = message)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ class KotlinCompiler @Inject constructor(
|
||||||
return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project)
|
return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return invokeCompilerDirectly(projectName ?: "kobalt-" + Random().nextInt(), outputDir,
|
return invokeCompilerDirectly(project, projectName ?: "kobalt-" + Random().nextInt(), outputDir,
|
||||||
info, classpath, filesToCompile)
|
info, classpath, filesToCompile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,14 +126,23 @@ class KotlinCompiler @Inject constructor(
|
||||||
// The Kotlin compiler issues warnings on stderr :-(
|
// The Kotlin compiler issues warnings on stderr :-(
|
||||||
containsErrors = { errors: List<String> -> errors.any { it.contains("rror")} }
|
containsErrors = { errors: List<String> -> errors.any { it.contains("rror")} }
|
||||||
}).invoke()
|
}).invoke()
|
||||||
return TaskResult(result == 0, "Error while compiling")
|
return TaskResult(result == 0, errorMessage = "Error while compiling")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun invokeCompilerDirectly(projectName: String, outputDir: String?, info: CompilerActionInfo,
|
private fun invokeCompilerDirectly(project: Project?, projectName: String, outputDir: String?,
|
||||||
classpathString: String, filesToCompile: Int): TaskResult {
|
info: CompilerActionInfo, classpathString: String, filesToCompile: Int): TaskResult {
|
||||||
val sourceFiles = info.sourceFiles
|
val sourceFiles = info.sourceFiles
|
||||||
val friends = info.friendPaths.toTypedArray()
|
val friends = info.friendPaths.toTypedArray()
|
||||||
val args = K2JVMCompilerArguments().apply {
|
|
||||||
|
// Collect the compiler args from kotlinCompiler{} and from settings.xml and parse them
|
||||||
|
val args2 = (kotlinConfig(project)?.args ?: arrayListOf<String>()) +
|
||||||
|
(settings.kobaltCompilerFlags?.split(" ") ?: listOf<String>())
|
||||||
|
val args = K2JVMCompilerArguments()
|
||||||
|
val compiler = K2JVMCompiler()
|
||||||
|
compiler.parseArguments(args2.toTypedArray(), args)
|
||||||
|
|
||||||
|
// Override important arguments with our values
|
||||||
|
args.apply {
|
||||||
moduleName = projectName
|
moduleName = projectName
|
||||||
destination = outputDir
|
destination = outputDir
|
||||||
classpath = classpathString
|
classpath = classpathString
|
||||||
|
@ -224,7 +233,7 @@ class KotlinCompiler @Inject constructor(
|
||||||
if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) {
|
if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) {
|
||||||
log(2, " Kotlin incremental compilation is disabled")
|
log(2, " Kotlin incremental compilation is disabled")
|
||||||
val duration = benchmarkMillis {
|
val duration = benchmarkMillis {
|
||||||
K2JVMCompiler().exec(collector, Services.Builder().build(), args)
|
compiler.exec(collector, Services.Builder().build(), args)
|
||||||
}
|
}
|
||||||
log(1, " Regular compilation time: ${duration.first} ms")
|
log(1, " Regular compilation time: ${duration.first} ms")
|
||||||
TaskResult(duration.second == ExitCode.OK)
|
TaskResult(duration.second == ExitCode.OK)
|
||||||
|
|
|
@ -88,7 +88,7 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager,
|
||||||
|
|
||||||
val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) }
|
val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) }
|
||||||
return Archives.generateArchive(project, context, war.name, ".war", files,
|
return Archives.generateArchive(project, context, war.name, ".war", files,
|
||||||
false /* don't expand jar files */, jarFactory)
|
false /* don't expand jar files */, manifest)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@ class BintrayApi @Inject constructor(val http: Http,
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
} else {
|
} else {
|
||||||
error(" Errors while uploading:\n" + errorMessages.map { " $it" }.joinToString("\n"))
|
error(" Errors while uploading:\n" + errorMessages.map { " $it" }.joinToString("\n"))
|
||||||
return TaskResult(false, errorMessages.joinToString("\n"))
|
return TaskResult(false, errorMessage = errorMessages.joinToString("\n"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn("Found no artifacts to upload")
|
warn("Found no artifacts to upload")
|
||||||
|
|
|
@ -153,7 +153,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
TaskResult()
|
TaskResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
val result = TaskResult(tmpResult.success, messages.joinToString("\n "))
|
val result = TaskResult(tmpResult.success, errorMessage = messages.joinToString("\n "))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
kobalt.version=1.0.58
|
kobalt.version=1.0.60
|
||||||
|
|
|
@ -2,36 +2,37 @@ import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.plugin.packaging.*
|
import com.beust.kobalt.plugin.packaging.*
|
||||||
import com.beust.kobalt.plugin.application.*
|
import com.beust.kobalt.plugin.application.*
|
||||||
{{imports}}
|
{{imports}}
|
||||||
|
{{#repositories.length}}
|
||||||
val bs = buildScript {
|
val bs = buildScript {
|
||||||
repos({{{repositories}}})
|
repos({{{repositories}}})
|
||||||
}
|
}
|
||||||
|
{{/repositories.length}}
|
||||||
{{#properties}}
|
{{#properties}}
|
||||||
val {{first}} = "{{second}}"
|
val {{first}} = "{{second}}"
|
||||||
{{/properties}}
|
{{/properties}}
|
||||||
|
|
||||||
val p = {{directive}} {
|
val p = {{directive}} {
|
||||||
|
|
||||||
name = "{{name}}"
|
name = "{{name}}"
|
||||||
group = "{{group}}"
|
group = "{{group}}"
|
||||||
artifactId = name
|
artifactId = name
|
||||||
version = "{{version}}"
|
version = "{{version}}"
|
||||||
|
{{#sourceDirectories.length}}
|
||||||
sourceDirectories {
|
sourceDirectories {
|
||||||
{{#sourceDirectories}}
|
{{#sourceDirectories}}
|
||||||
path("{{toString}}")
|
path("{{toString}}")
|
||||||
{{/sourceDirectories}}
|
{{/sourceDirectories}}
|
||||||
}
|
}
|
||||||
|
{{/sourceDirectories.length}}
|
||||||
|
{{#sourceDirectoriesTest.length}}
|
||||||
sourceDirectoriesTest {
|
sourceDirectoriesTest {
|
||||||
{{#sourceDirectoriesTest}}
|
{{#sourceDirectoriesTest}}
|
||||||
path("{{toString}}")
|
path("{{toString}}")
|
||||||
{{/sourceDirectoriesTest}}
|
{{/sourceDirectoriesTest}}
|
||||||
}
|
}
|
||||||
|
{{/sourceDirectoriesTest.length}}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// compile("com.beust:jcommander:1.48")
|
// compile("com.beust:jcommander:1.68")
|
||||||
{{#mainDependencies}}
|
{{#mainDependencies}}
|
||||||
compile("{{groupId}}:{{artifactId}}:{{version}}")
|
compile("{{groupId}}:{{artifactId}}:{{version}}")
|
||||||
{{/mainDependencies}}
|
{{/mainDependencies}}
|
||||||
|
@ -42,7 +43,6 @@ val p = {{directive}} {
|
||||||
{{#testDependencies}}
|
{{#testDependencies}}
|
||||||
compile("{{groupId}}:{{artifactId}}:{{version}}")
|
compile("{{groupId}}:{{artifactId}}:{{version}}")
|
||||||
{{/testDependencies}}
|
{{/testDependencies}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assemble {
|
assemble {
|
||||||
|
@ -53,6 +53,4 @@ val p = {{directive}} {
|
||||||
application {
|
application {
|
||||||
mainClass = "com.example.{{mainClass}}"
|
mainClass = "com.example.{{mainClass}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package com.beust.kobalt
|
package com.beust.kobalt
|
||||||
|
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.*
|
||||||
import com.beust.kobalt.misc.kobaltLog
|
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.jar.*
|
import java.util.jar.*
|
||||||
|
|
||||||
|
@ -37,6 +38,11 @@ class VerifyKobaltZipTest : KobaltTest() {
|
||||||
throw KobaltException("kobaltw has wrong line endings")
|
throw KobaltException("kobaltw has wrong line endings")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (OperatingSystem.current().isWindows()) {
|
||||||
|
warn("Can't determine if kobaltw is executable under Windows")
|
||||||
|
} else if (!Files.isExecutable(Paths.get("dist/kobaltw"))) {
|
||||||
|
throw KobaltException("kobaltw has invalid permissions")
|
||||||
|
}
|
||||||
foundKobaltw = true
|
foundKobaltw = true
|
||||||
} else if (entry.name.endsWith(mainJarFilePath)) {
|
} else if (entry.name.endsWith(mainJarFilePath)) {
|
||||||
val ins = zipFile.getInputStream(entry)
|
val ins = zipFile.getInputStream(entry)
|
||||||
|
|
|
@ -31,7 +31,7 @@ class DynamicGraphTest {
|
||||||
override fun call() : TaskResult2<T> {
|
override fun call() : TaskResult2<T> {
|
||||||
kobaltLog(2, "Running node $n")
|
kobaltLog(2, "Running node $n")
|
||||||
runNodes.add(n)
|
runNodes.add(n)
|
||||||
return TaskResult2(errorFunction(n), null, n)
|
return TaskResult2(errorFunction(n), value = n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue