mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Add ITestJvmFlagInterceptor.
This commit is contained in:
parent
dd65e3bbc7
commit
f682983bf9
3 changed files with 30 additions and 7 deletions
|
@ -0,0 +1,14 @@
|
||||||
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plug-ins that add flags to the JVM used to run tests should implement this interface.
|
||||||
|
*/
|
||||||
|
interface ITestJvmFlagInterceptor : IInterceptor {
|
||||||
|
/**
|
||||||
|
* @return the list of all flags that should be used. If you only want to add flags to the current list,
|
||||||
|
* just return the concatenation of @param[currentFlags] and your own list (or use ITestJvmFlagContributor).
|
||||||
|
* If you actually alter the list of flags, make sure you don't remove anything critical from @param[currentFlags].
|
||||||
|
*/
|
||||||
|
fun testJvmFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>) : List<String>
|
||||||
|
}
|
||||||
|
|
|
@ -66,21 +66,28 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
||||||
add(mainClass)
|
add(mainClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
// JVM args from the contributors
|
|
||||||
val pluginInfo = Kobalt.INJECTOR.getInstance(PluginInfo::class.java)
|
val pluginInfo = Kobalt.INJECTOR.getInstance(PluginInfo::class.java)
|
||||||
|
|
||||||
|
// JVM flags from the contributors
|
||||||
val flagsFromContributors = pluginInfo.testJvmFlagContributors.flatMap {
|
val flagsFromContributors = pluginInfo.testJvmFlagContributors.flatMap {
|
||||||
it.testJvmFlagsFor(project, context, jvmFlags)
|
it.testJvmFlagsFor(project, context, jvmFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flagsFromContributors.any()) {
|
// JVM flags from the interceptors (these overwrite flags instead of just adding to the list)
|
||||||
log(2, "Adding JVM flags from contributors: " + flagsFromContributors)
|
var interceptedArgs = ArrayList(flagsFromContributors)
|
||||||
|
pluginInfo.testJvmFlagInterceptors.forEach {
|
||||||
|
val newFlags = it.testJvmFlagsFor(project, context, interceptedArgs)
|
||||||
|
interceptedArgs.clear()
|
||||||
|
interceptedArgs.addAll(newFlags)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interceptedArgs.any()) {
|
||||||
|
log(2, "Final JVM test flags after running the contributors and interceptors: $interceptedArgs")
|
||||||
}
|
}
|
||||||
|
|
||||||
val allArgs = arrayListOf<String>().apply {
|
val allArgs = arrayListOf<String>().apply {
|
||||||
add(java!!.absolutePath)
|
add(java!!.absolutePath)
|
||||||
addAll(flagsFromContributors)
|
addAll(interceptedArgs)
|
||||||
addAll(jvmFlags)
|
|
||||||
addAll(args)
|
addAll(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
||||||
val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
|
val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
|
||||||
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
|
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
|
||||||
val testJvmFlagContributors = arrayListOf<ITestJvmFlagContributor>()
|
val testJvmFlagContributors = arrayListOf<ITestJvmFlagContributor>()
|
||||||
|
val testJvmFlagInterceptors = arrayListOf<ITestJvmFlagInterceptor>()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
|
@ -166,6 +167,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
||||||
|
|
||||||
// Not documented yet
|
// Not documented yet
|
||||||
if (this is ITestJvmFlagContributor) testJvmFlagContributors.add(this)
|
if (this is ITestJvmFlagContributor) testJvmFlagContributors.add(this)
|
||||||
|
if (this is ITestJvmFlagInterceptor) testJvmFlagInterceptors.add(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +180,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
||||||
compilerContributors, docContributors, sourceDirContributors,
|
compilerContributors, docContributors, sourceDirContributors,
|
||||||
testSourceDirContributors, buildConfigFieldContributors,
|
testSourceDirContributors, buildConfigFieldContributors,
|
||||||
taskContributors, assemblyContributors,
|
taskContributors, assemblyContributors,
|
||||||
incrementalAssemblyContributors, testJvmFlagContributors
|
incrementalAssemblyContributors, testJvmFlagInterceptors
|
||||||
).forEach {
|
).forEach {
|
||||||
it.forEach {
|
it.forEach {
|
||||||
it.cleanUpActors()
|
it.cleanUpActors()
|
||||||
|
@ -214,7 +216,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
||||||
buildConfigContributors.addAll(pluginInfo.buildConfigContributors)
|
buildConfigContributors.addAll(pluginInfo.buildConfigContributors)
|
||||||
assemblyContributors.addAll(pluginInfo.assemblyContributors)
|
assemblyContributors.addAll(pluginInfo.assemblyContributors)
|
||||||
incrementalAssemblyContributors.addAll(pluginInfo.incrementalAssemblyContributors)
|
incrementalAssemblyContributors.addAll(pluginInfo.incrementalAssemblyContributors)
|
||||||
testJvmFlagContributors.addAll(pluginInfo.testJvmFlagContributors)
|
testJvmFlagInterceptors.addAll(pluginInfo.testJvmFlagInterceptors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue