Skip to content

Commit

Permalink
Hide license column on sbt 1.3.x (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ennru authored Oct 8, 2019
1 parent 2bd8a8f commit 2f2b65e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import net.virtualvoid.sbt.graph.{ModuleTree, ModuleTreeNode}
import org.pegdown.Printer
import org.pegdown.ast.{DirectiveNode, Visitor}

class DependenciesDirective(projectIdToDependencies: String => ModuleTree) extends LeafBlockDirective("dependencies") {
class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: String => ModuleTree)
extends LeafBlockDirective("dependencies") {
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
val projectId = node.attributes.value("projectId")
val tree = 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, printer)
renderDirect(node, tree.roots, showLicenses, printer)
renderTree(node, tree.roots, printer)
} else {
printer.print("<dt>Direct dependencies</dt><dd>This module has no dependencies.</dd>")
Expand All @@ -38,10 +39,12 @@ class DependenciesDirective(projectIdToDependencies: String => ModuleTree) exten
printer.println()
}

private def renderDirect(node: DirectiveNode, roots: Seq[ModuleTreeNode], p: Printer): Unit = {
private def renderDirect(node: DirectiveNode, roots: Seq[ModuleTreeNode], 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><th>License</th></tr></thead>").println()
p.print("<thead><tr><th>Organization</th><th>Artifact</th><th>Version</th>")
if (showLicenses) p.print("<th>License</th></tr>")
p.print("</thead>").println()
p.print("<tbody>")
p.indent(2)
for {
Expand All @@ -61,7 +64,7 @@ class DependenciesDirective(projectIdToDependencies: String => ModuleTree) exten
)
.print(moduleId.version)
.print("</a></td>")
d.node.license.foreach(l => p.print("<td>").print(l).print("</td>"))
if (showLicenses) d.node.license.foreach(l => p.print("<td>").print(l).print("</td>"))
p.print("</tr>")
}
p.indent(-2).println()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ object ParadoxDependenciesPlugin extends AutoPlugin {
override def projectSettings: Seq[Setting[_]] = dependenciesSettings(Compile)

def dependenciesZeroSettings: Seq[Setting[_]] = Seq(
paradoxDependenciesShowLicenses := {
sbtVersion.value.startsWith("1.1.") || sbtVersion.value.startsWith("1.2.")
},
paradoxDependenciesModuleTrees := Def.taskDyn {
val projectsToFilter = paradoxDependenciesProjects.?.value
.map(inProjects)
Expand All @@ -54,7 +57,7 @@ object ParadoxDependenciesPlugin extends AutoPlugin {
val trees = paradoxDependenciesModuleTrees.value
Seq(
{ _: Writer.Context
new DependenciesDirective(projectId => {
new DependenciesDirective(paradoxDependenciesShowLicenses.value)(projectId => {
trees.get(projectId) match {
case Some(deps) => deps
case _ => throw new Error(s"Could not retrieve dependency information for project [$projectId]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import net.virtualvoid.sbt.graph.ModuleTree
import sbt._

trait ParadoxDependenciesPluginKeys {
val paradoxDependenciesProjects = settingKey[Seq[ProjectReference]]("Projects to get the dependency information for")
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")
}

0 comments on commit 2f2b65e

Please sign in to comment.