Enable the asciiGraphWidth setting to the dependencyTree tasks. #5962

This commit is contained in:
kijuky 2021-10-19 01:36:04 +09:00
parent 4f102fc46f
commit 76c1b68516
9 changed files with 76 additions and 11 deletions

View File

@ -12,7 +12,6 @@ import sbt.util.Show
import java.io.File
import Def.{ ScopedKey, compiled, flattenLocals }
import sbt.internal.util.Terminal
import Predef.{ any2stringadd => _, _ }
import sbt.io.IO
@ -123,10 +122,4 @@ object Graph {
toAsciiLines(top, 0, Set.empty).mkString("\n")
}
def defaultColumnSize: Int = {
val termWidth = Terminal.console.getWidth
if (termWidth > 20) termWidth - 8
else 80 // ignore termWidth
}
}

View File

@ -13,7 +13,7 @@ package rendering
import sbt.internal.util.Terminal.red
object AsciiTree {
def asciiTree(graph: ModuleGraph): String = {
def asciiTree(graph: ModuleGraph, graphWidth: Int): String = {
val deps = graph.dependencyMap
// there should only be one root node (the project itself)
@ -25,7 +25,7 @@ object AsciiTree {
root,
node => deps.getOrElse(node.id, Seq.empty[Module]),
displayModule,
Graph.defaultColumnSize
graphWidth
)
}
.mkString("\n")

View File

@ -80,7 +80,13 @@ object DependencyTreeSettings {
else GraphTransformations.ignoreScalaLibrary(sv, g)
},
dependencyTreeModuleGraphStore := (dependencyTreeModuleGraph0 storeAs dependencyTreeModuleGraphStore triggeredBy dependencyTreeModuleGraph0).value,
) ++ renderingTaskSettings(dependencyTree, rendering.AsciiTree.asciiTree _)
) ++ {
renderingTaskSettings(dependencyTree, null) :+ {
dependencyTree / asString := {
rendering.AsciiTree.asciiTree(dependencyTreeModuleGraph0.value, asciiGraphWidth.value)
}
}
}
/**
* This is the maximum strength settings for DependencyTreePlugin.
@ -130,11 +136,12 @@ object DependencyTreeSettings {
case None =>
graph.nodes.filter(m => m.id.organization == org && m.id.name == name).map(_.id)
}
val graphWidth = asciiGraphWidth.value
val output =
modules
.map { module =>
rendering.AsciiTree
.asciiTree(GraphTransformations.reverseGraphStartingAt(graph, module))
.asciiTree(GraphTransformations.reverseGraphStartingAt(graph, module), graphWidth)
}
.mkString("\n")

View File

@ -0,0 +1,13 @@
[@kijuky]: https://github.com/kijuky
[5962]: https://github.com/sbt/sbt/issues/5962
### Fixes with compatibility implications
- The output of the dependencyTree will not be truncated at the console width.
### Improvements
- Enable the asciiGraphWidth setting in the dependencyTree tasks.
### Bug fixes

View File

@ -0,0 +1,24 @@
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.5"
name := "asciiGraphWidthSpecs"
lazy val whenIsDefault = (project in file("when-is-default"))
.settings(
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.1.0",
check := checkTask.value
)
lazy val whenIs20 = (project in file("when-is-20"))
.settings(
asciiGraphWidth := 20,
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.1.0",
check := checkTask.value
)
lazy val check = taskKey[Unit]("check")
lazy val checkTask = Def.task {
val context = thisProject.value
val expected = IO.read(file(s"${context.base}/expected.txt"))
val actual = (Compile / dependencyTree / asString).value
require(actual == expected, s"${context.id} is failed.")
}

View File

@ -0,0 +1 @@
addDependencyTreePlugin

View File

@ -0,0 +1 @@
> check

View File

@ -0,0 +1,13 @@
whenis20:whenis20_..
+-org.typelevel:..
+-org.typeleve..
| +-org.typele..
| +-org.type..
| +-org.type..
|
+-org.typeleve..
+-org.typele..
+-org.type..
+-org.ty..
+-org.ty..

View File

@ -0,0 +1,13 @@
whenisdefault:whenisdefault_2.13:0.1.0-SNAPSHOT [S]
+-org.typelevel:cats-effect_2.13:3.1.0 [S]
+-org.typelevel:cats-effect-kernel_2.13:3.1.0 [S]
| +-org.typelevel:cats-core_2.13:2.6.0 [S]
| +-org.typelevel:cats-kernel_2.13:2.6.0 [S]
| +-org.typelevel:simulacrum-scalafix-annotations_2.13:0.5.4 [S]
|
+-org.typelevel:cats-effect-std_2.13:3.1.0 [S]
+-org.typelevel:cats-effect-kernel_2.13:3.1.0 [S]
+-org.typelevel:cats-core_2.13:2.6.0 [S]
+-org.typelevel:cats-kernel_2.13:2.6.0 [S]
+-org.typelevel:simulacrum-scalafix-annotations_2.13:0.5.4 [S]