mirror of https://github.com/sbt/sbt.git
handle Scala version better in 'about' command
This commit is contained in:
parent
ff95799af7
commit
6ea27e893b
|
|
@ -144,14 +144,28 @@ object BuiltinCommands
|
||||||
{
|
{
|
||||||
val e = Project.extract(s)
|
val e = Project.extract(s)
|
||||||
val current = "The current project is " + Project.display(e.currentRef) + "\n"
|
val current = "The current project is " + Project.display(e.currentRef) + "\n"
|
||||||
val built = e.getOpt(Keys.scalaVersion) match {
|
val sc = aboutScala(s, e)
|
||||||
case Some(sv) => "The current project is built against Scala " + sv + "\n"
|
val built = if(sc.isEmpty) "" else "The current project is built against " + sc + "\n"
|
||||||
case None => ""
|
|
||||||
}
|
|
||||||
current + built
|
current + built
|
||||||
}
|
}
|
||||||
else "No project is currently loaded.\n"
|
else "No project is currently loaded.\n"
|
||||||
|
|
||||||
|
def aboutScala(s: State, e: Extracted): String =
|
||||||
|
{
|
||||||
|
val scalaVersion = e.getOpt(Keys.scalaVersion)
|
||||||
|
val scalaHome = e.getOpt(Keys.scalaHome).flatMap(idFun)
|
||||||
|
val instance = e.getOpt(Keys.scalaInstance.task).flatMap(_ => quiet(e.evalTask(Keys.scalaInstance, s)))
|
||||||
|
(scalaVersion, scalaHome, instance) match {
|
||||||
|
case (sv, Some(home), Some(si)) => "local Scala version " + selectScalaVersion(sv, si) + " at " + home.getAbsolutePath
|
||||||
|
case (_, Some(home), None) => "a local Scala build at " + home.getAbsolutePath
|
||||||
|
case (sv, None, Some(si)) => "Scala " + selectScalaVersion(sv, si)
|
||||||
|
case (Some(sv), None, None) => "Scala " + sv
|
||||||
|
case (None, None, None) => ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private[this] def selectScalaVersion(sv: Option[String], si: ScalaInstance): String = sv match { case Some(si.version) => si.version; case _ => si.actualVersion }
|
||||||
|
private[this] def quiet[T](t: => T): Option[T] = try { Some(t) } catch { case e: Exception => None }
|
||||||
|
|
||||||
def tasks = Command.command(TasksCommand, tasksBrief, tasksDetailed) { s =>
|
def tasks = Command.command(TasksCommand, tasksBrief, tasksDetailed) { s =>
|
||||||
System.out.println(tasksPreamble)
|
System.out.println(tasksPreamble)
|
||||||
System.out.println(tasksHelp(s))
|
System.out.println(tasksHelp(s))
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,7 @@ final case class Extracted(structure: BuildStructure, session: SessionSettings,
|
||||||
def evalTask[T](key: ScopedTask[T], state: State): T =
|
def evalTask[T](key: ScopedTask[T], state: State): T =
|
||||||
{
|
{
|
||||||
import EvaluateTask._
|
import EvaluateTask._
|
||||||
val extracted = Project.extract(state)
|
val rkey = Project.mapScope(Scope.resolveScope(GlobalScope, currentRef.build, rootProject) )( key.scopedKey )
|
||||||
val rkey = Project.mapScope(Scope.resolveScope(GlobalScope, extracted.currentRef.build, rootProject) )( key.scopedKey )
|
|
||||||
val value: Option[Result[T]] = evaluateTask(structure, key.task.scopedKey, state, currentRef)
|
val value: Option[Result[T]] = evaluateTask(structure, key.task.scopedKey, state, currentRef)
|
||||||
val result = getOrError(rkey.scope, rkey.key, value)
|
val result = getOrError(rkey.scope, rkey.key, value)
|
||||||
processResult(result, ConsoleLogger())
|
processResult(result, ConsoleLogger())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue