diff --git a/project/build.properties b/project/build.properties index 43b8278..35c88ba 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.11 +sbt.version=0.13.12 diff --git a/src/main/scala/com/typesafe/sbt/SbtLicenseReport.scala b/src/main/scala/com/typesafe/sbt/SbtLicenseReport.scala index b407f94..4211e93 100644 --- a/src/main/scala/com/typesafe/sbt/SbtLicenseReport.scala +++ b/src/main/scala/com/typesafe/sbt/SbtLicenseReport.scala @@ -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 @@ -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.") @@ -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, @@ -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 } diff --git a/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala b/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala index 8b82e94..cd0afcc 100644 --- a/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala +++ b/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala @@ -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) { @@ -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) @@ -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._ diff --git a/src/main/scala/com/typesafe/sbt/license/LicenseReportConfiguration.scala b/src/main/scala/com/typesafe/sbt/license/LicenseReportConfiguration.scala index 04e059b..0bd781d 100644 --- a/src/main/scala/com/typesafe/sbt/license/LicenseReportConfiguration.scala +++ b/src/main/scala/com/typesafe/sbt/license/LicenseReportConfiguration.scala @@ -10,4 +10,5 @@ case class LicenseReportConfiguration( notes: DepModuleInfo => Option[String], licenseFilter: LicenseCategory => Boolean, reportDir: File, - reportStyleRules: Option[String] = None) + reportStyleRules: Option[String] = None +) diff --git a/src/sbt-test/dumpLicenseReport/default-report/example.sbt b/src/sbt-test/dumpLicenseReport/default-report/example.sbt index ca6a650..3d6c073 100644 --- a/src/sbt-test/dumpLicenseReport/default-report/example.sbt +++ b/src/sbt-test/dumpLicenseReport/default-report/example.sbt @@ -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")) diff --git a/test-project/project/build.properties b/test-project/project/build.properties index ea7ce39..35c88ba 100644 --- a/test-project/project/build.properties +++ b/test-project/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.5-RC1 +sbt.version=0.13.12