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

Add ITestJvmFlagInterceptor.

This commit is contained in:
Cedric Beust 2016-05-04 23:26:01 -08:00
parent dd65e3bbc7
commit f682983bf9
3 changed files with 30 additions and 7 deletions

View file

@ -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>
}

View file

@ -66,21 +66,28 @@ abstract class GenericTestRunner: ITestRunnerContributor {
add(mainClass)
}
// JVM args from the contributors
val pluginInfo = Kobalt.INJECTOR.getInstance(PluginInfo::class.java)
// JVM flags from the contributors
val flagsFromContributors = pluginInfo.testJvmFlagContributors.flatMap {
it.testJvmFlagsFor(project, context, jvmFlags)
}
if (flagsFromContributors.any()) {
log(2, "Adding JVM flags from contributors: " + flagsFromContributors)
// JVM flags from the interceptors (these overwrite flags instead of just adding to the list)
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 {
add(java!!.absolutePath)
addAll(flagsFromContributors)
addAll(jvmFlags)
addAll(interceptedArgs)
addAll(args)
}

View file

@ -80,6 +80,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
val testJvmFlagContributors = arrayListOf<ITestJvmFlagContributor>()
val testJvmFlagInterceptors = arrayListOf<ITestJvmFlagInterceptor>()
companion object {
/**
@ -166,6 +167,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
// Not documented yet
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,
testSourceDirContributors, buildConfigFieldContributors,
taskContributors, assemblyContributors,
incrementalAssemblyContributors, testJvmFlagContributors
incrementalAssemblyContributors, testJvmFlagInterceptors
).forEach {
it.forEach {
it.cleanUpActors()
@ -214,7 +216,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)
testJvmFlagInterceptors.addAll(pluginInfo.testJvmFlagInterceptors)
}
}