Skip to content

Commit

Permalink
Print license info for licenses where we haven't defined a category yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben McCann committed Feb 25, 2016
1 parent f905fa1 commit 4e476ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object LicenseCategory {
val CDDL = LicenseCategory("CDDL", Seq("Common Development and Distribution"))
val Proprietary = LicenseCategory("Proprietary")
val NoneSpecified = LicenseCategory("none specified")
val Unrecognized = LicenseCategory("unrecognized")

val all: Seq[LicenseCategory] =
Seq(PublicDomain, CommonPublic, CC0, Mozilla, MIT, BSD, Apache, LGPL, GPLClasspath, GPL, EPL, CDDL, Proprietary)
Expand Down
25 changes: 15 additions & 10 deletions src/main/scala/com/typesafe/sbt/license/LicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,24 @@ object LicenseReport {
makeReportImpl(report, configs, licenseSelection, overrides, log)
}
/**
* given a set of categories and an array of ivy-resolved licsenses, pick the first one from our list, or
* given a set of categories and an array of ivy-resolved licenses, pick the first one from our list, or
* default to 'none specified'.
*/
def pickLicense(categories: Seq[LicenseCategory])(licenses: Array[org.apache.ivy.core.module.descriptor.License]): LicenseInfo = {
val allMatchedLicenses =
for {
// We look for a lciense matching the category in the order they are defined.
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
category <- categories.toStream
l <- licenses
if category.unapply(l.getName)
} yield LicenseInfo(category, l.getName, l.getUrl)
allMatchedLicenses.headOption getOrElse LicenseInfo(LicenseCategory.NoneSpecified, "", "")
if (licenses.isEmpty) {
return LicenseInfo(LicenseCategory.NoneSpecified, "", "")
}
// We look for a license matching the category in the order they are defined.
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
for (category <- categories) {
for (license <- licenses) {
if (category.unapply(license.getName)) {
return LicenseInfo(category, license.getName, license.getUrl)
}
}
}
val license = licenses(0)
LicenseInfo(LicenseCategory.Unrecognized, license.getName, license.getUrl)
}
/** Picks a single license (or none) for this dependency. */
def pickLicenseForDep(dep: IvyNode, configs: Set[String], categories: Seq[LicenseCategory]): Option[DepLicense] =
Expand Down
5 changes: 5 additions & 0 deletions src/sbt-test/dumpLicenseReport/default-report/example.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
name := "example"

libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.5.4"
libraryDependencies += "junit" % "junit" % "4.12" % "test"

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"))
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"))
sys.error("Expected report to contain junit with EPL license: " + contents)
// Test whether exclusions are included.
if (contents.contains("scala-library"))
sys.error("Expected report to NOT contain scala-library: " + contents)
Expand Down

0 comments on commit 4e476ea

Please sign in to comment.