mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Added ITestJvmFlagContributor.
This commit is contained in:
parent
8e52d3ccb6
commit
3f60aeba54
6 changed files with 39 additions and 9 deletions
|
@ -0,0 +1,8 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
/**
|
||||
* Plug-ins that add flags to the JVM used to run tests should implement this interface.
|
||||
*/
|
||||
interface ITestJvmFlagContributor : IContributor {
|
||||
fun testJvmFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>) : List<String>
|
||||
}
|
|
@ -18,7 +18,7 @@ abstract class GenericTestRunner : ITestRunnerContributor {
|
|||
|
||||
override fun run(project: Project, context: KobaltContext, configName: String,
|
||||
classpath: List<IClasspathDependency>)
|
||||
= TaskResult(runTests(project, classpath, configName))
|
||||
= TaskResult(runTests(project, context, classpath, configName))
|
||||
|
||||
override fun affinity(project: Project, context: KobaltContext) =
|
||||
if (project.testDependencies.any { it.id.contains(dependencyName)}) IAffinity.DEFAULT_POSITIVE_AFFINITY
|
||||
|
@ -46,7 +46,8 @@ abstract class GenericTestRunner : ITestRunnerContributor {
|
|||
/**
|
||||
* @return true if all the tests passed
|
||||
*/
|
||||
fun runTests(project: Project, classpath: List<IClasspathDependency>, configName: String) : Boolean {
|
||||
fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||
configName: String) : Boolean {
|
||||
val jvm = JavaInfo.create(File(SystemProperties.javaBase))
|
||||
val java = jvm.javaExecutable
|
||||
var result = false
|
||||
|
@ -56,12 +57,30 @@ abstract class GenericTestRunner : ITestRunnerContributor {
|
|||
if (testConfig != null) {
|
||||
val args = args(project, classpath, testConfig)
|
||||
if (args.size > 0) {
|
||||
val allArgs = arrayListOf<String>().apply {
|
||||
add(java!!.absolutePath)
|
||||
|
||||
// Default JVM args
|
||||
val jvmFlags = arrayListOf<String>().apply {
|
||||
addAll(testConfig.jvmArgs)
|
||||
add("-classpath")
|
||||
add(classpath.map { it.jarFile.get().absolutePath }.joinToString(File.pathSeparator))
|
||||
add(mainClass)
|
||||
}
|
||||
|
||||
// JVM args from the contributors
|
||||
val pluginInfo = Kobalt.INJECTOR.getInstance(PluginInfo::class.java)
|
||||
|
||||
val flagsFromContributors = pluginInfo.testJvmFlagContributors.flatMap {
|
||||
it.testJvmFlagsFor(project, context, jvmFlags)
|
||||
}
|
||||
|
||||
if (flagsFromContributors.any()) {
|
||||
log(2, "Adding JVM flags from contributors: " + flagsFromContributors)
|
||||
}
|
||||
|
||||
val allArgs = arrayListOf<String>().apply {
|
||||
add(java!!.absolutePath)
|
||||
addAll(flagsFromContributors)
|
||||
addAll(jvmFlags)
|
||||
addAll(args)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.beust.kobalt.TestConfig
|
|||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.Project
|
||||
|
||||
open public class JUnitRunner() : GenericTestRunner() {
|
||||
open class JUnitRunner() : GenericTestRunner() {
|
||||
|
||||
override val mainClass = "org.junit.runner.JUnitCore"
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
// Not documented yet
|
||||
val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
|
||||
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
|
||||
val testJvmFlagContributors = arrayListOf<ITestJvmFlagContributor>()
|
||||
|
||||
companion object {
|
||||
/**
|
||||
|
@ -164,6 +165,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
if (this is IIncrementalAssemblyContributor) incrementalAssemblyContributors.add(this)
|
||||
|
||||
// Not documented yet
|
||||
if (this is ITestJvmFlagContributor) testJvmFlagContributors.add(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +178,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
compilerContributors, docContributors, sourceDirContributors,
|
||||
testSourceDirContributors, buildConfigFieldContributors,
|
||||
taskContributors, assemblyContributors,
|
||||
incrementalAssemblyContributors
|
||||
incrementalAssemblyContributors, testJvmFlagContributors
|
||||
).forEach {
|
||||
it.forEach {
|
||||
it.cleanUpActors()
|
||||
|
@ -212,6 +214,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
buildConfigContributors.addAll(pluginInfo.buildConfigContributors)
|
||||
assemblyContributors.addAll(pluginInfo.assemblyContributors)
|
||||
incrementalAssemblyContributors.addAll(pluginInfo.incrementalAssemblyContributors)
|
||||
testJvmFlagContributors.addAll(pluginInfo.testJvmFlagContributors)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ package com.beust.kobalt.internal
|
|||
* SpekRunner triggers if it finds a dependency on org.jetbrains.spek but other than that, it just
|
||||
* uses the regular JUnitRunner.
|
||||
*/
|
||||
public class SpekRunner() : JUnitRunner() {
|
||||
class SpekRunner : JUnitRunner() {
|
||||
override val dependencyName = "org.jetbrains.spek"
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.beust.kobalt.misc.KFiles
|
|||
import com.beust.kobalt.misc.warn
|
||||
import java.io.File
|
||||
|
||||
public class TestNgRunner() : GenericTestRunner() {
|
||||
class TestNgRunner : GenericTestRunner() {
|
||||
|
||||
override val mainClass = "org.testng.TestNG"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue