Skip to content

Commit

Permalink
Merge pull request #29 from xuwei-k/svg
Browse files Browse the repository at this point in the history
add projectsGraphSvg command
  • Loading branch information
dwijnand authored Jun 4, 2018
2 parents ea158d4 + fb009ba commit f1cb409
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ branches:
- master
- /^v[0-9]/

addons:
apt:
packages:
- graphviz

env:
global:
- COURSIER_PROGRESS=0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ As `sbt-project-graph` is an auto plugin that is all that is required.
## Tasks

[DOT]: https://en.wikipedia.org/wiki/DOT_(graph_description_language)
[graphviz]: https://www.graphviz.org

* `projectsGraphDot`: Creates `target/projects-graph.dot` with the project graph. See [DOT][].
* `projectsGraphSvg`: Creates `target/projects-graph.svg` with the project graph. Require [graphviz][].

## Licence

Expand Down
24 changes: 22 additions & 2 deletions src/main/scala/sbtprojectgraph/SbtProjectGraphPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ import sbt.internal.{ BuildStructure, LoadedBuildUnit } // sbt/sbt#3296
object SbtProjectGraphPlugin extends AutoPlugin {
override def trigger = allRequirements

override def buildSettings: Seq[Setting[_]] = Seq(commands += projectsGraphDot)
override def buildSettings: Seq[Setting[_]] = Seq(
commands ++= Seq(
projectsGraphDot,
projectsGraphSvg
)
)

val projectsGraphDot = Command.command("projectsGraphDot") { s =>
val (_, state) = executeProjectsGraphDot(s)
state
}

val projectsGraphSvg = Command.command("projectsGraphSvg") { s =>
val (dotFile, state) = executeProjectsGraphDot(s)
val extracted = Project extract state
val svgFile = extracted.get(target) / "projects-graph.svg"
val command = Seq("dot", "-o" + svgFile.getAbsolutePath, "-Tsvg", dotFile.getAbsolutePath)
sys.process.Process(command).!
extracted get sLog info s"Wrote project graph to '$svgFile'"
state
}

private[this] def executeProjectsGraphDot(s: State): (File, State) = {
val extracted: Extracted = Project extract s

val currentBuildUri: URI = extracted.currentRef.build
Expand All @@ -31,6 +51,6 @@ object SbtProjectGraphPlugin extends AutoPlugin {

extracted get sLog info s"Wrote project graph to '$projectsGraphDotFile'"

s
(projectsGraphDotFile, s)
}
}
2 changes: 2 additions & 0 deletions src/sbt-test/spec/works/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
> projectsGraphDot
> check
> projectsGraphSvg
$ exists target/projects-graph.svg

0 comments on commit f1cb409

Please sign in to comment.