Skip to content

Commit

Permalink
Use sbt-dependency-graph 0.10.0-RC1 (#19)
Browse files Browse the repository at this point in the history
without the changes suggested in sbt/sbt-dependency-graph#168
  • Loading branch information
francisdb authored Feb 13, 2020
1 parent 2f2b65e commit ecbf5a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 1 addition & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ organization := "com.lightbend.paradox"
name := "sbt-paradox-dependencies"

addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.4.3")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2+10-148ba0ff")

resolvers += Resolver.bintrayIvyRepo("2m", "sbt-plugins")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")

licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0"))
homepage := Some(url("https://github.com/lightbend/sbt-paradox-dependencies"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@
package com.lightbend.paradox.dependencies

import com.lightbend.paradox.markdown.LeafBlockDirective
import net.virtualvoid.sbt.graph.{ModuleTree, ModuleTreeNode}
import net.virtualvoid.sbt.graph.{Module, ModuleGraph}
import org.pegdown.Printer
import org.pegdown.ast.{DirectiveNode, Visitor}

class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: String => ModuleTree)
class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: String => ModuleGraph)
extends LeafBlockDirective("dependencies") {
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
val projectId = node.attributes.value("projectId")
val tree = projectIdToDependencies(projectId)
val graph = projectIdToDependencies(projectId)
printer.println()
val classes = Seq("dependencies", node.attributes.classesString).filter(_.nonEmpty)
printer.print(s"""<dl class="${classes.mkString(" ")}">""")
if (tree.roots.flatMap(_.children).nonEmpty) {
renderDirect(node, tree.roots, showLicenses, printer)
renderTree(node, tree.roots, printer)
if (graph.roots.flatMap(m => children(graph, m)).nonEmpty) {
renderDirect(graph, showLicenses, printer)
renderTree(graph, printer)
} else {
printer.print("<dt>Direct dependencies</dt><dd>This module has no dependencies.</dd>")
}
printer.print("</dl>")
printer.println()
}

private def renderDirect(node: DirectiveNode, roots: Seq[ModuleTreeNode], showLicenses: Boolean, p: Printer): Unit = {
private def renderDirect(graph: ModuleGraph, showLicenses: Boolean, p: Printer): Unit = {
p.print("<dt>Direct dependencies</dt><dd><table>")
p.indent(2).println()
p.print("<thead><tr><th>Organization</th><th>Artifact</th><th>Version</th>")
Expand All @@ -48,10 +48,10 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri
p.print("<tbody>")
p.indent(2)
for {
r <- roots
d <- r.children
r <- graph.roots
d <- children(graph, r)
} {
val moduleId = d.node.id
val moduleId = d.id
val name = moduleId.name
p.println()
.print("<tr><td>")
Expand All @@ -64,7 +64,7 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri
)
.print(moduleId.version)
.print("</a></td>")
if (showLicenses) d.node.license.foreach(l => p.print("<td>").print(l).print("</td>"))
if (showLicenses) d.license.foreach(l => p.print("<td>").print(l).print("</td>"))
p.print("</tr>")
}
p.indent(-2).println()
Expand All @@ -73,20 +73,20 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri
p.print("</table></dd>").println()
}

private def renderTree(node: DirectiveNode, roots: Seq[ModuleTreeNode], p: Printer): Unit = {
private def renderTree(graph: ModuleGraph, p: Printer): Unit = {
p.print("<dt>Dependency tree</dt><dd><pre>")
for {
r <- roots
d <- r.children
r <- graph.roots
d <- children(graph, r)
} {
renderTreeNode(p, d)
renderTreeNode(p, graph, d)
}
p.print("</pre></dd>").println()
}

private def renderTreeNode(p: Printer, n: ModuleTreeNode): Unit =
if (n.node.evictedByVersion.isEmpty) {
val moduleId = n.node.id
private def renderTreeNode(p: Printer, graph: ModuleGraph, n: Module): Unit =
if (n.evictedByVersion.isEmpty) {
val moduleId = n.id
val name = moduleId.name
p.println()
.print(moduleId.organisation)
Expand All @@ -97,12 +97,14 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri
)
.print(moduleId.version)
.print("</a>")
n.node.license.foreach(l => p.print(" ").print(l))
if (n.children.nonEmpty) {
n.license.foreach(l => p.print(" ").print(l))
if (children(graph, n).nonEmpty) {
p.indent(4)
n.children.foreach(renderTreeNode(p, _))
children(graph, n).foreach(renderTreeNode(p, graph, _))
p.indent(-4)
}
}

private def children(graph: ModuleGraph, module: Module) = graph.dependencyMap(module.id)

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.lightbend.paradox.dependencies
import com.lightbend.paradox.markdown.Writer
import com.lightbend.paradox.sbt.ParadoxPlugin
import com.lightbend.paradox.sbt.ParadoxPlugin.autoImport.paradoxDirectives
import net.virtualvoid.sbt.graph.{DependencyGraphKeys, ModuleTree}
import net.virtualvoid.sbt.graph.{DependencyGraphKeys, ModuleGraph}
import sbt._
import sbt.Keys._

Expand Down Expand Up @@ -47,7 +47,8 @@ object ParadoxDependenciesPlugin extends AutoPlugin {
val filter: ScopeFilter = ScopeFilter(projectsToFilter, inConfigurations(Compile))

val projectIdWithTree = Def.task {
(thisProject.value.id, ModuleTree(DependencyGraphKeys.moduleGraphSbt.value))
val sbtGraph = DependencyGraphKeys.moduleGraphSbt.value
(thisProject.value.id, ModuleGraph.apply(sbtGraph.nodes, sbtGraph.edges))
}

projectIdWithTree.all(filter).map(_.toMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package com.lightbend.paradox.dependencies

import net.virtualvoid.sbt.graph.ModuleTree

import net.virtualvoid.sbt.graph.ModuleGraph
import sbt._

trait ParadoxDependenciesPluginKeys {
val paradoxDependenciesProjects = settingKey[Seq[ProjectReference]]("Projects to get the dependency information for")
val paradoxDependenciesShowLicenses =
settingKey[Boolean]("Show the license column (license information is unavailable with sbt 1.3.2)")
val paradoxDependenciesModuleTrees = taskKey[Map[String, ModuleTree]]("Retrieved module trees")
val paradoxDependenciesModuleTrees = taskKey[Map[String, ModuleGraph]]("Retrieved module graph")
}

0 comments on commit ecbf5a9

Please sign in to comment.