mirror of https://github.com/sbt/sbt.git
Tweak Def.displayRelative
My driving use case was LocalProject: it should display the same as a fully resolved ProjectRef. Similarly ThisBuild should display as such.
This commit is contained in:
parent
4635af182a
commit
c5b684984c
|
|
@ -10,6 +10,7 @@ package sbt
|
|||
import java.io.File
|
||||
import java.net.URI
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import sbt.KeyRanks.{ DTask, Invisible }
|
||||
import sbt.Scope.{ GlobalScope, ThisScope }
|
||||
import sbt.internal.util.Types.const
|
||||
|
|
@ -132,13 +133,19 @@ object Def extends Init[Scope] with TaskMacroExtra {
|
|||
project: Reference,
|
||||
trailingSlash: Boolean
|
||||
): String = {
|
||||
val trailing = if (trailingSlash) " /" else ""
|
||||
project match {
|
||||
case BuildRef(current.build) => "ThisBuild" + trailing
|
||||
case `current` => ""
|
||||
case ProjectRef(current.build, x) => x + trailing
|
||||
case _ => Reference.display(project) + trailing
|
||||
import Reference.{ display => displayRef }
|
||||
@tailrec def loop(ref: Reference): String = ref match {
|
||||
case ProjectRef(b, p) => if (b == current.build) loop(LocalProject(p)) else displayRef(ref)
|
||||
case BuildRef(b) => if (b == current.build) loop(ThisBuild) else displayRef(ref)
|
||||
case RootProject(b) => if (b == current.build) loop(LocalRootProject) else displayRef(ref)
|
||||
case LocalProject(p) => if (p == current.project) "" else p
|
||||
case ThisBuild => "ThisBuild"
|
||||
case LocalRootProject => "<root>"
|
||||
case ThisProject => "<this>"
|
||||
}
|
||||
val str = loop(project)
|
||||
if (trailingSlash && !str.isEmpty) s"$str /"
|
||||
else str
|
||||
}
|
||||
|
||||
@deprecated("Use variant without multi", "1.1.1")
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ class ScopeDisplaySpec extends FlatSpec {
|
|||
it should "ProjectRef diff build" in assert(disp(p3) == """ProjectRef(uri("other"), "qux") /""")
|
||||
it should "BuildRef same build" in assert(disp(BuildRef(b1)) == "ThisBuild /")
|
||||
it should "BuildRef diff build" in assert(disp(BuildRef(b2)) == "{other} /")
|
||||
it should "RootProject same build" in assert(disp(RootProject(b1)) == "{foo/bar }<root> /")
|
||||
it should "RootProject same build" in assert(disp(RootProject(b1)) == "<root> /")
|
||||
it should "RootProject diff build" in assert(disp(RootProject(b2)) == "{other }<root> /")
|
||||
it should "LocalProject curr proj" in assert(disp(LocalProject(p1.project)) == "{<this>}bar /")
|
||||
it should "LocalProject diff proj" in assert(disp(LocalProject(p2.project)) == "{<this>}baz /")
|
||||
it should "ThisBuild" in assert(disp(ThisBuild) == "{<this>} /")
|
||||
it should "LocalRootProject" in assert(disp(LocalRootProject) == "{<this>}<root> /")
|
||||
it should "ThisProject" in assert(disp(ThisProject) == "{<this>}<this> /")
|
||||
it should "LocalProject curr proj" in assert(disp(LocalProject(p1.project)) == "")
|
||||
it should "LocalProject diff proj" in assert(disp(LocalProject(p2.project)) == "baz /")
|
||||
it should "ThisBuild" in assert(disp(ThisBuild) == "ThisBuild /")
|
||||
it should "LocalRootProject" in assert(disp(LocalRootProject) == "<root> /")
|
||||
it should "ThisProject" in assert(disp(ThisProject) == "<this> /")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue