mirror of https://github.com/sbt/sbt.git
Merge pull request #5435 from dwijnand/tweak-Def.displayRelative
Tweak Def.displayRelative
This commit is contained in:
commit
9c384dca15
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -47,4 +47,28 @@ class ScopeDisplaySpec extends FlatSpec {
|
|||
)
|
||||
assert(string == "blah")
|
||||
}
|
||||
|
||||
behavior of "Def.displayRelative2"
|
||||
|
||||
val b1 = project.build
|
||||
val b2 = sbt.io.IO.toURI(file("other"))
|
||||
|
||||
val p1 = project
|
||||
val p2 = ProjectRef(b1, "baz")
|
||||
val p3 = ProjectRef(b2, "qux")
|
||||
|
||||
private def disp(r: Reference) = Def.displayRelative2(current = p1, r)
|
||||
|
||||
it should "ProjectRef curr proj" in assert(disp(p1) == "")
|
||||
it should "ProjectRef same build" in assert(disp(p2) == "baz /")
|
||||
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)) == "<root> /")
|
||||
it should "RootProject diff build" in assert(disp(RootProject(b2)) == "{other }<root> /")
|
||||
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