mirror of https://github.com/sbt/sbt.git
automatically use `dependency-tree` for `dependency-graph` if there are too many nodes
This commit is contained in:
parent
fb3d99e5e0
commit
2fe1989322
|
|
@ -18,6 +18,8 @@ package net.virtualvoid.sbt.graph
|
||||||
|
|
||||||
import sbt._
|
import sbt._
|
||||||
import Keys._
|
import Keys._
|
||||||
|
import complete.Parser
|
||||||
|
|
||||||
import org.apache.ivy.core.resolve.ResolveOptions
|
import org.apache.ivy.core.resolve.ResolveOptions
|
||||||
|
|
||||||
object Plugin extends sbt.Plugin {
|
object Plugin extends sbt.Plugin {
|
||||||
|
|
@ -29,7 +31,7 @@ object Plugin extends sbt.Plugin {
|
||||||
"The dependency graph for a project")
|
"The dependency graph for a project")
|
||||||
val asciiGraph = TaskKey[String]("dependency-graph-string",
|
val asciiGraph = TaskKey[String]("dependency-graph-string",
|
||||||
"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 = InputKey[Unit]("dependency-graph",
|
||||||
"Prints the ascii graph to the console")
|
"Prints the ascii graph to the console")
|
||||||
val asciiTree = TaskKey[String]("dependency-tree-string",
|
val asciiTree = TaskKey[String]("dependency-tree-string",
|
||||||
"Returns a string containing an ascii tree representation of the dependency graph for a project")
|
"Returns a string containing an ascii tree representation of the dependency graph for a project")
|
||||||
|
|
@ -61,7 +63,20 @@ object Plugin extends sbt.Plugin {
|
||||||
ivyReport <<= ivyReportFunction map (_(config.toString)) dependsOn(ignoreMissingUpdate),
|
ivyReport <<= ivyReportFunction map (_(config.toString)) dependsOn(ignoreMissingUpdate),
|
||||||
moduleGraph <<= ivyReport map (absoluteReportPath.andThen(IvyGraphMLDependencies.graph)),
|
moduleGraph <<= ivyReport map (absoluteReportPath.andThen(IvyGraphMLDependencies.graph)),
|
||||||
asciiGraph <<= moduleGraph map IvyGraphMLDependencies.asciiGraph,
|
asciiGraph <<= moduleGraph map IvyGraphMLDependencies.asciiGraph,
|
||||||
dependencyGraph <<= print(asciiGraph),
|
dependencyGraph <<= InputTask(parser) { force =>
|
||||||
|
(force, moduleGraph, streams) map { (force, graph, streams) =>
|
||||||
|
if (force || graph.nodes.size < 15) {
|
||||||
|
streams.log.info(IvyGraphMLDependencies.asciiGraph(graph))
|
||||||
|
} else {
|
||||||
|
streams.log.info(IvyGraphMLDependencies.asciiTree(graph))
|
||||||
|
|
||||||
|
if (!force) {
|
||||||
|
streams.log.info("\n")
|
||||||
|
streams.log.info("Note: The graph was estimated to be too big to display (> 15 nodes). Use `dependency-graph --force` to force graph display.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
asciiTree <<= moduleGraph map IvyGraphMLDependencies.asciiTree,
|
asciiTree <<= moduleGraph map IvyGraphMLDependencies.asciiTree,
|
||||||
dependencyTree <<= print(asciiTree),
|
dependencyTree <<= print(asciiTree),
|
||||||
dependencyGraphMLFile <<= target / "dependencies-%s.graphml".format(config.toString),
|
dependencyGraphMLFile <<= target / "dependencies-%s.graphml".format(config.toString),
|
||||||
|
|
@ -84,6 +99,13 @@ object Plugin extends sbt.Plugin {
|
||||||
def print(key: TaskKey[String]) =
|
def print(key: TaskKey[String]) =
|
||||||
(streams, key) map (_.log.info(_))
|
(streams, key) map (_.log.info(_))
|
||||||
|
|
||||||
|
import Project._
|
||||||
|
val parser: State => Parser[Boolean] = { (state: State) =>
|
||||||
|
import complete.DefaultParsers._
|
||||||
|
|
||||||
|
(Space ~> token("--force")).?.map(_.isDefined)
|
||||||
|
}
|
||||||
|
|
||||||
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