Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions src/main/scala/sbtlicensereport/SbtLicenseReport.scala
Original file line number Diff line number Diff line change
@@ -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 {
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
47 changes: 2 additions & 45 deletions src/main/scala/sbtlicensereport/license/LicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -119,23 +112,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 @@ -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,
Expand All @@ -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
}
Expand All @@ -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)
}
}
Loading