convenience methods for working in console-project

This commit is contained in:
Mark Harrah 2011-04-20 23:33:53 -04:00
parent 815ed50dcf
commit 8f639ffc4d
2 changed files with 19 additions and 2 deletions

View File

@ -63,6 +63,23 @@ final case class Extracted(structure: BuildStructure, session: SessionSettings,
{
lazy val currentUnit = structure units currentRef.build
lazy val currentProject = currentUnit defined currentRef.project
def get[T](key: ScopedTask[T]): Task[T] = get(key.task)
def get[T](key: ScopedSetting[T]): T =
{
val scope = if(key.scope.project == This) key.scope.copy(project = Select(currentRef)) else key.scope
getOrError(scope, key.key)
}
def runTask[T](key: ScopedTask[T], state: State): T =
{
import EvaluateTask._
val value: Option[Result[T]] = evaluateTask(structure, key.task.scoped, state, currentRef)
val result = getOrError(key.scope, key.key, value)
processResult(result, ConsoleLogger())
}
private def getOrError[T](scope: Scope, key: AttributeKey[_], value: Option[T]): T =
value getOrElse error(Project.display(ScopedKey(scope, key)) + " is undefined.")
private def getOrError[T](scope: Scope, key: AttributeKey[T]): T =
structure.data.get(scope, key) getOrElse error(Project.display(ScopedKey(scope, key)) + " is undefined.")
}
sealed trait ClasspathDep[PR <: ProjectReference] { def project: PR; def configuration: Option[String] }

View File

@ -137,7 +137,7 @@ object Scoped
{
def scope: Scope
def key: AttributeKey[S]
protected final val scoped = ScopedKey(scope, key)
final val scoped = ScopedKey(scope, key)
final def :==(value: S): Setting[S] = :=(value)
final def := (value: => S): Setting[S] = setting(scoped, Project.value(value))
@ -170,7 +170,7 @@ object Scoped
def get(settings: Settings[Scope]): Option[Task[S]] = settings.get(scope, key)
type App[T] = Initialize[Task[T]]
private[this] def scoped = ScopedKey(scope, key)
def scoped = ScopedKey(scope, key)
private[this] def mk[T](onTask: Task[S] => Task[T]): App[T] = Apply.single(scoped)(onTask)
def flatMapR[T](f: Result[S] => Task[T]): App[T] = mk(_ flatMapR f)