provide more convenient access to BuildStructure and all projects

This commit is contained in:
Mark Harrah 2011-04-08 22:03:41 -04:00
parent 14c6ee4b2a
commit 50e453c70c
4 changed files with 14 additions and 5 deletions

View File

@ -80,7 +80,8 @@ object Defaults
showSuccess :== true,
commands :== Nil,
retrieveManaged :== false,
settings <<= state map { state => Project.structure(state).data }
buildStructure <<= state map Project.structure,
settings <<= buildStructure map ( _.data )
))
def projectCore: Seq[Setting[_]] = Seq(
name <<= thisProject(_.id),

View File

@ -27,7 +27,8 @@ object Keys
// Project keys
val projectCommand = AttributeKey[Boolean]("project-command")
val sessionSettings = AttributeKey[SessionSettings]("session-settings")
val buildStructure = AttributeKey[Load.BuildStructure]("build-structure")
val stateBuildStructure = AttributeKey[Load.BuildStructure]("build-structure")
val buildStructure = TaskKey[Load.BuildStructure]("build-structure")
val appConfiguration = SettingKey[xsbti.AppConfiguration]("app-configuration")
val thisProject = SettingKey[ResolvedProject]("this-project")
val thisProjectRef = SettingKey[ProjectRef]("this-project-ref")

View File

@ -432,6 +432,13 @@ object Load
def referenced[PR <: ProjectReference](definitions: Seq[ProjectDefinition[PR]]): Seq[PR] = definitions flatMap { _.referenced }
final class BuildStructure(val units: Map[URI, LoadedBuildUnit], val root: URI, val settings: Seq[Setting[_]], val data: Settings[Scope], val index: StructureIndex, val streams: Streams, val delegates: Scope => Seq[Scope], val scopeLocal: ScopeLocal)
{
def allProjects: Seq[ResolvedProject] = units.values.flatMap(_.defined.values).toSeq
def allProjects(build: URI): Seq[ResolvedProject] = units(build).defined.values.toSeq
def allProjectRefs: Seq[ProjectRef] = units.toSeq flatMap { case (build, unit) => refs(build, unit.defined.values.toSeq) }
def allProjectRefs(build: URI): Seq[ProjectRef] = refs(build, allProjects(build))
private[this] def refs(build: URI, projects: Seq[ResolvedProject]): Seq[ProjectRef] = projects.map { p => ProjectRef(build, p.id) }
}
final case class LoadBuildConfiguration(stagingDirectory: File, commonPluginClasspath: Seq[Attributed[File]], classpath: Seq[File], loader: ClassLoader, compilers: Compilers, evalPluginDef: (BuildStructure, State) => Seq[Attributed[File]], delegates: LoadedBuild => Scope => Seq[Scope], scopeLocal: ScopeLocal, injectSettings: Seq[Setting[_]], log: Logger)
// information that is not original, but can be reconstructed from the rest of BuildStructure
final class StructureIndex(val keyMap: Map[String, AttributeKey[_]], val taskToKey: Map[Task[_], ScopedKey[Task[_]]], val keyIndex: KeyIndex)

View File

@ -6,7 +6,7 @@ package sbt
import java.io.File
import java.net.URI
import Project._
import Keys.{appConfiguration, buildStructure, commands, configuration, historyPath, logged, projectCommand, sessionSettings, shellPrompt, streams, thisProject, thisProjectRef, watch}
import Keys.{appConfiguration, stateBuildStructure, commands, configuration, historyPath, logged, projectCommand, sessionSettings, shellPrompt, streams, thisProject, thisProjectRef, watch}
import Scope.{GlobalScope,ThisScope}
import CommandSupport.logger
@ -92,7 +92,7 @@ object Project extends Init[Scope]
}
def getOrError[T](state: State, key: AttributeKey[T], msg: String): T = state get key getOrElse error(msg)
def structure(state: State): Load.BuildStructure = getOrError(state, buildStructure, "No build loaded.")
def structure(state: State): Load.BuildStructure = getOrError(state, stateBuildStructure, "No build loaded.")
def session(state: State): SessionSettings = getOrError(state, sessionSettings, "Session not initialized.")
def extract(state: State): Extracted =
@ -109,7 +109,7 @@ object Project extends Init[Scope]
def setProject(session: SessionSettings, structure: Load.BuildStructure, s: State): State =
{
val newAttrs = s.attributes.put(buildStructure, structure).put(sessionSettings, session)
val newAttrs = s.attributes.put(stateBuildStructure, structure).put(sessionSettings, session)
val newState = s.copy(attributes = newAttrs)
updateCurrent(newState.runExitHooks())
}