Skip to content

Commit

Permalink
sbt-license-report-31 Add a link to the homepage of a dependency.
Browse files Browse the repository at this point in the history
- bumped sbt version to 0.13.12
- implemented sbt#31 as described
  • Loading branch information
NicolasRouquette committed Aug 28, 2016
1 parent c1289a8 commit e18f18b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.11
sbt.version=0.13.12
12 changes: 5 additions & 7 deletions src/main/scala/com/typesafe/sbt/SbtLicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import sbt._
import Keys._
import license._



/** A plugin which enables reporting on licensing used within a project. */
object SbtLicenseReport extends AutoPlugin {
override def requires: Plugins = plugins.IvyPlugin
override def trigger = allRequirements

object autoImportImpl {
// Types and objects to auto-expose
type LicenseCategory = com.typesafe.sbt.license.LicenseCategory
Expand All @@ -21,7 +19,7 @@ object SbtLicenseReport extends AutoPlugin {
def Html = com.typesafe.sbt.license.Html
def MarkDown = com.typesafe.sbt.license.MarkDown
def Csv = com.typesafe.sbt.license.Csv

// Keys
val updateLicenses = taskKey[LicenseReport]("Construct a report of used licenses in a project.")
val licenseReportConfigurations = taskKey[Seq[LicenseReportConfiguration]]("Configuration for each license report we're generating.")
Expand All @@ -40,7 +38,7 @@ object SbtLicenseReport extends AutoPlugin {
// Workaround for broken autoImport in sbt 0.13.5
val autoImport = autoImportImpl
import autoImport._

override def projectSettings: Seq[Setting[_]] =
Seq(
licenseSelection := LicenseCategory.all,
Expand Down Expand Up @@ -73,8 +71,8 @@ object SbtLicenseReport extends AutoPlugin {
dumpLicenseReport := {
val report = updateLicenses.value
val dir = licenseReportDir.value
for(config <- licenseReportConfigurations.value)
LicenseReport.dumpLicenseReport(report, config)
for (config <- licenseReportConfigurations.value)
LicenseReport.dumpLicenseReport(report, config)
dir
}

Expand Down
20 changes: 15 additions & 5 deletions src/main/scala/com/typesafe/sbt/license/LicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ package license
import sbt._
import org.apache.ivy.core.report.ResolveReport
import org.apache.ivy.core.resolve.IvyNode
import scala.util.control.Exception._

case class DepModuleInfo(organization: String, name: String, version: String) {
override def toString = s"${organization} # ${name} # ${version}"
}
case class DepLicense(module: DepModuleInfo, license: LicenseInfo, configs: Set[String]) {
override def toString = s"$module on $license in ${configs.mkString("(", ",", ")")}"
case class DepLicense(module: DepModuleInfo, license: LicenseInfo, homepage: Option[URL], configs: Set[String]) {
override def toString = s"$module ${homepage.map(url => s" from $url")} on $license in ${configs.mkString("(", ",", ")")}"
}

case class LicenseReport(licenses: Seq[DepLicense], orig: ResolveReport) {
Expand Down Expand Up @@ -52,11 +53,16 @@ object LicenseReport {
print(language.tableHeader("Category", "License", "Dependency", "Notes"))
for (dep <- ordered) {
val licenseLink = language.createHyperLink(dep.license.url, dep.license.name)
val moduleLink = dep.homepage match {
case None => dep.module.toString
case Some(url) => language.createHyperLink(url.toExternalForm, dep.module.toString)
}
print(language.tableRow(
dep.license.category.name,
licenseLink,
dep.module.toString,
notes(dep.module) getOrElse ""))
moduleLink,
notes(dep.module) getOrElse ""
))
}
print(language.tableEnd)
print(language.documentEnd)
Expand Down Expand Up @@ -103,8 +109,12 @@ object LicenseReport {
if !filteredConfigs.forall(d.isEvicted)
desc <- Option(dep.getDescriptor)
licenses = Option(desc.getLicenses).filterNot(_.isEmpty).getOrElse(Array(new org.apache.ivy.core.module.descriptor.License("none specified", "none specified")))
homepage = Option.apply(desc.getHomePage).flatMap(loc =>
nonFatalCatch[Option[URL]]
.withApply((_: Throwable) => Option.empty[URL])
.apply(Some(url(loc))))
// TODO - grab configurations.
} yield DepLicense(getModuleInfo(dep), pickLicense(categories)(licenses), filteredConfigs)
} yield DepLicense(getModuleInfo(dep), pickLicense(categories)(licenses), homepage, filteredConfigs)

def getLicenses(report: ResolveReport, configs: Set[String] = Set.empty, categories: Seq[LicenseCategory] = LicenseCategory.all): Seq[DepLicense] = {
import collection.JavaConverters._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ case class LicenseReportConfiguration(
notes: DepModuleInfo => Option[String],
licenseFilter: LicenseCategory => Boolean,
reportDir: File,
reportStyleRules: Option[String] = None)
reportStyleRules: Option[String] = None
)
4 changes: 2 additions & 2 deletions src/sbt-test/dumpLicenseReport/default-report/example.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ excludeDependencies += SbtExclusionRule(organization = "org.scala-lang")

TaskKey[Unit]("check") := {
val contents = sbt.IO.read(target.value / "license-reports" / "example-licenses.md")
if (!contents.contains("[The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) | com.fasterxml.jackson.core # jackson-databind # 2.5.4"))
if (!contents.contains("[The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) | [com.fasterxml.jackson.core # jackson-core # 2.5.4](https://github.com/FasterXML/jackson)"))
sys.error("Expected report to contain jackson-databind with Apache license: " + contents)
if (!contents.contains("jackson-databind"))
sys.error("Expected report to contain jackson-databind: " + contents)
if (!contents.contains("[Eclipse Public License 1.0](http://www.eclipse.org/legal/epl-v10.html) | junit # junit # 4.12"))
if (!contents.contains("[Eclipse Public License 1.0](http://www.eclipse.org/legal/epl-v10.html) | [junit # junit # 4.12](http://junit.org)"))
sys.error("Expected report to contain junit with EPL license: " + contents)
// Test whether exclusions are included.
if (contents.contains("scala-library"))
Expand Down
2 changes: 1 addition & 1 deletion test-project/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.5-RC1
sbt.version=0.13.12

0 comments on commit e18f18b

Please sign in to comment.