mirror of https://github.com/sbt/sbt.git
Change TaskRunner to throw an exception instead of using Either
This commit is contained in:
parent
65fc0e0453
commit
56b047035a
|
|
@ -9,7 +9,7 @@ trait Cache[I,O]
|
|||
}
|
||||
trait SBinaryFormats extends CollectionTypes with JavaFormats with NotNull
|
||||
{
|
||||
//TODO: add basic types minus FileFormat
|
||||
//TODO: add basic types from SBinary minus FileFormat
|
||||
}
|
||||
object Cache extends BasicCacheImplicits with SBinaryFormats with HListCacheImplicits
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,16 +2,17 @@ package xsbt
|
|||
|
||||
object TaskRunner
|
||||
{
|
||||
def apply[T](node: Task[T]): Either[ List[WorkFailure[Task[_]]] , T ] = apply(node, Runtime.getRuntime.availableProcessors)
|
||||
def apply[T](node: Task[T]): T = apply(node, Runtime.getRuntime.availableProcessors)
|
||||
/** Executes work for nodes in a directed acyclic graph with root node `node`.
|
||||
* The maximum number of tasks to execute simultaneously is `maximumTasks`. */
|
||||
def apply[T](node: Task[T], maximumTasks: Int): Either[ List[WorkFailure[Task[_]]] , T ] =
|
||||
def apply[T](node: Task[T], maximumTasks: Int): T =
|
||||
{
|
||||
require(maximumTasks > 0)
|
||||
val compute = new Compute[Work.Job, Result] { def apply[A](w: Work.Job[A]) = w.apply }
|
||||
val strategy = new SimpleStrategy[Work[_,_]]
|
||||
val scheduler = new TaskScheduler(node, strategy, new BasicTaskListener)
|
||||
val distributor = new Distributor[ Either[ List[WorkFailure[Task[_]]], T ] , Work.Job, Result](scheduler, compute, maximumTasks)
|
||||
distributor.run()
|
||||
distributor.run().fold(failures => throw new TasksFailed(failures), identity[T])
|
||||
}
|
||||
}
|
||||
}
|
||||
final case class TasksFailed(failures: List[WorkFailure[Task[_]]]) extends RuntimeException(failures.length + " failed")
|
||||
|
|
@ -41,7 +41,8 @@ object TaskRunnerCircularTest extends Properties("TaskRunner Circular")
|
|||
} named("it_" + i)
|
||||
it
|
||||
}
|
||||
TaskRunner(top, workers).fold(_.exists(_.exception.isInstanceOf[CircularDependency]), x => false)
|
||||
try { TaskRunner(top, workers); false }
|
||||
catch { case TasksFailed(failures) => failures.exists(_.exception.isInstanceOf[CircularDependency]) }
|
||||
}
|
||||
final def checkRootComplete(intermediate: Int, workers: Int) =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ object TaskRunnerCallTest extends Properties("TaskRunner Call")
|
|||
("Workers: " + workers) |: ("i: " + i) |: ("fib(i): " + f) |:
|
||||
{
|
||||
def result = TaskRunner( fibTask(i), workers)
|
||||
("Result: " + result) |: (result == Right(f))
|
||||
checkResult(result, f)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ object TaskRunnerSortTest extends Properties("TaskRunnerSort")
|
|||
("Workers: " + workers) |: ("Array: " + a.toList) |:
|
||||
{
|
||||
def result = TaskRunner( sort(a.toArray), workers)
|
||||
checkResult(result.right.map(_.toList), sorted.toList)
|
||||
checkResult(result.toList, sorted.toList)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,23 +4,19 @@ import org.scalacheck.Prop._
|
|||
|
||||
object checkResult
|
||||
{
|
||||
def apply[T](run: => Either[List[WorkFailure[Task[_]]],T], expected: T) =
|
||||
def apply[T](run: => T, expected: T) =
|
||||
{
|
||||
("Expected: " + expected) |:
|
||||
(try
|
||||
{
|
||||
val actual = run
|
||||
("Actual: " + actual) |:
|
||||
(actual match
|
||||
{
|
||||
case Right(a) => a == expected
|
||||
case Left(failures) =>
|
||||
failures.foreach(f => f.exception.printStackTrace)
|
||||
false
|
||||
})
|
||||
("Actual: " + actual) |: (actual == expected)
|
||||
}
|
||||
catch
|
||||
{
|
||||
case TasksFailed(failures) =>
|
||||
failures.foreach(f => f.exception.printStackTrace)
|
||||
"One or more tasks failed" |: false
|
||||
case e =>
|
||||
e.printStackTrace
|
||||
"Error in framework" |: false
|
||||
|
|
|
|||
Loading…
Reference in New Issue