我想创建一个新的自定义InputTask
(testOnlyCustom
)
testOnly
用与给testOnlyCustom
和相同的参数调用condition
另一个任务(我们称之为pre
)。在这里,我必须强制执行“顺序”执行。因此:
If condition is true
testOnlyCustom com.dummy.TestSuite calls
pre and then
testOnly com.dummy.TestSuite
If condition is false
testOnlyCustom com.dummy.TestSuite calls
testOnly com.dummy.TestSuite
虽然我能够实现溶液与testCustom
参照pre
和test
(因而具有无参数),我不能够解决该问题testOnlyCustom
,作为InputTask
使用的
这是我的代码:
import sbt._
import sbt.Keys._
import sbt.Def._
import sbtsequential.Plugin._
object Simple extends sbt.Plugin {
import SimpleKeys._
object SimpleKeys {
lazy val condition = SettingKey[Boolean]("mode", "The mode.")
lazy val pre = TaskKey[Unit]("test-with-pre", "Do some pre step.")
lazy val testWithPre = TaskKey[Unit]("test-with-pre", "Run pre task beforehand")
lazy val testCustom = TaskKey[Unit]("test-custom", "Run pre (depending on condition) and then test.")
lazy val testOnlyWithPre = InputKey[Unit]("test-only-with-pre", "Run selected tests (like test-only in SBT) with pre executed before.")
lazy val testOnlyCustom = InputKey[Unit]("test-only-configured", "Run pre (depending on condition) and then call test-only.")
}
lazy val baseSettings: Seq[sbt.Def.Setting[_]] = Seq(
// this is working
testWithPre := test.value,
testWithPre <<= testWithPre.dependsOn( pre ),
testCustom := Def.taskDyn {
val c = condition.value
if (c) {
testWithPre
} else {
test
}
}.value,
//
// this is the part, where my question focuses on
//
testOnlyWithPre := testOnly.evaluated,
testOnlyWithPre <<= testOnlyWithPre.dependsOn( pre ),
// is this the correct approach?
testOnlyCustom := Def.inputTaskDyn {
// ???????????????????????????????
Def.task()
}.evaluated
)
lazy val testSimpleSettings: Seq[sbt.Def.Setting[_]] = baseSettings
}
inputTaskDyn
路要走吗?到底是什么?我刚刚选择了它,因为它似乎是的动态版本InputTasks
。不幸的是,上的文档很少inputTaskDyn
。dependsOn
像我一样通过强制“顺序”执行?我已经看到SBT 0.13.8包含了Def.sequantial
。但这似乎不适用于InputTasks吗?InputTask
为A Task
(与taskDyn / inputTaskDyn一起使用),但仍然坚持evaluated
使用显式解析器?还是有一种重用testOnly
解析器的方法?.evaluated
及.parsed
的InputTask
。到底是做InputTask.parse
什么的?如果有人可以提供可行的解决方案,那就太好了!
提前谢谢了
马丁
首先,OlegYch_在Freenode#sbt上指出,随着SBT 0.13.9的Inputtask
出现,可以通过以下命令执行s
def runInputTask[T](key: InputKey[T], input: String, state: State): (State, T)
在sbt.Extracted.scala
。
其次,testOnly解析器可以通过进行重用sbt.Defaults#inputTests
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句