Add support for ASCII-art dependency graphs

This commit is contained in:
Matt Russell 2012-06-26 08:06:06 +01:00
parent 47ba5ef22f
commit d3cd49bd73
4 changed files with 39 additions and 5 deletions

View File

@ -1,3 +1,3 @@
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")

View File

@ -4,7 +4,7 @@ name := "sbt-dependency-graph"
organization := "net.virtual-void"
version := "0.6.0"
version := "0.6.1-SNAPSHOT"
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) :=
"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"

View File

@ -23,6 +23,8 @@ import collection.mutable.MultiMap
import collection.mutable.{Set => MSet}
import sbt.Graph
import xml.{Document, XML, Node}
import com.github.mdr.ascii.layout
import com.github.mdr.ascii.layout._
object IvyGraphMLDependencies extends App {
case class Module(organisation: String, name: String, version: String) {
@ -44,8 +46,22 @@ object IvyGraphMLDependencies extends App {
ModuleGraph(nodes, edges)
}
def ascii(ivyReportFile: String): String = {
private def asciiGraph(moduleGraph: ModuleGraph): layout.Graph[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 graph = buildGraph(doc)
import graph._

View File

@ -28,6 +28,10 @@ object Plugin extends sbt.Plugin {
"Returns a string containing the ascii representation of the dependency graph for a project")
val dependencyGraph = TaskKey[Unit]("dependency-graph",
"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",
"A function which returns the file containing the ivy report from the ivy cache for a given configuration")
val ivyReport = TaskKey[File]("ivy-report",
@ -44,12 +48,14 @@ object Plugin extends sbt.Plugin {
ivyReport <<= ivyReportFunction map (_(config.toString)) dependsOn(update),
asciiGraph <<= asciiGraphTask,
dependencyGraph <<= printAsciiGraphTask,
asciiTree <<= asciiTreeTask,
dependencyTree <<= printAsciiTreeTask,
dependencyGraphMLFile <<= target / "dependencies-%s.graphml".format(config.toString),
dependencyGraphML <<= dependencyGraphMLTask
))
def asciiGraphTask = (ivyReport) map { report =>
IvyGraphMLDependencies.ascii(report.getAbsolutePath)
IvyGraphMLDependencies.asciiGraph(report.getAbsolutePath)
}
def printAsciiGraphTask =
@ -62,6 +68,13 @@ object Plugin extends sbt.Plugin {
resultFile
}
def asciiTreeTask = (ivyReport) map { report =>
IvyGraphMLDependencies.asciiTree(report.getAbsolutePath)
}
def printAsciiTreeTask =
(streams, asciiTree) map (_.log.info(_))
def crossName(ivyModule: IvySbt#Module) =
ivyModule.moduleSettings match {
case ic: InlineConfiguration => ic.module.name