diff --git a/src/main/scala/sbtlicensereport/license/LicenseReport.scala b/src/main/scala/sbtlicensereport/license/LicenseReport.scala index afc691a..ca6e1a3 100644 --- a/src/main/scala/sbtlicensereport/license/LicenseReport.scala +++ b/src/main/scala/sbtlicensereport/license/LicenseReport.scala @@ -147,20 +147,23 @@ object LicenseReport { // Even though the url is optional this field seems to always exist val licensesWithUrls = licenses.collect { case (name, Some(url)) => (name, url) } if (licensesWithUrls.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 <- licensesWithUrls) { - val (name, url) = license - if (category.unapply(name)) { - return LicenseInfo(category, name, url) + LicenseInfo(LicenseCategory.NoneSpecified, "", "") + } else { + // 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) + categories + .flatMap(category => + licensesWithUrls.collectFirst { + case (name, url) if category.unapply(name) => + LicenseInfo(category, name, url) + } + ) + .headOption + .getOrElse { + val license = licensesWithUrls(0) + LicenseInfo(LicenseCategory.Unrecognized, license._1, license._2) } - } } - val license = licensesWithUrls(0) - LicenseInfo(LicenseCategory.Unrecognized, license._1, license._2) } /** Picks a single license (or none) for this dependency. */