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

Hide license column on sbt 1.3.x #17

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")
}