Merge commit 'refs/pull/10'

Conflicts:
	build.sbt
This commit is contained in:
Johannes Rudolph 2012-10-21 18:59:36 +02:00
commit 445d53a583
3 changed files with 33 additions and 2 deletions

View File

@ -3,3 +3,5 @@ seq(lsSettings :_*)
CrossBuilding.crossSbtVersions := Seq("0.11.1", "0.11.2", "0.11.3", "0.12")
CrossBuilding.scriptedSettings
libraryDependencies += "com.github.mdr" %% "ascii-graphs" % "0.0.2"

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 layout._
object IvyGraphMLDependencies extends App {
case class Module(organisation: String, name: String, version: String, error: Option[String] = None) {
@ -44,8 +46,22 @@ object IvyGraphMLDependencies extends App {
ModuleGraph(nodes, edges)
}
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 ascii(ivyReportFile: String): String = {
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

@ -29,6 +29,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",
@ -55,13 +59,15 @@ object Plugin extends sbt.Plugin {
ivyReport <<= ivyReportFunction map (_(config.toString)) dependsOn(ignoreMissingUpdate),
asciiGraph <<= asciiGraphTask,
dependencyGraph <<= printAsciiGraphTask,
asciiTree <<= asciiTreeTask,
dependencyTree <<= printAsciiTreeTask,
dependencyGraphMLFile <<= target / "dependencies-%s.graphml".format(config.toString),
dependencyGraphML <<= dependencyGraphMLTask,
Compat.ignoreMissingUpdateT
))
def asciiGraphTask = (ivyReport) map { report =>
IvyGraphMLDependencies.ascii(report.getAbsolutePath)
IvyGraphMLDependencies.asciiGraph(report.getAbsolutePath)
}
def printAsciiGraphTask =
@ -74,6 +80,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