Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'update' instead of ivy resolution #143

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 3 additions & 4 deletions src/main/scala/sbtlicensereport/SbtLicenseReport.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sbtlicensereport

import sbt._
import sbt.librarymanagement.ivy.IvyDependencyResolution
import Keys._
import license._

Expand Down Expand Up @@ -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,
Expand Down
51 changes: 4 additions & 47 deletions src/main/scala/sbtlicensereport/license/LicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -117,23 +110,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 @@ -193,30 +177,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,
configs: Set[String],
categories: Seq[LicenseCategory],
originatingModule: DepModuleInfo
): Seq[DepLicense] = {
for {
dep <- allModuleReports(report.configurations)
dep <- report.allModuleReports
report <- pickLicenseForDep(dep, configs, categories, originatingModule)
} yield report
}
Expand All @@ -241,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)
}
}