Take into account UpdateConfiguration passed to DependencyResolution

This commit is contained in:
Alexandre Archambault 2020-06-26 14:13:52 +02:00
parent edb1cfa20c
commit e248a43f32
5 changed files with 52 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import dataclass.data
import coursier.cache.CacheDefaults
import lmcoursier.credentials.Credentials
import lmcoursier.definitions.{Authentication, CacheLogger, CachePolicy, FromCoursier, Module, ModuleMatchers, Project, Reconciliation, Strict}
import sbt.librarymanagement.Resolver
import sbt.librarymanagement.{Resolver, UpdateConfiguration}
import xsbti.Logger
import scala.concurrent.duration.Duration
@ -84,6 +84,9 @@ import scala.concurrent.duration.Duration
withTtl(Some(ttl))
def addRepositoryAuthentication(repositoryId: String, authentication: Authentication): CoursierConfiguration =
withAuthenticationByRepositoryId(authenticationByRepositoryId :+ (repositoryId, authentication))
def withUpdateConfiguration(conf: UpdateConfiguration): CoursierConfiguration =
withMissingOk(conf.missingOk)
}
object CoursierConfiguration {

View File

@ -35,6 +35,8 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
log: Logger
): Either[UnresolvedWarning, UpdateReport] = {
val conf = this.conf.withUpdateConfiguration(configuration)
// TODO Take stuff in configuration into account? uwconfig too?
val module0 = module match {

View File

@ -317,7 +317,7 @@ private[internal] object SbtUpdateReport {
)
val reports0 = subRes.rootDependencies match {
case Seq(dep) =>
case Seq(dep) if subRes.projectCache.contains(dep.moduleVersion) =>
// quick hack ensuring the module for the only root dependency
// appears first in the update report, see https://github.com/coursier/coursier/issues/650
val (_, proj) = subRes.projectCache(dep.moduleVersion)

View File

@ -0,0 +1,43 @@
package lmcoursier
import org.scalatest.matchers.should.Matchers
import org.scalatest.propspec.AnyPropSpec
import sbt.librarymanagement.ModuleID
import sbt.librarymanagement.UpdateConfiguration
import sbt.librarymanagement.UnresolvedWarningConfiguration
import sbt.util.Logger
import sbt.librarymanagement.ModuleInfo
import sbt.librarymanagement.ModuleDescriptorConfiguration
import sbt.librarymanagement.Configuration
class CoursierDependencyResolutionTests extends AnyPropSpec with Matchers {
property("missingOk from passed UpdateConfiguration") {
val depRes = CoursierDependencyResolution(CoursierConfiguration().withAutoScalaLibrary(false))
val desc = ModuleDescriptorConfiguration(ModuleID("test", "foo", "1.0"), ModuleInfo("foo"))
.withDependencies(Vector(
ModuleID("io.get-coursier", "coursier_2.13", "0.1.53").withConfigurations(Some("compile")),
ModuleID("org.scala-lang", "scala-library", "2.12.11").withConfigurations(Some("compile"))
))
.withConfigurations(Vector(Configuration.of("Compile", "compile")))
val module = depRes.moduleDescriptor(desc)
val logger: Logger = new Logger {
def log(level: sbt.util.Level.Value, message: => String): Unit =
System.err.println(s"${level.id} $message")
def success(message: => String): Unit =
System.err.println(message)
def trace(t: => Throwable): Unit =
System.err.println(s"trace $t")
}
depRes.update(module, UpdateConfiguration(), UnresolvedWarningConfiguration(), logger)
.fold(w => (), rep => sys.error(s"Expected resolution to fail, got report $rep"))
val report = depRes.update(module, UpdateConfiguration().withMissingOk(true), UnresolvedWarningConfiguration(), logger)
.fold(w => throw w.resolveException, identity)
}
}

View File

@ -201,9 +201,9 @@ object LmCoursierPlugin extends AutoPlugin {
.withIvyHome(ivyPaths.value.ivyHome)
.withStrict(strict)
.withForceVersions(userForceVersions.toVector)
// seems missingOk is false in the updateConfig of updateSbtClassifiers?
.withMissingOk(updateConfig.missingOk || sbtClassifiers)
.withSbtClassifiers(sbtClassifiers)
// seems missingOk is false in the updateConfig of updateSbtClassifiers?
.withUpdateConfiguration(updateConfig.withMissingOk(updateConfig.missingOk || sbtClassifiers))
}
}
private def mkDependencyResolution: Def.Initialize[Task[DependencyResolution]] =