Skip to content

Commit 2d71ae0

Browse files
committed
Merge pull request #26 from benmccann/junit-fix
Print license info for licenses where we haven't defined a category yet
2 parents f905fa1 + 4e476ea commit 2d71ae0

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/main/scala/com/typesafe/sbt/license/LicenseCategory.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ object LicenseCategory {
3232
val CDDL = LicenseCategory("CDDL", Seq("Common Development and Distribution"))
3333
val Proprietary = LicenseCategory("Proprietary")
3434
val NoneSpecified = LicenseCategory("none specified")
35+
val Unrecognized = LicenseCategory("unrecognized")
3536

3637
val all: Seq[LicenseCategory] =
3738
Seq(PublicDomain, CommonPublic, CC0, Mozilla, MIT, BSD, Apache, LGPL, GPLClasspath, GPL, EPL, CDDL, Proprietary)

src/main/scala/com/typesafe/sbt/license/LicenseReport.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,24 @@ object LicenseReport {
7575
makeReportImpl(report, configs, licenseSelection, overrides, log)
7676
}
7777
/**
78-
* given a set of categories and an array of ivy-resolved licsenses, pick the first one from our list, or
78+
* given a set of categories and an array of ivy-resolved licenses, pick the first one from our list, or
7979
* default to 'none specified'.
8080
*/
8181
def pickLicense(categories: Seq[LicenseCategory])(licenses: Array[org.apache.ivy.core.module.descriptor.License]): LicenseInfo = {
82-
val allMatchedLicenses =
83-
for {
84-
// We look for a lciense matching the category in the order they are defined.
85-
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
86-
category <- categories.toStream
87-
l <- licenses
88-
if category.unapply(l.getName)
89-
} yield LicenseInfo(category, l.getName, l.getUrl)
90-
allMatchedLicenses.headOption getOrElse LicenseInfo(LicenseCategory.NoneSpecified, "", "")
82+
if (licenses.isEmpty) {
83+
return LicenseInfo(LicenseCategory.NoneSpecified, "", "")
84+
}
85+
// We look for a license matching the category in the order they are defined.
86+
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
87+
for (category <- categories) {
88+
for (license <- licenses) {
89+
if (category.unapply(license.getName)) {
90+
return LicenseInfo(category, license.getName, license.getUrl)
91+
}
92+
}
93+
}
94+
val license = licenses(0)
95+
LicenseInfo(LicenseCategory.Unrecognized, license.getName, license.getUrl)
9196
}
9297
/** Picks a single license (or none) for this dependency. */
9398
def pickLicenseForDep(dep: IvyNode, configs: Set[String], categories: Seq[LicenseCategory]): Option[DepLicense] =

src/sbt-test/dumpLicenseReport/default-report/example.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
name := "example"
22

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

56
excludeDependencies += SbtExclusionRule(organization = "org.scala-lang")
67

78
TaskKey[Unit]("check") := {
89
val contents = sbt.IO.read(target.value / "license-reports" / "example-licenses.md")
910
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"))
1011
sys.error("Expected report to contain jackson-databind with Apache license: " + contents)
12+
if (!contents.contains("jackson-databind"))
13+
sys.error("Expected report to contain jackson-databind: " + contents)
14+
if (!contents.contains("[Eclipse Public License 1.0](http://www.eclipse.org/legal/epl-v10.html) | junit # junit # 4.12"))
15+
sys.error("Expected report to contain junit with EPL license: " + contents)
1116
// Test whether exclusions are included.
1217
if (contents.contains("scala-library"))
1318
sys.error("Expected report to NOT contain scala-library: " + contents)

0 commit comments

Comments
 (0)