Skip to content
This repository was archived by the owner on Apr 8, 2021. It is now read-only.

add file-output option to dependencyTree #146

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ the notes of version [0.8.2](https://github.com/jrudolph/sbt-dependency-graph/tr
## Main Tasks

* `dependencyTree`: Shows an ASCII tree representation of the project's dependencies
* write output to a file by passing `-o <output path>` arguments
* `dependencyBrowseGraph`: Opens a browser window with a visualization of the dependency graph (courtesy of graphlib-dot + dagre-d3).
* `dependencyList`: Shows a flat list of all transitive dependencies on the sbt console (sorted by organization and name)
* `whatDependsOn <organization> <module> <revision>`: Find out what depends on an artifact. Shows a reverse dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ trait DependencyGraphKeys {
"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",
val dependencyTree = InputKey[Unit]("dependency-tree",
"Prints an ascii tree of all the dependencies to the console")
val dependencyList = TaskKey[Unit]("dependency-list",
"Prints a list of all dependencies to the console")
Expand All @@ -74,4 +74,4 @@ trait DependencyGraphKeys {
private[graph] val crossProjectId = SettingKey[ModuleID]("dependency-graph-cross-project-id")
}

object DependencyGraphKeys extends DependencyGraphKeys
object DependencyGraphKeys extends DependencyGraphKeys
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package net.virtualvoid.sbt.graph

import scala.language.reflectiveCalls
import java.nio.file.Files.newOutputStream
import java.nio.file.{ Path, Paths }

import sbt._
import Keys._
Expand All @@ -25,7 +27,6 @@ import net.virtualvoid.sbt.graph.backend.{ IvyReport, SbtUpdateReport }
import net.virtualvoid.sbt.graph.rendering.{ AsciiGraph, DagreHTML }
import net.virtualvoid.sbt.graph.util.IOUtil
import internal.librarymanagement._
import librarymanagement._
import sbt.dependencygraph.DependencyGraphSbtCompat
import sbt.dependencygraph.DependencyGraphSbtCompat.Implicits._

Expand All @@ -45,7 +46,7 @@ object DependencyGraphSettings {
Seq(Compile, Test, IntegrationTest, Runtime, Provided, Optional).flatMap(ivyReportForConfig)

def ivyReportForConfig(config: Configuration) = inConfig(config)(Seq(
ivyReport := { Def.task { ivyReportFunction.value.apply(config.toString) } dependsOn (ignoreMissingUpdate) }.value,
ivyReport := { Def.task { ivyReportFunction.value.apply(config.toString) } dependsOn ignoreMissingUpdate }.value,
crossProjectId := sbt.CrossVersion(scalaVersion.value, scalaBinaryVersion.value)(projectID.value),
moduleGraphSbt :=
ignoreMissingUpdate.value.configuration(configuration.value).map(report ⇒ SbtUpdateReport.fromConfigurationReport(report, crossProjectId.value)).getOrElse(ModuleGraph.empty),
Expand All @@ -66,7 +67,19 @@ object DependencyGraphSettings {
},
moduleGraphStore := (moduleGraph storeAs moduleGraphStore triggeredBy moduleGraph).value,
asciiTree := rendering.AsciiTree.asciiTree(moduleGraph.value),
dependencyTree := print(asciiTree).value,
dependencyTree := {
val tree = asciiTree.value
dependencyTreeOutputPathParser.parsed match {
case Some(path) ⇒
streams.value.log.info(s"Writing dependency-tree to path: $path")
val os = newOutputStream(path)
os.write(tree.getBytes)
os.close()
case _ ⇒
streams.value.log.info(tree)
}

},
dependencyGraphMLFile := { target.value / "dependencies-%s.graphml".format(config.toString) },
dependencyGraphML := dependencyGraphMLTask.value,
dependencyDotFile := { target.value / "dependencies-%s.dot".format(config.toString) },
Expand Down Expand Up @@ -152,13 +165,20 @@ object DependencyGraphSettings {
streams.log.info(output)
}

import Project._
import sbt.complete.DefaultParsers._
val shouldForceParser: State ⇒ Parser[Boolean] = { (state: State) ⇒
import sbt.complete.DefaultParsers._

(Space ~> token("--force")).?.map(_.isDefined)
}

val dependencyTreeOutputPathParser: State ⇒ Parser[Option[Path]] = { (state: State) ⇒
(
Space ~
(token("--out") | token("-o")) ~ Space ~>
StringBasic)
.map(Paths.get(_))
.?
}

val artifactIdParser: Def.Initialize[State ⇒ Parser[ModuleId]] =
resolvedScoped { ctx ⇒
(state: State) ⇒
Expand Down
30 changes: 30 additions & 0 deletions src/sbt-test/sbt-dependency-graph/dependencyTreeFile/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.nio.file.{ Files, Paths }

import scala.io.Source

scalaVersion := "2.9.1"

resolvers += "typesafe maven" at "https://repo.typesafe.com/typesafe/maven-releases/"

libraryDependencies ++= Seq(
"com.codahale" % "jerkson_2.9.1" % "0.5.0"
)

InputKey[Unit]("check") := {
val is = Files.newInputStream(Paths.get("foo"))
val tree = Source.fromInputStream(is).mkString
is.close()

require(
tree ==
"""default:dependencytreefile_2.9.1:0.1-SNAPSHOT [S]
| +-com.codahale:jerkson_2.9.1:0.5.0 [S]
| +-org.codehaus.jackson:jackson-core-asl:1.9.11
| +-org.codehaus.jackson:jackson-mapper-asl:1.9.11
| +-org.codehaus.jackson:jackson-core-asl:1.9.11
| """
.stripMargin,
s"Tree didn't match expected:\n$tree"
)
()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % sys.props("project.version"))
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-dependency-graph/dependencyTreeFile/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> dependencyTree -o foo
> check