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

Add moduleTree to preserve tree structure for other tools #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ trait DependencyGraphKeys {
val moduleGraph = TaskKey[ModuleGraph](
"module-graph",
"The dependency graph for a project")
val moduleTree = TaskKey[ModuleTree](
"module-tree",
"The dependency tree for a project")
val moduleGraphIvyReport = TaskKey[ModuleGraph](
"module-graph-ivy-report",
"The dependency graph for a project as generated from an Ivy Report XML")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ object DependencyGraphSettings {
},
moduleGraphStore := (moduleGraph storeAs moduleGraphStore triggeredBy moduleGraph).value,

moduleTree := ModuleTree(DependencyGraphKeys.moduleGraph.value),

// browse
dependencyBrowseGraphTarget := { target.value / "browse-dependency-graph" },
dependencyBrowseGraphHTML := browseGraphHTMLTask.value,
Expand Down
20 changes: 20 additions & 0 deletions src/main/scala/net/virtualvoid/sbt/graph/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.io.File
import sbinary.Format

import scala.collection.mutable.{ HashMap, MultiMap, Set }
import scala.collection.immutable

case class ModuleId(
organisation: String,
Expand Down Expand Up @@ -77,3 +78,22 @@ object ModuleGraphProtocol extends ModuleGraphProtocolCompat {
implicit val ModuleFormat: Format[Module] = asProduct6(Module)(Module.unapply(_).get)
implicit val ModuleGraphFormat: Format[ModuleGraph] = asProduct2(ModuleGraph.apply _)(ModuleGraph.unapply(_).get)
}

case class ModuleTreeNode(node: Module, children: immutable.Seq[ModuleTreeNode])

object ModuleTreeNode {
def apply(module: Module, deps: Map[ModuleId, Seq[Module]]): ModuleTreeNode = {
val children = deps.getOrElse(module.id, immutable.Seq.empty[Module]).map(m ⇒ apply(m, deps)).toList
ModuleTreeNode(module, children)
}
}

case class ModuleTree(roots: immutable.Seq[ModuleTreeNode])

object ModuleTree {
def apply(graph: ModuleGraph): ModuleTree = {
val deps = graph.dependencyMap
ModuleTree(graph.roots.toList.map { root ⇒ ModuleTreeNode(root, deps) })
}

}