mirror of https://github.com/sbt/sbt.git
Merge pull request #3891 from allanrenucci/scripted
Enable parallel execution of scripted in the plugin
This commit is contained in:
commit
8cfec5b3bf
|
|
@ -26,6 +26,11 @@ object ScriptedPlugin extends AutoPlugin {
|
|||
val scriptedBufferLog = SettingKey[Boolean]("scripted-buffer-log")
|
||||
val scriptedClasspath = TaskKey[PathFinder]("scripted-classpath")
|
||||
val scriptedTests = TaskKey[AnyRef]("scripted-tests")
|
||||
val scriptedBatchExecution =
|
||||
settingKey[Boolean]("Enables or disables batch execution for scripted.")
|
||||
val scriptedParallelInstances =
|
||||
settingKey[Int](
|
||||
"Configures the number of scripted instances for parallel testing, only used in batch mode.")
|
||||
val scriptedRun = TaskKey[Method]("scripted-run")
|
||||
val scriptedLaunchOpts = SettingKey[Seq[String]](
|
||||
"scripted-launch-opts",
|
||||
|
|
@ -56,6 +61,8 @@ object ScriptedPlugin extends AutoPlugin {
|
|||
scriptedBufferLog := true,
|
||||
scriptedClasspath := getJars(ScriptedConf).value,
|
||||
scriptedTests := scriptedTestsTask.value,
|
||||
scriptedParallelInstances := 1,
|
||||
scriptedBatchExecution := false,
|
||||
scriptedRun := scriptedRunTask.value,
|
||||
scriptedDependencies := {
|
||||
def use[A](@deprecated("unused", "") x: A*): Unit = () // avoid unused warnings
|
||||
|
|
@ -73,15 +80,22 @@ object ScriptedPlugin extends AutoPlugin {
|
|||
ModuleUtilities.getObject("sbt.test.ScriptedTests", loader)
|
||||
}
|
||||
|
||||
def scriptedRunTask: Initialize[Task[Method]] = Def.task(
|
||||
scriptedTests.value.getClass.getMethod("run",
|
||||
classOf[File],
|
||||
classOf[Boolean],
|
||||
classOf[Array[String]],
|
||||
classOf[File],
|
||||
classOf[Array[String]],
|
||||
classOf[java.util.List[File]])
|
||||
)
|
||||
def scriptedRunTask: Initialize[Task[Method]] = Def.taskDyn {
|
||||
val fCls = classOf[File]
|
||||
val bCls = classOf[Boolean]
|
||||
val asCls = classOf[Array[String]]
|
||||
val lfCls = classOf[java.util.List[File]]
|
||||
val iCls = classOf[Int]
|
||||
|
||||
val clazz = scriptedTests.value.getClass
|
||||
val method =
|
||||
if (scriptedBatchExecution.value)
|
||||
clazz.getMethod("runInParallel", fCls, bCls, asCls, fCls, asCls, lfCls, iCls)
|
||||
else
|
||||
clazz.getMethod("run", fCls, bCls, asCls, fCls, asCls, lfCls)
|
||||
|
||||
Def.task(method)
|
||||
}
|
||||
|
||||
import DefaultParsers._
|
||||
case class ScriptedTestPage(page: Int, total: Int)
|
||||
|
|
@ -134,15 +148,18 @@ object ScriptedPlugin extends AutoPlugin {
|
|||
val args = scriptedParser(sbtTestDirectory.value).parsed
|
||||
scriptedDependencies.value
|
||||
try {
|
||||
scriptedRun.value.invoke(
|
||||
scriptedTests.value,
|
||||
sbtTestDirectory.value,
|
||||
scriptedBufferLog.value: java.lang.Boolean,
|
||||
args.toArray,
|
||||
sbtLauncher.value,
|
||||
scriptedLaunchOpts.value.toArray,
|
||||
new java.util.ArrayList()
|
||||
)
|
||||
val method = scriptedRun.value
|
||||
val scriptedInstance = scriptedTests.value
|
||||
val dir = sbtTestDirectory.value
|
||||
val log: java.lang.Boolean = scriptedBufferLog.value
|
||||
val launcher = sbtLauncher.value
|
||||
val opts = scriptedLaunchOpts.value.toArray
|
||||
val empty = new java.util.ArrayList[File]()
|
||||
val instances: java.lang.Integer = scriptedParallelInstances.value
|
||||
|
||||
if (scriptedBatchExecution.value)
|
||||
method.invoke(scriptedInstance, dir, log, args.toArray, launcher, opts, empty, instances)
|
||||
else method.invoke(scriptedInstance, dir, log, args.toArray, launcher, opts, empty)
|
||||
} catch { case e: java.lang.reflect.InvocationTargetException => throw e.getCause }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -324,8 +324,8 @@ class ScriptedRunner {
|
|||
prescripted.add(f); ()
|
||||
}) //new FullLogger(Logger.xlog2Log(log)))
|
||||
}
|
||||
// This is called by sbt-scripted 0.13.x (the sbt host) when cross-compiling to sbt 0.13.x and 1.0.x
|
||||
// See https://github.com/sbt/sbt/issues/3245
|
||||
|
||||
// This is called by sbt-scripted 0.13.x and 1.x (see https://github.com/sbt/sbt/issues/3245)
|
||||
def run(resourceBaseDirectory: File,
|
||||
bufferLog: Boolean,
|
||||
tests: Array[String],
|
||||
|
|
@ -374,6 +374,21 @@ class ScriptedRunner {
|
|||
1)
|
||||
}
|
||||
|
||||
// This is used by sbt-scripted sbt 1.x
|
||||
def runInParallel(
|
||||
baseDir: File,
|
||||
bufferLog: Boolean,
|
||||
tests: Array[String],
|
||||
bootProps: File,
|
||||
launchOpts: Array[String],
|
||||
prescripted: java.util.List[File],
|
||||
instances: Int
|
||||
): Unit = {
|
||||
val logger = ConsoleLogger()
|
||||
val addTestFile = (f: File) => { prescripted.add(f); () }
|
||||
runInParallel(baseDir, bufferLog, tests, logger, bootProps, launchOpts, addTestFile, instances)
|
||||
}
|
||||
|
||||
def runInParallel(
|
||||
resourceBaseDirectory: File,
|
||||
bufferLog: Boolean,
|
||||
|
|
|
|||
Loading…
Reference in New Issue