mirror of https://github.com/sbt/sbt.git
sbt-based repl access with command line dependency declarations
based on the ideas of n8han, softprops, paulp
This commit is contained in:
parent
30e454af0a
commit
c432331ec0
|
|
@ -0,0 +1,62 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2011 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
import java.io.File
|
||||
import Attributed.blankSeq
|
||||
import Configurations.Compile
|
||||
import Keys._
|
||||
|
||||
object IvyConsole
|
||||
{
|
||||
final val Name = "ivy-console"
|
||||
lazy val command =
|
||||
Command.command(Name) { state =>
|
||||
val Dependencies(managed, repos, unmanaged) = parseDependencies(state.remainingCommands, CommandSupport.logger(state))
|
||||
val base = new File(state.configuration.provider.scalaProvider.launcher.bootDirectory, Name)
|
||||
IO.createDirectory(base)
|
||||
|
||||
val (eval, structure) = Load.defaultLoad(state, base, CommandSupport.logger(state))
|
||||
val session = Load.initialSession(structure, eval)
|
||||
val extracted = Project.extract(session, structure)
|
||||
import extracted._
|
||||
|
||||
val depSettings: Seq[Project.Setting[_]] = Seq(
|
||||
libraryDependencies ++= managed.reverse,
|
||||
resolvers ++= repos.reverse,
|
||||
unmanagedJars in Compile ++= unmanaged.reverse,
|
||||
logLevel in Global := Level.Warn,
|
||||
showSuccess in Global := false
|
||||
)
|
||||
val append = Load.transformSettings(Load.projectScope(currentRef), currentRef.build, rootProject, depSettings)
|
||||
|
||||
val newStructure = Load.reapply(session.original ++ append, structure)
|
||||
val newState = state.copy(remainingCommands = "console-quick" :: Nil)
|
||||
Project.setProject(session, newStructure, newState)
|
||||
}
|
||||
|
||||
final case class Dependencies(managed: Seq[ModuleID], resolvers: Seq[Resolver], unmanaged: Seq[File])
|
||||
def parseDependencies(args: Seq[String], log: Logger): Dependencies = (Dependencies(Nil, Nil, Nil) /: args)( parseArgument(log) )
|
||||
def parseArgument(log: Logger)(acc: Dependencies, arg: String): Dependencies =
|
||||
if(arg contains " at ")
|
||||
acc.copy(resolvers = parseResolver(arg) +: acc.resolvers)
|
||||
else if(arg endsWith ".jar")
|
||||
acc.copy(unmanaged = new File(arg) +: acc.unmanaged)
|
||||
else
|
||||
acc.copy(managed = parseManaged(arg, log) ++ acc.managed)
|
||||
|
||||
private[this] def parseResolver(arg: String): MavenRepository =
|
||||
{
|
||||
val Array(name, url) = arg.split(" at ")
|
||||
new MavenRepository(name.trim, url.trim)
|
||||
}
|
||||
|
||||
val DepPattern = """([^%]+)%(%?)([^%]+)%([^%]+)""".r
|
||||
def parseManaged(arg: String, log: Logger): Seq[ModuleID] =
|
||||
arg match
|
||||
{
|
||||
case DepPattern(group, cross, name, version) => ModuleID(group.trim, name.trim, version.trim, crossVersion = !cross.trim.isEmpty) :: Nil
|
||||
case _ => log.warn("Ignoring invalid argument '" + arg + "'"); Nil
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,16 @@ final class ScriptMain extends xsbti.AppMain
|
|||
MainLoop.run(state)
|
||||
}
|
||||
}
|
||||
final class ConsoleMain extends xsbti.AppMain
|
||||
{
|
||||
def run(configuration: xsbti.AppConfiguration): xsbti.MainResult =
|
||||
{
|
||||
import BuiltinCommands.{initialAttributes, ConsoleCommands}
|
||||
val commands = IvyConsole.Name +: configuration.arguments.map(_.trim)
|
||||
val state = State( configuration, ConsoleCommands, Set.empty, None, commands, initialAttributes, Next.Continue )
|
||||
MainLoop.run(state)
|
||||
}
|
||||
}
|
||||
object MainLoop
|
||||
{
|
||||
@tailrec final def run(state: State): xsbti.MainResult =
|
||||
|
|
@ -72,6 +82,7 @@ object BuiltinCommands
|
|||
{
|
||||
def initialAttributes = AttributeMap.empty.put(logged, ConsoleLogger())
|
||||
|
||||
def ConsoleCommands: Seq[Command] = Seq(ignore, exit, IvyConsole.command, act, nop)
|
||||
def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, act, nop)
|
||||
def DefaultCommands: Seq[Command] = Seq(ignore, help, reboot, read, history, continuous, exit, loadProject, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
|
||||
projects, project, setOnFailure, clearOnFailure, ifLast, multi, shell, set, inspect, eval, alias, append, last, lastGrep, nop, sessionCommand, act)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
[scala]
|
||||
version: 2.8.1
|
||||
|
||||
[app]
|
||||
org: org.scala-tools.sbt
|
||||
name: sbt
|
||||
version: read(sbt.version)[0.9.4-SNAPSHOT]
|
||||
class: ${sbt.main.class-sbt.xMain}
|
||||
components: xsbti
|
||||
cross-versioned: true
|
||||
|
||||
[repositories]
|
||||
local
|
||||
maven-local
|
||||
sbt-db: http://databinder.net/repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
|
||||
maven-central
|
||||
scala-tools-releases
|
||||
scala-tools-snapshots
|
||||
|
||||
[boot]
|
||||
directory: ${sbt.boot.directory-project/boot/}
|
||||
|
||||
[ivy]
|
||||
ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
[scala]
|
||||
version: 2.8.1
|
||||
|
||||
[app]
|
||||
org: org.scala-tools.sbt
|
||||
name: sbt
|
||||
version: 0.9.4-SNAPSHOT
|
||||
class: sbt.ScriptMain
|
||||
components: xsbti
|
||||
cross-versioned: true
|
||||
|
||||
[repositories]
|
||||
local
|
||||
maven-local
|
||||
sbt-db: http://databinder.net/repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
|
||||
maven-central
|
||||
scala-tools-releases
|
||||
scala-tools-snapshots
|
||||
|
||||
[boot]
|
||||
directory: ${sbt.boot.directory-${user.home}/.sbt/scripts/}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
[scala]
|
||||
version: 2.8.1
|
||||
|
||||
[app]
|
||||
org: org.scala-tools.sbt
|
||||
name: sbt
|
||||
version: 0.9.4-SNAPSHOT
|
||||
class: sbt.ConsoleMain
|
||||
components: xsbti
|
||||
cross-versioned: true
|
||||
|
||||
[repositories]
|
||||
local
|
||||
maven-local
|
||||
sbt-db: http://databinder.net/repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
|
||||
maven-central
|
||||
scala-tools-releases
|
||||
scala-tools-snapshots
|
||||
|
||||
[boot]
|
||||
directory: ${sbt.boot.directory-${user.home}/.sbt/screpl/}
|
||||
Loading…
Reference in New Issue