-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: make sbt-license-report more fault tolerance with ivy unresolv…
…ed dependencies (#803) Signed-off-by: Pat Losoponkul <[email protected]>
- Loading branch information
patlo-iog
authored
Dec 4, 2023
1 parent
c49c813
commit f1b4904
Showing
5 changed files
with
108 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import sbt.Logger | ||
import sbt.librarymanagement._ | ||
import sbt.librarymanagement.ivy._ | ||
import sbt.internal.librarymanagement.{IvySbt, IvyRetrieve} | ||
|
||
// Since ivy fails to resolve project dependencies, customized version is used to ignore any failure. | ||
// This is OK as we only grab license information from the resolution metadata, | ||
// and the faing dependencies are only used in 'Test' configuration. | ||
// This should be used until 'sbt-license-report' plugin use coursier to populate licenses. | ||
// | ||
// https://github.com/sbt/sbt-license-report/issues/47 | ||
// https://github.com/sbt/sbt-license-report/issues/87 | ||
class LicenseReportCustomDependencyResolution(ivyConfiguration: IvyConfiguration, ivyModule: IvySbt#Module) | ||
extends DependencyResolutionInterface { | ||
|
||
private val ivyResolution = IvyDependencyResolution(ivyConfiguration) | ||
private val dummyFile = java.io.File.createTempFile("sbt-license-report", "") | ||
|
||
override def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): ModuleDescriptor = | ||
ivyResolution.moduleDescriptor(moduleSetting) | ||
|
||
// Resolve using low-level ivy directly to skip sbt-wrapped ivy failing the resolution and discard the UpdateReport. | ||
// https://github.com/sbt/sbt-license-report/blob/5a8cb0b6567789bd8867e709b0cad8bb93aca50f/src/main/scala/sbtlicensereport/license/LicenseReport.scala#L221 | ||
override def update( | ||
module: ModuleDescriptor, | ||
configuration: UpdateConfiguration, | ||
uwconfig: UnresolvedWarningConfiguration, | ||
log: Logger | ||
): Either[UnresolvedWarning, UpdateReport] = { | ||
val (resolveReport, err) = ivyModule.withModule(Logger.Null) { (ivy, desc, default) => | ||
import org.apache.ivy.core.resolve.ResolveOptions | ||
val resolveOptions = new ResolveOptions | ||
val resolveId = ResolveOptions.getDefaultResolveId(desc) | ||
resolveOptions.setResolveId(resolveId) | ||
import org.apache.ivy.core.LogOptions.LOG_QUIET | ||
resolveOptions.setLog(LOG_QUIET) | ||
val resolveReport = ivy.resolve(desc, resolveOptions) | ||
val err = | ||
if (resolveReport.hasError) { | ||
val messages = resolveReport.getAllProblemMessages.toArray.map(_.toString).distinct | ||
val failed = resolveReport.getUnresolvedDependencies.map(node => IvyRetrieve.toModuleID(node.getId)) | ||
Some(new ResolveException(messages, failed)) | ||
} else None | ||
(resolveReport, err) | ||
} | ||
|
||
err.foreach { resolveException => | ||
log.warn(":::::::::::::::::::::::::::::::::::::::::::::::::::") | ||
log.warn(":: LicenseReport Unresolved Dependencies ::") | ||
log.warn(":::::::::::::::::::::::::::::::::::::::::::::::::::") | ||
resolveException | ||
.failed | ||
.map(_.toString()) | ||
.distinct | ||
.sorted | ||
.foreach { module => log.warn(s":: $module") } | ||
log.warn(":::::::::::::::::::::::::::::::::::::::::::::::::::") | ||
} | ||
|
||
val updateReport = IvyRetrieve.updateReport(resolveReport, dummyFile) | ||
Right(updateReport) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Using unreleased plugin from 'main' which accepts DependencyResolution interface for building license report. | ||
lazy val sbtLicenseReportPlugin = ProjectRef(uri("https://github.com/sbt/sbt-license-report.git#9675cedb19c794de1119cbcf46a255fc8dcd5d4e"), "sbt-license-report") | ||
|
||
lazy val root = (project in file(".")).dependsOn(sbtLicenseReportPlugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters