Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sbt-dependency-graph 0.10.0-RC1 #19

Merged
merged 5 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
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} // .graph.{ModuleTree, ModuleTreeNode}
francisdb marked this conversation as resolved.
Show resolved Hide resolved
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}
francisdb marked this conversation as resolved.
Show resolved Hide resolved
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")
}