Permalink
Browse files

split command core to main/command/

  • Loading branch information...
1 parent bf472b8 commit 98c98f9c2689cd2ee6bf7e9b8e116eb83cccf73b @harrah committed Jan 29, 2012
View
@@ -11,7 +11,7 @@ package sbt
import DefaultParsers._
import Types.idFun
import java.net.URI
- import CommandSupport.ShowCommand
+ import CommandStrings.ShowCommand
final class ParsedKey(val key: ScopedKey[_], val mask: ScopeMask)
object Act
@@ -3,46 +3,30 @@
*/
package sbt
-import complete.HistoryCommands
-import scala.annotation.tailrec
-
-import java.io.File
-import Path._
-
-object CommandSupport
+object CommandStrings
{
- def logger(s: State) = globalLogging(s).full
- def globalLogging(s: State) = s get Keys.globalLogging getOrElse error("Global logging misconfigured")
-
- // slightly better fallback in case of older launcher
- def bootDirectory(state: State): File =
- try { state.configuration.provider.scalaProvider.launcher.bootDirectory }
- catch { case e: NoSuchMethodError => new File(".").getAbsoluteFile }
-
- private def canRead = (_: File).canRead
- def notReadable(files: Seq[File]): Seq[File] = files filterNot canRead
- def readable(files: Seq[File]): Seq[File] = files filter canRead
- def sbtRCs(s: State): Seq[File] =
- (Path.userHome / sbtrc) ::
- (s.baseDir / sbtrc asFile) ::
- Nil
+ @deprecated("Use the `log` member of a State instance directly.", "0.12.0")
+ def logger(s: State) = s.log
- def readLines(files: Seq[File]): Seq[String] = files flatMap (line => IO.readLines(line)) flatMap processLine
- def processLine(s: String) = { val trimmed = s.trim; if(ignoreLine(trimmed)) None else Some(trimmed) }
- def ignoreLine(s: String) = s.isEmpty || s.startsWith("#")
+ @deprecated("Use the `globalLogging` member of a State instance directly.", "0.12.0")
+ def globalLogging(s: State) = s.globalLogging
/** The prefix used to identify a request to execute the remaining input on source changes.*/
- val ContinuousExecutePrefix = "~"
- val HelpCommand = "help"
val AboutCommand = "about"
val TasksCommand = "tasks"
val ProjectCommand = "project"
val ProjectsCommand = "projects"
val ShowCommand = "show"
val BootCommand = "boot"
- val Exit = "exit"
- val Quit = "quit"
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ val ContinuousExecutePrefix = BasicCommandStrings.ContinuousExecutePrefix
+
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ val Exit = BasicCommandStrings.Exit
+
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ val Quit = BasicCommandStrings.Quit
val EvalCommand = "eval"
val evalBrief = (EvalCommand + " <expression>", "Evaluates the given Scala expression and prints the result and type.")
@@ -128,9 +112,8 @@ SetCommand + """ <setting-expression>
def sessionBrief = (SessionCommand + " <session-command>", "Manipulates session settings. For details, run 'help " + SessionCommand + "'.")
/** The command name to terminate the program.*/
- val TerminateAction: String = Exit
-
- def continuousBriefHelp = (ContinuousExecutePrefix + " <command>", "Executes the specified command whenever source files change.")
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ val TerminateAction: String = BasicCommandStrings.TerminateAction
def tasksPreamble = """
This is a list of tasks defined for the current project.
@@ -140,11 +123,6 @@ Tasks produce values. Use the 'show' command to run the task and print the resu
def tasksBrief = "Displays the tasks defined for the current project."
def tasksDetailed = "Displays the tasks defined directly or indirectly for the current project."
- def helpBrief = (HelpCommand + " [command]*", "Displays this help message or prints detailed help on requested commands.")
- def helpDetailed = """
-If an argument is provided, this prints detailed help for that command.
-Otherwise, this prints a help summary."""
-
def aboutBrief = "Displays basic information about sbt and the build."
def aboutDetailed = aboutBrief
@@ -175,126 +153,23 @@ ProjectCommand +
def projectsBrief = projectsDetailed
def projectsDetailed = "Displays the names of available projects."
- def historyHelp = Help.briefDetail(HistoryCommands.descriptions)
-
- def exitBrief = "Terminates the build."
-
def sbtrc = ".sbtrc"
- def ReadCommand = "<"
- def ReadFiles = " file1 file2 ..."
- def ReadBrief = (ReadCommand + " <file>*", "Reads command lines from the provided files.")
- def ReadDetailed =
-ReadCommand + ReadFiles + """
-
- Reads the lines from the given files and inserts them as commands.
- All empty lines and lines that start with '#' are ignored.
- If a file does not exist or is not readable, this command fails.
-
- All the lines from all the files are read before any of the commands
- are executed. Thus, if any file is not readable, none of commands
- from any of the files (even the existing ones) will be run.
-
- You probably need to escape this command if entering it at your shell."""
-
- def ApplyCommand = "apply"
- def ApplyBrief = (ApplyCommand + " <module-name>*", ApplyDetailed)
- def ApplyDetailed = "Transforms the current State by calling <module-name>.apply(currentState) for each listed."
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ def ReadCommand = BasicCommandStrings.ReadCommand
def DefaultsCommand = "add-default-commands"
def DefaultsBrief = (DefaultsCommand, DefaultsDetailed)
def DefaultsDetailed = "Registers default built-in commands"
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
def RebootCommand = "reboot"
- def RebootSummary = RebootCommand + " [full]"
- def RebootBrief = (RebootSummary, "Reboots sbt and then executes the remaining commands.")
- def RebootDetailed =
-RebootSummary + """
-
- This command is equivalent to exiting sbt, restarting, and running the
- remaining commands with the exception that the JVM is not shut down.
-
- If 'full' is specified, the boot directory (`~/.sbt/boot` by default)
- is deleted before restarting. This forces an update of sbt and Scala
- and is useful when working with development versions of sbt or Scala."""
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
def Multi = ";"
- def MultiBrief = (Multi + " <command> (" + Multi + " <command>)*", "Runs the provided semicolon-separated commands.")
- def MultiDetailed =
-Multi + " command1 " + Multi + """ command2 ...
-
- Runs the specified commands."""
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
def AppendCommand = "append"
- def AppendLastBrief = (AppendCommand + " <command>", AppendLastDetailed)
- def AppendLastDetailed = "Appends 'command' to list of commands to run."
-
- val AliasCommand = "alias"
- def AliasBrief = (AliasCommand, "Adds, removes, or prints command aliases.")
- def AliasDetailed =
-AliasCommand + """
-
- Prints a list of defined aliases.
-
-""" +
-AliasCommand + """ name
-
- Prints the alias defined for `name`.
-
-""" +
-AliasCommand + """ name=value
-
- Sets the alias `name` to `value`, replacing any existing alias with that name.
- Whenever `name` is entered, the corresponding `value` is run.
- If any argument is provided to `name`, it is appended as argument to `value`.
-
-""" +
-AliasCommand + """ name=
-
- Removes the alias for `name`."""
-
- def Discover = "discover"
- def DiscoverBrief = (DiscoverSyntax, "Finds annotated classes and subclasses.")
- def DiscoverSyntax = Discover + " [-module true|false] [-sub <names>] [-annot <names>]"
- def DiscoverDetailed =
-DiscoverSyntax + """
-
- Looks for public, concrete classes that match the requested query using the current sbt.inc.Analysis instance.
-
- -module
- Specifies whether modules (true) or classes (false) are found.
- The default is classes/traits (false).
-
- -sub
- Specifies comma-separated class names.
- Classes that have one or more of these classes as an ancestor are included in the resulting list.
-
- -annot
- Specifies comma-separated annotation names.
- Classes with one or more of these annotations on the class or one of its non-private methods are included in the resulting list.
-"""
-
- def CompileName = "direct-compile"
- def CompileBrief = (CompileSyntax, "Incrementally compiles the provided sources.")
- def CompileSyntax = CompileName + " -src <paths> [-cp <paths>] [-d <path>]"
- def CompileDetailed =
-CompileSyntax + """
-
- Incrementally compiles Scala and Java sources.
-
- <paths> are explicit paths separated by the platform path separator.
-
- The specified output path will contain the following directory structure:
-
- scala_<version>/
- classes/
- cache/
-
- Compiled classes will be written to the 'classes' directory.
- Cached information about the compilation will be written to 'cache'.
-"""
-
- val FailureWall = "---"
def Load = "load"
def LoadLabel = "a project"
@@ -308,31 +183,20 @@ CompileSyntax + """
def LoadProjectBrief = (LoadProject, LoadProjectDetailed)
def LoadProjectDetailed = "Loads the project in the current directory"
- def Shell = "shell"
- def ShellBrief = ShellDetailed
- def ShellDetailed = "Provides an interactive prompt from which commands can be run."
-
- def ClearOnFailure = "--"
- def OnFailure = "-"
- def OnFailureBrief = (OnFailure + " command", "Registers 'command' to run if a command fails.")
- def OnFailureDetailed =
-OnFailure + """ command
+ @deprecated("Moved to State", "0.12.0")
+ val FailureWall = State.FailureWall
- Registers 'command' to run when a command fails to complete normally.
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ def Shell = BasicCommandStrings.Shell
- Only one failure command may be registered at a time, so this command
- replaces the previous command if there is one.
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ def ClearOnFailure = "--"
- The failure command resets when it runs once, so it must be added
- again if desired."""
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
+ def OnFailure = "-"
+ @deprecated("Moved to BasicCommandStrings", "0.12.0")
def IfLast = "iflast"
- def IfLastBrief = (IfLast + " <command>", IfLastCommon)
- def IfLastCommon = "If there are no more commands after this one, 'command' is run."
- def IfLastDetailed =
-IfLast + """ command
-
- """ + IfLastCommon
def InitCommand = "initialize"
def InitBrief = (InitCommand, "Initializes command processing.")
@@ -352,4 +216,12 @@ load-commands -base ~/.sbt/commands
< .sbtrc
Runs commands from ~/.sbtrc and ./.sbtrc if they exist
"""
+
+ import java.io.File
+ import Path._
+
+ def sbtRCs(s: State): Seq[File] =
+ (Path.userHome / sbtrc) ::
+ (s.baseDir / sbtrc asFile) ::
+ Nil
}
@@ -14,7 +14,7 @@ object IvyConsole
lazy val command =
Command.command(Name) { state =>
val Dependencies(managed, repos, unmanaged) = parseDependencies(state.remainingCommands, state.log)
- val base = new File(CommandSupport.bootDirectory(state), Name)
+ val base = new File(CommandUtil.bootDirectory(state), Name)
IO.createDirectory(base)
val (eval, structure) = Load.defaultLoad(state, base, state.log)
View
@@ -56,11 +56,10 @@ object Keys
// val onComplete = SettingKey[RMap[Task,Result] => RMap[Task,Result]]("on-complete", "Transformation to apply to the final task result map. This may also be used to register hooks to run when task evaluation completes.")
// Command keys
- val globalLogging = AttributeKey[GlobalLogging]("global-logging", "Provides a global Logger, including command logging.")
- val historyPath = SettingKey[Option[File]]("history", "The location where command line history is persisted.")
- val shellPrompt = SettingKey[State => String]("shell-prompt", "The function that constructs the command prompt from the current build state.")
+ val historyPath = SettingKey(BasicKeys.historyPath)
+ val shellPrompt = SettingKey(BasicKeys.shellPrompt)
val analysis = AttributeKey[inc.Analysis]("analysis", "Analysis of compilation, including dependencies and generated outputs.")
- val watch = SettingKey[Watched]("watch", "Continuous execution configuration.")
+ val watch = SettingKey(BasicKeys.watch)
val pollInterval = SettingKey[Int]("poll-interval", "Interval between checks for modified sources by the continuous execution command.")
val watchSources = TaskKey[Seq[File]]("watch-sources", "Defines the sources in this project for continuous execution to watch for changes.")
val watchTransitiveSources = TaskKey[Seq[File]]("watch-transitive-sources", "Defines the sources in all projects for continuous execution to watch.")
View
@@ -14,7 +14,7 @@ package sbt
import inc.{FileValueCache, Locate}
import Project.{inScope, ScopedKey, ScopeLocal, Setting}
import Keys.{appConfiguration, baseDirectory, configuration, streams, Streams, thisProject, thisProjectRef}
- import Keys.{globalLogging, isDummy, loadedBuild, parseResult, resolvedScoped, taskDefinitionKey}
+ import Keys.{isDummy, loadedBuild, parseResult, resolvedScoped, taskDefinitionKey}
import tools.nsc.reporters.ConsoleReporter
import Build.{analyzed, data}
import Scope.{GlobalScope, ThisScope}
@@ -489,7 +489,7 @@ object Load
val inputs = Compiler.inputs(data(classpath), sources, target, Nil, Nil, definesClass, Compiler.DefaultMaxErrors, CompileOrder.Mixed)(compilers, log)
val analysis =
try { Compiler(inputs, log) }
- catch { case _: xsbti.CompileFailed => throw new NoMessageException } // compiler already logged errors
+ catch { case _: xsbti.CompileFailed => throw new AlreadyHandledException } // compiler already logged errors
(inputs, analysis)
}
View
@@ -9,6 +9,7 @@ package sbt
import std.Transform
import Project.ScopedKey
import Scope.GlobalScope
+ import MainLogging._
import Keys.{logLevel, logManager, persistLogLevel, persistTraceLevel, state, traceLevel}
object LogManager
@@ -21,11 +22,6 @@ object LogManager
lazy val default: LogManager = withLoggers()
def defaults(extra: ScopedKey[_] => Seq[AbstractLogger]): LogManager = withLoggers(extra = extra)
- def defaultScreen: AbstractLogger = ConsoleLogger()
-
- def defaultBacked(useColor: Boolean = ConsoleLogger.formatEnabled): PrintWriter => ConsoleLogger =
- to => ConsoleLogger(ConsoleLogger.printWriterOut(to), useColor = useColor) // TODO: should probably filter ANSI codes when useColor=false
-
def withScreenLogger(mk: => AbstractLogger): LogManager = withLoggers(mk)
def withLoggers(screen: => AbstractLogger = defaultScreen, backed: PrintWriter => AbstractLogger = defaultBacked(), extra: ScopedKey[_] => Seq[AbstractLogger] = _ => Nil): LogManager =
@@ -42,40 +38,12 @@ object LogManager
val backingLevel = getOr(persistLogLevel.key, Level.Debug)
val screenTrace = getOr(traceLevel.key, -1)
val backingTrace = getOr(persistTraceLevel.key, Int.MaxValue)
- val extraBacked = (state get Keys.globalLogging).map(_.backed).toList
+ val extraBacked = state.globalLogging.backed :: Nil
multiLogger( new MultiLoggerConfig(console, backed, extraBacked ::: extra, screenLevel, backingLevel, screenTrace, backingTrace) )
}
- def multiLogger(config: MultiLoggerConfig): Logger =
- {
- import config._
- val multi = new MultiLogger(console :: backed :: extra)
- // sets multi to the most verbose for clients that inspect the current level
- multi setLevel Level.unionAll(backingLevel :: screenLevel :: extra.map(_.getLevel))
- // set the specific levels
- console setLevel screenLevel
- backed setLevel backingLevel
- console setTrace screenTrace
- backed setTrace backingTrace
- multi: Logger
- }
- def globalDefault(writer: PrintWriter, backing: GlobalLogBacking): GlobalLogging =
- {
- val backed = defaultBacked()(writer)
- val full = multiLogger(defaultMultiConfig( backed ) )
- GlobalLogging(full, backed, backing)
- }
-
- def defaultMultiConfig(backing: AbstractLogger): MultiLoggerConfig =
- new MultiLoggerConfig(defaultScreen, backing, Nil, Level.Info, Level.Debug, -1, Int.MaxValue)
}
-final case class MultiLoggerConfig(console: AbstractLogger, backed: AbstractLogger, extra: List[AbstractLogger], screenLevel: Level.Value, backingLevel: Level.Value, screenTrace: Int, backingTrace: Int)
+
trait LogManager
{
def apply(data: Settings[Scope], state: State, task: ScopedKey[_], writer: PrintWriter): Logger
}
-final case class GlobalLogBacking(file: File, last: Option[File])
-{
- def shift(newFile: File) = GlobalLogBacking(newFile, Some(file))
- def unshift = GlobalLogBacking(last getOrElse file, None)
-}
-final case class GlobalLogging(full: Logger, backed: ConsoleLogger, backing: GlobalLogBacking)
Oops, something went wrong. Retry.

0 comments on commit 98c98f9

Please sign in to comment.