keys cleanup part 2

This commit is contained in:
Mark Harrah 2011-02-26 23:56:30 -05:00
parent 5ea24a460b
commit 19698e308e
10 changed files with 47 additions and 42 deletions

View File

@ -3,7 +3,8 @@
*/
package sbt
import Project.{ScopedKey, ThisProject}
import Project.ScopedKey
import Keys.ThisProject
import CommandSupport.logger
import Load.BuildStructure
import complete.{DefaultParsers, Parser}
@ -83,5 +84,5 @@ object Act
def requireSession[T](s: State, p: => Parser[T]): Parser[T] =
if(s get Project.SessionKey isEmpty) failure("No project loaded") else p
if(s get Keys.SessionKey isEmpty) failure("No project loaded") else p
}

View File

@ -7,11 +7,11 @@ package sbt
import java.net.URI
import compile.{Discovered,Discovery,Eval,EvalImports}
import classpath.ClasspathUtilities
import inc.Analysis
import scala.annotation.tailrec
import collection.mutable
import Compile.{Compilers,Inputs}
import Project.{AppConfig, Config, ScopedKey, ScopeLocal, Setting, ThisProject, ThisProjectRef}
import Project.{ScopedKey, ScopeLocal, Setting}
import Keys.{AppConfig, Config, ThisProject, ThisProjectRef}
import TypeFunctions.{Endo,Id}
import tools.nsc.reporters.ConsoleReporter
import Build.{analyzed, data}
@ -32,7 +32,7 @@ object Build
def defaultProject(id: String, base: File): Project = Project(id, base)
def data[T](in: Seq[Attributed[T]]): Seq[T] = in.map(_.data)
def analyzed(in: Seq[Attributed[_]]): Seq[Analysis] = in.flatMap{ _.metadata.get(Command.Analysis) }
def analyzed(in: Seq[Attributed[_]]): Seq[inc.Analysis] = in.flatMap{ _.metadata.get(Keys.Analysis) }
}
object RetrieveUnit
{
@ -497,14 +497,14 @@ object Load
def loadDefinition(loader: ClassLoader, definition: String): Build =
ModuleUtilities.getObject(definition, loader).asInstanceOf[Build]
def build(classpath: Seq[File], sources: Seq[File], target: File, compilers: Compilers, log: Logger): (Inputs, Analysis) =
def build(classpath: Seq[File], sources: Seq[File], target: File, compilers: Compilers, log: Logger): (Inputs, inc.Analysis) =
{
val inputs = Compile.inputs(classpath, sources, target, Nil, Nil, Nil, Compile.DefaultMaxErrors)(compilers, log)
val analysis = Compile(inputs, log)
(inputs, analysis)
}
def loadPlugins(classpath: Seq[File], loader: ClassLoader, analysis: Seq[Analysis]): LoadedPlugins =
def loadPlugins(classpath: Seq[File], loader: ClassLoader, analysis: Seq[inc.Analysis]): LoadedPlugins =
{
val (pluginNames, plugins) = if(classpath.isEmpty) (Nil, Nil) else {
val names = analysis flatMap findPlugins
@ -521,9 +521,9 @@ object Load
def importAll(values: Seq[String]) = if(values.isEmpty) Nil else values.map( _ + "._" ).mkString("import ", ", ", "") :: Nil
def findPlugins(analysis: Analysis): Seq[String] = discover(analysis, "sbt.Plugin")
def findDefinitions(analysis: Analysis): Seq[String] = discover(analysis, "sbt.Build")
def discover(analysis: Analysis, subclasses: String*): Seq[String] =
def findPlugins(analysis: inc.Analysis): Seq[String] = discover(analysis, "sbt.Plugin")
def findDefinitions(analysis: inc.Analysis): Seq[String] = discover(analysis, "sbt.Build")
def discover(analysis: inc.Analysis, subclasses: String*): Seq[String] =
{
val subclassSet = subclasses.toSet
val ds = Discovery(subclassSet, Set.empty)(Test.allDefs(analysis))

View File

@ -28,12 +28,6 @@ object Command
import DefaultParsers._
val Logged = AttributeKey[Logger]("log")
val HistoryPath = SettingKey[Option[File]]("history")
val ShellPrompt = SettingKey[State => String]("shell-prompt")
val Analysis = AttributeKey[inc.Analysis]("analysis")
val Watch = SettingKey[Watched]("continuous-watch")
def command(name: String)(f: State => State): Command = command(name, Nil)(f)
def command(name: String, briefHelp: String, detail: String)(f: State => State): Command = command(name, Help(name, (name, briefHelp), detail) :: Nil)(f)
def command(name: String, help: Seq[Help])(f: State => State): Command = make(name, help : _*)(state => success(() => f(state)))

View File

@ -11,7 +11,7 @@ import Path._
object CommandSupport
{
def logger(s: State) = s get Command.Logged getOrElse ConsoleLogger()
def logger(s: State) = s get Keys.Logged getOrElse ConsoleLogger()
private def canRead = (_: File).canRead
def notReadable(files: Seq[File]): Seq[File] = files filterNot canRead

View File

@ -6,12 +6,10 @@ package sbt
import java.io.File
import Build.data
import Scope.{GlobalScope,ThisScope}
import Project.{AppConfig, Config, Initialize, ScopedKey, Setting, ThisProject, ThisProjectRef}
import Project.{Initialize, ScopedKey, Setting}
import Configurations.{Compile => CompileConf, Test => TestConf}
import Command.{HistoryPath, ShellPrompt}
import EvaluateTask.{resolvedScoped, streams}
import complete._
import inc.Analysis
import std.TaskExtra._
import scala.xml.{Node => XNode,NodeSeq}
import org.apache.ivy.core.module.{descriptor, id}
@ -49,10 +47,10 @@ object Default
def prefix(config: String) = if(config == "compile") "" else config + "-"
def toSeq[T](key: ScopedSetting[T]): Initialize[Seq[T]] = key( _ :: Nil)
def extractAnalysis[T](a: Attributed[T]): (T, Analysis) =
(a.data, a.metadata get Command.Analysis getOrElse Analysis.Empty)
def extractAnalysis[T](a: Attributed[T]): (T, inc.Analysis) =
(a.data, a.metadata get Keys.Analysis getOrElse inc.Analysis.Empty)
def analysisMap[T](cp: Seq[Attributed[T]]): Map[T, Analysis] =
def analysisMap[T](cp: Seq[Attributed[T]]): Map[T, inc.Analysis] =
(cp map extractAnalysis).toMap
def core: Seq[Setting[_]] = Seq(
@ -66,7 +64,7 @@ object Default
Name <<= ThisProject(_.id),
Version :== "0.1",
MaxErrors in GlobalScope :== 100,
Project.Commands :== Nil,
Commands :== Nil,
Data <<= EvaluateTask.state map { state => Project.structure(state).data }
)
def paths = Seq(
@ -251,7 +249,7 @@ object Default
def mainRunTask = RunTask <<= runTask(FullClasspath in Configurations.Runtime, MainClass in RunTask, Runner in RunTask)
def discoverMainClasses(analysis: Analysis): Seq[String] =
def discoverMainClasses(analysis: inc.Analysis): Seq[String] =
compile.Discovery.applications(Test.allDefs(analysis)) collect { case (definition, discovered) if(discovered.hasMain) => definition.name }
def consoleProject = (EvaluateTask.state, streams, InitialCommands in ConsoleProject) map { (state, s, extra) => Console.sbt(state, extra)(s.log) }
@ -346,7 +344,7 @@ object Classpaths
def concat[T](a: ScopedTaskable[Seq[T]], b: ScopedTaskable[Seq[T]]): Initialize[Task[Seq[T]]] = (a,b) map (_ ++ _)
lazy val configSettings: Seq[Project.Setting[_]] = Seq(
lazy val configSettings: Seq[Setting[_]] = Seq(
ExternalDependencyClasspath <<= concat(UnmanagedClasspath, ManagedClasspath),
DependencyClasspath <<= concat(InternalDependencyClasspath, ExternalDependencyClasspath),
FullClasspath <<= concat(Products, DependencyClasspath),
@ -361,7 +359,7 @@ object Classpaths
def defaultPackageTasks: Seq[ScopedTask[_]] =
for(task <- Seq(Package, PackageSrc, PackageDoc); conf <- Seq(CompileConf, TestConf)) yield (task in conf)
val publishSettings: Seq[Project.Setting[_]] = Seq(
val publishSettings: Seq[Setting[_]] = Seq(
PublishMavenStyle in GlobalScope :== true,
PackageToPublish <<= defaultPackageTasks.dependOn,
DeliverDepends <<= (PublishMavenStyle, MakePom.setting, PackageToPublish.setting) { (mavenStyle, makePom, ptp) =>
@ -373,7 +371,7 @@ object Classpaths
Publish <<= publish(PublishConfig, Deliver),
PublishLocal <<= publish(PublishLocalConfig, DeliverLocal)
)
val baseSettings: Seq[Project.Setting[_]] = Seq(
val baseSettings: Seq[Setting[_]] = Seq(
UnmanagedBase <<= Base / "lib",
NormalizedName <<= Name(StringUtilities.normalize),
Organization :== NormalizedName,
@ -502,7 +500,7 @@ object Classpaths
new RawRepository(new ProjectResolver("inter-project", m))
}
def analyzed[T](data: T, analysis: Analysis) = Attributed.blank(data).put(Command.Analysis, analysis)
def analyzed[T](data: T, analysis: inc.Analysis) = Attributed.blank(data).put(Keys.Analysis, analysis)
def makeProducts: Initialize[Task[Classpath]] =
(CompileTask, CompileInputs, CopyResources) map { (analysis, i, _) => analyzed(i.config.classesDirectory, analysis) :: Nil }

View File

@ -15,6 +15,23 @@ package sbt
object Keys
{
// Project keys
val ProjectCommand = AttributeKey[Boolean]("project-command")
val SessionKey = AttributeKey[SessionSettings]("session-settings")
val StructureKey = AttributeKey[Load.BuildStructure]("build-structure")
val AppConfig = SettingKey[xsbti.AppConfiguration]("app-configuration")
val ThisProject = SettingKey[Project]("project")
val ThisProjectRef = SettingKey[ProjectRef]("project-ref")
val Config = SettingKey[Configuration]("configuration")
val Commands = SettingKey[Seq[Command]]("commands")
// Command keys
val Logged = AttributeKey[Logger]("log")
val HistoryPath = SettingKey[Option[File]]("history")
val ShellPrompt = SettingKey[State => String]("shell-prompt")
val Analysis = AttributeKey[inc.Analysis]("analysis")
val Watch = SettingKey[Watched]("continuous-watch")
// Path Keys
val Base = SettingKey[File]("base-directory")
val Target = SettingKey[File]("target")

View File

@ -10,7 +10,8 @@ package sbt
import compile.EvalImports
import sbt.complete.{DefaultParsers, Parser}
import Command.{applyEffect,Analysis,HistoryPath,Logged,ShellPrompt,Watch}
import Command.applyEffect
import Keys.{Analysis,HistoryPath,Logged,ShellPrompt,Watch}
import scala.annotation.tailrec
import scala.collection.JavaConversions._
import Function.tupled

View File

@ -7,7 +7,7 @@ package sbt
import java.net.URI
import Project._
import Types.Endo
import Command.{HistoryPath,ShellPrompt,Watch}
import Keys.{AppConfig, Commands, Config, HistoryPath, ProjectCommand, SessionKey, ShellPrompt, StructureKey, ThisProject, ThisProjectRef, Watch}
import CommandSupport.logger
import compile.Eval
@ -153,15 +153,6 @@ object Project extends Init[Scope]
}
def reverseDependencies(cMap: CompiledMap, scoped: ScopedKey[_]): Iterable[ScopedKey[_]] =
for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key
val ProjectCommand = AttributeKey[Boolean]("project-command")
val SessionKey = AttributeKey[SessionSettings]("session-settings")
val StructureKey = AttributeKey[Load.BuildStructure]("build-structure")
val AppConfig = SettingKey[xsbti.AppConfiguration]("app-configuration")
val ThisProject = SettingKey[Project]("project")
val ThisProjectRef = SettingKey[ProjectRef]("project-ref")
val Config = SettingKey[Configuration]("configuration")
val Commands = SettingKey[Seq[Command]]("commands")
}
import SessionSettings._

View File

@ -4,7 +4,8 @@
package sbt
import ProjectNavigation._
import Project.{SessionKey, updateCurrent}
import Project.updateCurrent
import Keys.SessionKey
import CommandSupport.logger
import complete.{DefaultParsers, Parser}
import DefaultParsers._
@ -19,7 +20,7 @@ object ProjectNavigation
final class ChangeProject(val id: String) extends Navigate
def command(s: State): Parser[() => State] =
if(s get Project.SessionKey isEmpty) failure("No project loaded") else (new ProjectNavigation(s)).command
if(s get SessionKey isEmpty) failure("No project loaded") else (new ProjectNavigation(s)).command
}
final class ProjectNavigation(s: State)
{

View File

@ -3,6 +3,8 @@
*/
package object sbt extends sbt.std.TaskExtra with sbt.Types with sbt.ProcessExtra with sbt.impl.DependencyBuilders with sbt.PathExtra with sbt.ProjectConstructors
{
type Setting[T] = Project.Setting[T]
type ScopedKey[T] = Project.ScopedKey[T]
type File = java.io.File
type URI = java.net.URI
implicit def maybeToOption[S](m: xsbti.Maybe[S]): Option[S] =