mirror of https://github.com/sbt/sbt.git
Add support for ASCII-art dependency graphs
This commit is contained in:
parent
47ba5ef22f
commit
d3cd49bd73
|
|
@ -1,3 +1,3 @@
|
||||||
seq(lsSettings :_*)
|
seq(lsSettings :_*)
|
||||||
|
|
||||||
CrossBuilding.crossSbtVersions := Seq("0.11.1", "0.11.2", "0.11.3", "0.12.0-Beta2")
|
CrossBuilding.crossSbtVersions := Seq("0.11.1", "0.11.2", "0.11.3", "0.12.0-Beta2")
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ name := "sbt-dependency-graph"
|
||||||
|
|
||||||
organization := "net.virtual-void"
|
organization := "net.virtual-void"
|
||||||
|
|
||||||
version := "0.6.0"
|
version := "0.6.1-SNAPSHOT"
|
||||||
|
|
||||||
homepage := Some(url("http://github.com/jrudolph/sbt-dependency-graph"))
|
homepage := Some(url("http://github.com/jrudolph/sbt-dependency-graph"))
|
||||||
|
|
||||||
|
|
@ -16,3 +16,8 @@ licenses in GlobalScope += "Apache License 2.0" -> url("https://github.com/jrudo
|
||||||
|
|
||||||
(description in LsKeys.lsync) :=
|
(description in LsKeys.lsync) :=
|
||||||
"An sbt plugin to visualize dependencies of your build."
|
"An sbt plugin to visualize dependencies of your build."
|
||||||
|
|
||||||
|
libraryDependencies += "com.github.mdr" %% "ascii-graphs" % "0.0.1-SNAPSHOT"
|
||||||
|
|
||||||
|
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ import collection.mutable.MultiMap
|
||||||
import collection.mutable.{Set => MSet}
|
import collection.mutable.{Set => MSet}
|
||||||
import sbt.Graph
|
import sbt.Graph
|
||||||
import xml.{Document, XML, Node}
|
import xml.{Document, XML, Node}
|
||||||
|
import com.github.mdr.ascii.layout
|
||||||
|
import com.github.mdr.ascii.layout._
|
||||||
|
|
||||||
object IvyGraphMLDependencies extends App {
|
object IvyGraphMLDependencies extends App {
|
||||||
case class Module(organisation: String, name: String, version: String) {
|
case class Module(organisation: String, name: String, version: String) {
|
||||||
|
|
@ -44,8 +46,22 @@ object IvyGraphMLDependencies extends App {
|
||||||
ModuleGraph(nodes, edges)
|
ModuleGraph(nodes, edges)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def asciiGraph(moduleGraph: ModuleGraph): layout.Graph[String] = {
|
||||||
def ascii(ivyReportFile: String): String = {
|
def renderVertex(module: Module): String = {
|
||||||
|
module.name + "\n" + module.organisation + "\n" + module.version
|
||||||
|
}
|
||||||
|
val vertices = moduleGraph.nodes.map(renderVertex).toList
|
||||||
|
val edges = moduleGraph.edges.toList.map { case (from, to) ⇒ (renderVertex(from), renderVertex(to)) }
|
||||||
|
layout.Graph(vertices, edges)
|
||||||
|
}
|
||||||
|
|
||||||
|
def asciiGraph(ivyReportFile: String): String = {
|
||||||
|
val doc = buildDoc(ivyReportFile)
|
||||||
|
val graph = buildGraph(doc)
|
||||||
|
Layouter.renderGraph(asciiGraph(graph))
|
||||||
|
}
|
||||||
|
|
||||||
|
def asciiTree(ivyReportFile: String): String = {
|
||||||
val doc = buildDoc(ivyReportFile)
|
val doc = buildDoc(ivyReportFile)
|
||||||
val graph = buildGraph(doc)
|
val graph = buildGraph(doc)
|
||||||
import graph._
|
import graph._
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ object Plugin extends sbt.Plugin {
|
||||||
"Returns a string containing the ascii representation of the dependency graph for a project")
|
"Returns a string containing the ascii representation of the dependency graph for a project")
|
||||||
val dependencyGraph = TaskKey[Unit]("dependency-graph",
|
val dependencyGraph = TaskKey[Unit]("dependency-graph",
|
||||||
"Prints the ascii graph to the console")
|
"Prints the ascii graph to the console")
|
||||||
|
val asciiTree = TaskKey[String]("dependency-tree-string",
|
||||||
|
"Returns a string containing an ascii tree representation of the dependency graph for a project")
|
||||||
|
val dependencyTree = TaskKey[Unit]("dependency-tree",
|
||||||
|
"Prints the ascii tree to the console")
|
||||||
val ivyReportFunction = TaskKey[String => File]("ivy-report-function",
|
val ivyReportFunction = TaskKey[String => File]("ivy-report-function",
|
||||||
"A function which returns the file containing the ivy report from the ivy cache for a given configuration")
|
"A function which returns the file containing the ivy report from the ivy cache for a given configuration")
|
||||||
val ivyReport = TaskKey[File]("ivy-report",
|
val ivyReport = TaskKey[File]("ivy-report",
|
||||||
|
|
@ -44,12 +48,14 @@ object Plugin extends sbt.Plugin {
|
||||||
ivyReport <<= ivyReportFunction map (_(config.toString)) dependsOn(update),
|
ivyReport <<= ivyReportFunction map (_(config.toString)) dependsOn(update),
|
||||||
asciiGraph <<= asciiGraphTask,
|
asciiGraph <<= asciiGraphTask,
|
||||||
dependencyGraph <<= printAsciiGraphTask,
|
dependencyGraph <<= printAsciiGraphTask,
|
||||||
|
asciiTree <<= asciiTreeTask,
|
||||||
|
dependencyTree <<= printAsciiTreeTask,
|
||||||
dependencyGraphMLFile <<= target / "dependencies-%s.graphml".format(config.toString),
|
dependencyGraphMLFile <<= target / "dependencies-%s.graphml".format(config.toString),
|
||||||
dependencyGraphML <<= dependencyGraphMLTask
|
dependencyGraphML <<= dependencyGraphMLTask
|
||||||
))
|
))
|
||||||
|
|
||||||
def asciiGraphTask = (ivyReport) map { report =>
|
def asciiGraphTask = (ivyReport) map { report =>
|
||||||
IvyGraphMLDependencies.ascii(report.getAbsolutePath)
|
IvyGraphMLDependencies.asciiGraph(report.getAbsolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
def printAsciiGraphTask =
|
def printAsciiGraphTask =
|
||||||
|
|
@ -62,6 +68,13 @@ object Plugin extends sbt.Plugin {
|
||||||
resultFile
|
resultFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def asciiTreeTask = (ivyReport) map { report =>
|
||||||
|
IvyGraphMLDependencies.asciiTree(report.getAbsolutePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
def printAsciiTreeTask =
|
||||||
|
(streams, asciiTree) map (_.log.info(_))
|
||||||
|
|
||||||
def crossName(ivyModule: IvySbt#Module) =
|
def crossName(ivyModule: IvySbt#Module) =
|
||||||
ivyModule.moduleSettings match {
|
ivyModule.moduleSettings match {
|
||||||
case ic: InlineConfiguration => ic.module.name
|
case ic: InlineConfiguration => ic.module.name
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue