Skip to content

Commit

Permalink
Use 'update' instead of ivy resolution
Browse files Browse the repository at this point in the history
Reproduces #87
  • Loading branch information
raboof committed Jul 6, 2024
1 parent 277d267 commit 2146599
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.10.0
4 changes: 1 addition & 3 deletions src/main/scala/sbtlicensereport/SbtLicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ object SbtLicenseReport extends AutoPlugin {
Seq(
licenseReportTitle := s"${normalizedName.value}-licenses",
updateLicenses := {
val ignore = update.value
val overrides = licenseOverrides.value.lift
val depExclusions = licenseDepExclusions.value.lift
val originatingModule = DepModuleInfo(organization.value, name.value, version.value)
license.LicenseReport.makeReport(
ivyModule.value,
IvyDependencyResolution(ivyConfiguration.value),
update.value,
licenseConfigurations.value,
licenseSelection.value,
overrides,
Expand Down
29 changes: 2 additions & 27 deletions src/main/scala/sbtlicensereport/license/LicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,14 @@ object LicenseReport {
}

def makeReport(
module: IvySbt#Module,
depRes: DependencyResolution,
updateReport: UpdateReport,
configs: Set[String],
licenseSelection: Seq[LicenseCategory],
overrides: DepModuleInfo => Option[LicenseInfo],
exclusions: DepModuleInfo => Option[Boolean],
originatingModule: DepModuleInfo,
log: Logger
): LicenseReport = {
// Ideally we should be using just standard sbt update task however due to
// https://github.com/coursier/coursier/issues/1790 coursier cannot correctly
// resolve license information from Ivy modules, so instead we just use
// IvyDependencyResolution directly
val updateReport = resolve(depRes, module, log) match {
case Left(exception) => throw exception.resolveException
case Right(updateReport) => updateReport
}
makeReportImpl(updateReport, configs, licenseSelection, overrides, exclusions, originatingModule, log)
}

Expand Down Expand Up @@ -190,30 +181,14 @@ object LicenseReport {
}
}

// TODO: Use https://github.com/sbt/librarymanagement/pull/428 instead when merged and released
private def moduleKey(m: ModuleID) = (m.organization, m.name, m.revision)

private def allModuleReports(configurations: Vector[ConfigurationReport]): Vector[ModuleReport] =
configurations.flatMap(_.modules).groupBy(mR => moduleKey(mR.module)).toVector map { case (_, v) =>
v reduceLeft { (agg, x) =>
agg.withConfigurations(
(agg.configurations, x.configurations) match {
case (v, _) if v.isEmpty => x.configurations
case (ac, v) if v.isEmpty => ac
case (ac, xc) => ac ++ xc
}
)
}
}

private def getLicenses(
report: UpdateReport,
configs: Set[String] = Set.empty,
categories: Seq[LicenseCategory] = LicenseCategory.all,
originatingModule: DepModuleInfo
): Seq[DepLicense] = {
for {
dep <- allModuleReports(report.configurations)
dep <- report.allModuleReports
report <- pickLicenseForDep(dep, configs, categories, originatingModule)
} yield report
}
Expand Down

0 comments on commit 2146599

Please sign in to comment.