Skip to content

Commit

Permalink
Merge pull request #145 from raboof/invalid-uri-error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Dec 29, 2024
2 parents 2425654 + 0f882e1 commit 2dce5f4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/scala/sbtlicensereport/license/LicenseReport.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sbtlicensereport
package license

import java.net.URISyntaxException

import sbt._
import sbt.io.Using
import sbt.internal.librarymanagement.IvySbt
Expand Down Expand Up @@ -171,7 +173,8 @@ object LicenseReport {
dep: ModuleReport,
configs: Set[String],
categories: Seq[LicenseCategory],
originatingModule: DepModuleInfo
originatingModule: DepModuleInfo,
log: Logger
): Option[DepLicense] = {
val cs = dep.configurations
val filteredConfigs = if (cs.isEmpty) cs else cs.filter(configs.map(ConfigRef.apply))
Expand All @@ -180,7 +183,15 @@ object LicenseReport {
None
else {
val licenses = dep.licenses
val homepage = dep.homepage.map(string => new URI(string).toURL)
val homepage = dep.homepage.flatMap(string => {
try {
Some(new URI(string).toURL)
} catch {
case _: URISyntaxException =>
log.warn(s"sbt-license-report: dependency [${dep.module}] has malformed homepage url [$string]")
None
}
})
Some(
DepLicense(
getModuleInfo(dep),
Expand Down Expand Up @@ -213,11 +224,12 @@ object LicenseReport {
report: UpdateReport,
configs: Set[String] = Set.empty,
categories: Seq[LicenseCategory] = LicenseCategory.all,
originatingModule: DepModuleInfo
originatingModule: DepModuleInfo,
log: Logger
): Seq[DepLicense] = {
for {
dep <- allModuleReports(report.configurations)
report <- pickLicenseForDep(dep, configs, categories, originatingModule)
report <- pickLicenseForDep(dep, configs, categories, originatingModule, log)
} yield report
}

Expand All @@ -230,7 +242,7 @@ object LicenseReport {
originatingModule: DepModuleInfo,
log: Logger
): LicenseReport = {
val licenses = getLicenses(report, configs, categories, originatingModule) filterNot { dep =>
val licenses = getLicenses(report, configs, categories, originatingModule, log) filterNot { dep =>
exclusions(dep.module).getOrElse(false)
} map { l =>
overrides(l.module) match {
Expand Down

0 comments on commit 2dce5f4

Please sign in to comment.