2010-08-14 15:55:49 +02:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2010 Mark Harrah
|
|
|
|
|
*/
|
|
|
|
|
package sbt
|
|
|
|
|
|
2010-08-28 01:17:03 +02:00
|
|
|
import Types._
|
|
|
|
|
import Task._
|
2010-08-14 15:55:49 +02:00
|
|
|
|
2010-08-28 01:17:03 +02:00
|
|
|
// Action, Task, and Info are intentionally invariant in their type parameter.
|
2010-08-14 15:55:49 +02:00
|
|
|
// Various natural transformations used, such as PMap, require invariant type constructors for correctness
|
|
|
|
|
|
|
|
|
|
sealed trait Action[T]
|
2010-08-22 04:55:42 +02:00
|
|
|
final case class Pure[T](f: () => T) extends Action[T]
|
2010-08-14 15:55:49 +02:00
|
|
|
final case class Mapped[T, In <: HList](in: Tasks[In], f: Results[In] => T) extends Action[T]
|
|
|
|
|
final case class FlatMapped[T, In <: HList](in: Tasks[In], f: Results[In] => Task[T]) extends Action[T]
|
|
|
|
|
final case class DependsOn[T](in: Task[T], deps: Seq[Task[_]]) extends Action[T]
|
2010-08-22 04:55:42 +02:00
|
|
|
final case class Join[T, U](in: Seq[Task[U]], f: Seq[Result[U]] => Either[Task[T], T]) extends Action[T]
|
2010-08-14 15:55:49 +02:00
|
|
|
|
|
|
|
|
object Task
|
|
|
|
|
{
|
|
|
|
|
type Tasks[HL <: HList] = KList[Task, HL]
|
|
|
|
|
type Results[HL <: HList] = KList[Result, HL]
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-22 04:54:46 +02:00
|
|
|
final case class Task[T](info: Info[T], work: Action[T])
|
2010-08-14 15:55:49 +02:00
|
|
|
{
|
2011-09-22 04:54:46 +02:00
|
|
|
override def toString = info.name getOrElse ("Task(" + info + ")")
|
2011-08-06 03:56:32 +02:00
|
|
|
override def hashCode = info.hashCode
|
2010-08-14 15:55:49 +02:00
|
|
|
}
|
2011-09-22 04:54:46 +02:00
|
|
|
final case class Info[T](attributes: AttributeMap = AttributeMap.empty, post: T => AttributeMap = const(AttributeMap.empty))
|
2010-08-14 15:55:49 +02:00
|
|
|
{
|
2010-08-22 04:55:42 +02:00
|
|
|
import Info._
|
|
|
|
|
def name = attributes.get(Name)
|
|
|
|
|
def description = attributes.get(Description)
|
|
|
|
|
def setName(n: String) = set(Name, n)
|
|
|
|
|
def setDescription(d: String) = set(Description, d)
|
|
|
|
|
def set[T](key: AttributeKey[T], value: T) = copy(attributes = this.attributes.put(key, value))
|
2011-09-22 04:54:46 +02:00
|
|
|
def postTransform[A](f: (T, AttributeMap) => AttributeMap) = copy(post = (t: T) => f(t, post(t)) )
|
2010-09-13 04:41:02 +02:00
|
|
|
|
2011-09-22 04:54:46 +02:00
|
|
|
override def toString = if(attributes.isEmpty) "_" else attributes.toString
|
2010-08-14 15:55:49 +02:00
|
|
|
}
|
2010-08-22 04:55:42 +02:00
|
|
|
object Info
|
|
|
|
|
{
|
2010-08-28 01:17:03 +02:00
|
|
|
val Name = AttributeKey[String]("name")
|
|
|
|
|
val Description = AttributeKey[String]("description")
|
2010-08-22 04:55:42 +02:00
|
|
|
}
|