From 2146599e056977977154b20ae87d88c72b1ff343 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 3 Jul 2024 01:18:22 +0200 Subject: [PATCH 1/4] Use 'update' instead of ivy resolution Reproduces #87 --- project/build.properties | 2 +- .../sbtlicensereport/SbtLicenseReport.scala | 4 +-- .../license/LicenseReport.scala | 29 ++----------------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/project/build.properties b/project/build.properties index 04267b1..081fdbb 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.9 +sbt.version=1.10.0 diff --git a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala index 921af29..9c5ca68 100644 --- a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala +++ b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala @@ -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, diff --git a/src/main/scala/sbtlicensereport/license/LicenseReport.scala b/src/main/scala/sbtlicensereport/license/LicenseReport.scala index afc691a..deb73c2 100644 --- a/src/main/scala/sbtlicensereport/license/LicenseReport.scala +++ b/src/main/scala/sbtlicensereport/license/LicenseReport.scala @@ -117,8 +117,7 @@ object LicenseReport { } def makeReport( - module: IvySbt#Module, - depRes: DependencyResolution, + updateReport: UpdateReport, configs: Set[String], licenseSelection: Seq[LicenseCategory], overrides: DepModuleInfo => Option[LicenseInfo], @@ -126,14 +125,6 @@ object LicenseReport { 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) } @@ -190,22 +181,6 @@ 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, @@ -213,7 +188,7 @@ object LicenseReport { originatingModule: DepModuleInfo ): Seq[DepLicense] = { for { - dep <- allModuleReports(report.configurations) + dep <- report.allModuleReports report <- pickLicenseForDep(dep, configs, categories, originatingModule) } yield report } From 78eb0860a29266b8903de10b4308b0c7183af83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Sur=C3=A9e?= Date: Wed, 6 Nov 2024 15:05:35 +0100 Subject: [PATCH 2/4] Remove unused code --- .../sbtlicensereport/SbtLicenseReport.scala | 1 - .../license/LicenseReport.scala | 22 ++----------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala index 56c205f..be01b49 100644 --- a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala +++ b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala @@ -1,7 +1,6 @@ package sbtlicensereport import sbt._ -import sbt.librarymanagement.ivy.IvyDependencyResolution import Keys._ import license._ diff --git a/src/main/scala/sbtlicensereport/license/LicenseReport.scala b/src/main/scala/sbtlicensereport/license/LicenseReport.scala index 74fffa5..ca7716c 100644 --- a/src/main/scala/sbtlicensereport/license/LicenseReport.scala +++ b/src/main/scala/sbtlicensereport/license/LicenseReport.scala @@ -3,13 +3,6 @@ package license import sbt._ import sbt.io.Using -import sbt.internal.librarymanagement.IvySbt -import sbt.librarymanagement.{ - DependencyResolution, - UnresolvedWarning, - UnresolvedWarningConfiguration, - UpdateConfiguration -} case class DepModuleInfo(organization: String, name: String, version: String) { override def toString = s"${organization} # ${name} # ${version}" @@ -186,8 +179,8 @@ object LicenseReport { private def getLicenses( report: UpdateReport, - configs: Set[String] = Set.empty, - categories: Seq[LicenseCategory] = LicenseCategory.all, + configs: Set[String], + categories: Seq[LicenseCategory], originatingModule: DepModuleInfo ): Seq[DepLicense] = { for { @@ -216,15 +209,4 @@ object LicenseReport { // TODO - Filter for a real report... LicenseReport(licenses, report) } - - private def resolve( - depRes: DependencyResolution, - module: IvySbt#Module, - log: Logger - ): Either[UnresolvedWarning, UpdateReport] = { - val uc = UpdateConfiguration().withLogging(UpdateLogging.Quiet) - val uwc = UnresolvedWarningConfiguration() - - depRes.update(module, uc, uwc, log) - } } From 8029aa6a9d8dc054b1ee7f5c13b72ff4f4c71fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Sur=C3=A9e?= Date: Wed, 13 Nov 2024 18:09:34 +0100 Subject: [PATCH 3/4] Check sbt version --- README.md | 2 +- src/main/scala/sbtlicensereport/SbtLicenseReport.scala | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ee7fed..abd608c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # sbt-license-report -This plugin will allow you to report the licenses used in your projects. It requires 1.0.0+. +This plugin will allow you to report the licenses used in your projects. It requires 1.10.5+. ## Installation diff --git a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala index be01b49..d01fb3f 100644 --- a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala +++ b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala @@ -81,6 +81,8 @@ object SbtLicenseReport extends AutoPlugin { Seq( licenseReportTitle := s"${normalizedName.value}-licenses", updateLicenses := { + if (VersionNumber(sbtVersion.value).matchesSemVer(SemanticSelector("<1.10.5"))) + throw new sbt.MessageOnlyException("sbt-license-report requires sbt 1.10.5 or greater.") val overrides = licenseOverrides.value.lift val depExclusions = licenseDepExclusions.value.lift val originatingModule = DepModuleInfo(organization.value, name.value, version.value) From a25227e0021b98f577b058edb5b8c58afb81da25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Sur=C3=A9e?= Date: Fri, 15 Nov 2024 16:24:21 +0100 Subject: [PATCH 4/4] Remove IvyPlugin from requires --- src/main/scala/sbtlicensereport/SbtLicenseReport.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala index d01fb3f..3bdd72b 100644 --- a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala +++ b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala @@ -6,7 +6,7 @@ import license._ /** A plugin which enables reporting on licensing used within a project. */ object SbtLicenseReport extends AutoPlugin { - override def requires: Plugins = plugins.IvyPlugin + override def requires: Plugins = empty override def trigger = allRequirements object autoImportImpl {