diff --git a/main/Project.scala b/main/Project.scala index 4f11b1ca8..11123660a 100644 --- a/main/Project.scala +++ b/main/Project.scala @@ -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] } diff --git a/main/Structure.scala b/main/Structure.scala index fa13e95c8..fa60acc57 100644 --- a/main/Structure.scala +++ b/main/Structure.scala @@ -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)