diff --git a/src/main/scala/com/typesafe/sbt/license/LicenseCategory.scala b/src/main/scala/com/typesafe/sbt/license/LicenseCategory.scala index c0621e3..a3a16e8 100644 --- a/src/main/scala/com/typesafe/sbt/license/LicenseCategory.scala +++ b/src/main/scala/com/typesafe/sbt/license/LicenseCategory.scala @@ -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) diff --git a/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala b/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala index 6032640..5249145 100644 --- a/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala +++ b/src/main/scala/com/typesafe/sbt/license/LicenseReport.scala @@ -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] = diff --git a/src/sbt-test/dumpLicenseReport/default-report/example.sbt b/src/sbt-test/dumpLicenseReport/default-report/example.sbt index 2b2eafe..ca6a650 100644 --- a/src/sbt-test/dumpLicenseReport/default-report/example.sbt +++ b/src/sbt-test/dumpLicenseReport/default-report/example.sbt @@ -1,6 +1,7 @@ name := "example" libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.5.4" +libraryDependencies += "junit" % "junit" % "4.12" % "test" excludeDependencies += SbtExclusionRule(organization = "org.scala-lang") @@ -8,6 +9,10 @@ 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)