Skip to content

Commit 2f2b65e

Browse files
authored
Hide license column on sbt 1.3.x (#17)
1 parent 2bd8a8f commit 2f2b65e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/main/scala/com/lightbend/paradox/dependencies/DependenciesDirective.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ import net.virtualvoid.sbt.graph.{ModuleTree, ModuleTreeNode}
2121
import org.pegdown.Printer
2222
import org.pegdown.ast.{DirectiveNode, Visitor}
2323

24-
class DependenciesDirective(projectIdToDependencies: String => ModuleTree) extends LeafBlockDirective("dependencies") {
24+
class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: String => ModuleTree)
25+
extends LeafBlockDirective("dependencies") {
2526
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
2627
val projectId = node.attributes.value("projectId")
2728
val tree = projectIdToDependencies(projectId)
2829
printer.println()
2930
val classes = Seq("dependencies", node.attributes.classesString).filter(_.nonEmpty)
3031
printer.print(s"""<dl class="${classes.mkString(" ")}">""")
3132
if (tree.roots.flatMap(_.children).nonEmpty) {
32-
renderDirect(node, tree.roots, printer)
33+
renderDirect(node, tree.roots, showLicenses, printer)
3334
renderTree(node, tree.roots, printer)
3435
} else {
3536
printer.print("<dt>Direct dependencies</dt><dd>This module has no dependencies.</dd>")
@@ -38,10 +39,12 @@ class DependenciesDirective(projectIdToDependencies: String => ModuleTree) exten
3839
printer.println()
3940
}
4041

41-
private def renderDirect(node: DirectiveNode, roots: Seq[ModuleTreeNode], p: Printer): Unit = {
42+
private def renderDirect(node: DirectiveNode, roots: Seq[ModuleTreeNode], showLicenses: Boolean, p: Printer): Unit = {
4243
p.print("<dt>Direct dependencies</dt><dd><table>")
4344
p.indent(2).println()
44-
p.print("<thead><tr><th>Organization</th><th>Artifact</th><th>Version</th><th>License</th></tr></thead>").println()
45+
p.print("<thead><tr><th>Organization</th><th>Artifact</th><th>Version</th>")
46+
if (showLicenses) p.print("<th>License</th></tr>")
47+
p.print("</thead>").println()
4548
p.print("<tbody>")
4649
p.indent(2)
4750
for {
@@ -61,7 +64,7 @@ class DependenciesDirective(projectIdToDependencies: String => ModuleTree) exten
6164
)
6265
.print(moduleId.version)
6366
.print("</a></td>")
64-
d.node.license.foreach(l => p.print("<td>").print(l).print("</td>"))
67+
if (showLicenses) d.node.license.foreach(l => p.print("<td>").print(l).print("</td>"))
6568
p.print("</tr>")
6669
}
6770
p.indent(-2).println()

src/main/scala/com/lightbend/paradox/dependencies/ParadoxDependenciesPlugin.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ object ParadoxDependenciesPlugin extends AutoPlugin {
3434
override def projectSettings: Seq[Setting[_]] = dependenciesSettings(Compile)
3535

3636
def dependenciesZeroSettings: Seq[Setting[_]] = Seq(
37+
paradoxDependenciesShowLicenses := {
38+
sbtVersion.value.startsWith("1.1.") || sbtVersion.value.startsWith("1.2.")
39+
},
3740
paradoxDependenciesModuleTrees := Def.taskDyn {
3841
val projectsToFilter = paradoxDependenciesProjects.?.value
3942
.map(inProjects)
@@ -54,7 +57,7 @@ object ParadoxDependenciesPlugin extends AutoPlugin {
5457
val trees = paradoxDependenciesModuleTrees.value
5558
Seq(
5659
{ _: Writer.Context
57-
new DependenciesDirective(projectId => {
60+
new DependenciesDirective(paradoxDependenciesShowLicenses.value)(projectId => {
5861
trees.get(projectId) match {
5962
case Some(deps) => deps
6063
case _ => throw new Error(s"Could not retrieve dependency information for project [$projectId]")

src/main/scala/com/lightbend/paradox/dependencies/ParadoxDependenciesPluginKeys.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import net.virtualvoid.sbt.graph.ModuleTree
2121
import sbt._
2222

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

0 commit comments

Comments
 (0)