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 6aa9e0e..3bdd72b 100644 --- a/src/main/scala/sbtlicensereport/SbtLicenseReport.scala +++ b/src/main/scala/sbtlicensereport/SbtLicenseReport.scala @@ -1,13 +1,12 @@ package sbtlicensereport import sbt._ -import sbt.librarymanagement.ivy.IvyDependencyResolution import Keys._ 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 { @@ -82,13 +81,13 @@ object SbtLicenseReport extends AutoPlugin { Seq( licenseReportTitle := s"${normalizedName.value}-licenses", updateLicenses := { - val ignore = update.value + 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) 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 f0f318a..4a35c72 100644 --- a/src/main/scala/sbtlicensereport/license/LicenseReport.scala +++ b/src/main/scala/sbtlicensereport/license/LicenseReport.scala @@ -5,13 +5,6 @@ import java.net.URISyntaxException 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}" @@ -119,8 +112,7 @@ object LicenseReport { } def makeReport( - module: IvySbt#Module, - depRes: DependencyResolution, + updateReport: UpdateReport, configs: Set[String], licenseSelection: Seq[LicenseCategory], overrides: DepModuleInfo => Option[LicenseInfo], @@ -128,14 +120,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) } @@ -204,22 +188,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, @@ -228,7 +196,7 @@ object LicenseReport { log: Logger ): Seq[DepLicense] = { for { - dep <- allModuleReports(report.configurations) + dep <- report.allModuleReports report <- pickLicenseForDep(dep, configs, categories, originatingModule, log) } yield report } @@ -253,15 +221,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) - } }