mirror of https://github.com/sbt/sbt.git
convenience methods for working in console-project
This commit is contained in:
parent
815ed50dcf
commit
8f639ffc4d
|
|
@ -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] }
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue