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
|
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
|
object Cache extends BasicCacheImplicits with SBinaryFormats with HListCacheImplicits
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,17 @@ package xsbt
|
||||||
|
|
||||||
object TaskRunner
|
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`.
|
/** Executes work for nodes in a directed acyclic graph with root node `node`.
|
||||||
* The maximum number of tasks to execute simultaneously is `maximumTasks`. */
|
* 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)
|
require(maximumTasks > 0)
|
||||||
val compute = new Compute[Work.Job, Result] { def apply[A](w: Work.Job[A]) = w.apply }
|
val compute = new Compute[Work.Job, Result] { def apply[A](w: Work.Job[A]) = w.apply }
|
||||||
val strategy = new SimpleStrategy[Work[_,_]]
|
val strategy = new SimpleStrategy[Work[_,_]]
|
||||||
val scheduler = new TaskScheduler(node, strategy, new BasicTaskListener)
|
val scheduler = new TaskScheduler(node, strategy, new BasicTaskListener)
|
||||||
val distributor = new Distributor[ Either[ List[WorkFailure[Task[_]]], T ] , Work.Job, Result](scheduler, compute, maximumTasks)
|
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)
|
} named("it_" + i)
|
||||||
it
|
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) =
|
final def checkRootComplete(intermediate: Int, workers: Int) =
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ object TaskRunnerCallTest extends Properties("TaskRunner Call")
|
||||||
("Workers: " + workers) |: ("i: " + i) |: ("fib(i): " + f) |:
|
("Workers: " + workers) |: ("i: " + i) |: ("fib(i): " + f) |:
|
||||||
{
|
{
|
||||||
def result = TaskRunner( fibTask(i), workers)
|
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) |:
|
("Workers: " + workers) |: ("Array: " + a.toList) |:
|
||||||
{
|
{
|
||||||
def result = TaskRunner( sort(a.toArray), workers)
|
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
|
object checkResult
|
||||||
{
|
{
|
||||||
def apply[T](run: => Either[List[WorkFailure[Task[_]]],T], expected: T) =
|
def apply[T](run: => T, expected: T) =
|
||||||
{
|
{
|
||||||
("Expected: " + expected) |:
|
("Expected: " + expected) |:
|
||||||
(try
|
(try
|
||||||
{
|
{
|
||||||
val actual = run
|
val actual = run
|
||||||
("Actual: " + actual) |:
|
("Actual: " + actual) |: (actual == expected)
|
||||||
(actual match
|
|
||||||
{
|
|
||||||
case Right(a) => a == expected
|
|
||||||
case Left(failures) =>
|
|
||||||
failures.foreach(f => f.exception.printStackTrace)
|
|
||||||
false
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
case TasksFailed(failures) =>
|
||||||
|
failures.foreach(f => f.exception.printStackTrace)
|
||||||
|
"One or more tasks failed" |: false
|
||||||
case e =>
|
case e =>
|
||||||
e.printStackTrace
|
e.printStackTrace
|
||||||
"Error in framework" |: false
|
"Error in framework" |: false
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue