mirror of https://github.com/sbt/sbt.git
Get dependency / artifact matching straight from coursier
Rather than matching them after-the-fact in a fragile way.
This commit is contained in:
parent
ecd84e2b83
commit
597a4c014a
|
|
@ -12,6 +12,8 @@ import lmcoursier.internal.{ArtifactsParams, ArtifactsRun, CoursierModuleDescrip
|
|||
import sbt.internal.librarymanagement.IvySbt
|
||||
import sbt.librarymanagement._
|
||||
import sbt.util.Logger
|
||||
import coursier.core.Dependency
|
||||
import coursier.core.Publication
|
||||
|
||||
class CoursierDependencyResolution(conf: CoursierConfiguration) extends DependencyResolutionInterface {
|
||||
|
||||
|
|
@ -191,12 +193,13 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
|||
|
||||
def updateParams(
|
||||
resolutions: Map[Set[Configuration], Resolution],
|
||||
artifacts: Map[Artifact, File]
|
||||
artifacts: Seq[(Dependency, Publication, Artifact, Option[File])]
|
||||
) =
|
||||
UpdateParams(
|
||||
thisModule = (ToCoursier.module(mod), ver),
|
||||
shadedConfigOpt = None,
|
||||
artifacts = artifacts,
|
||||
artifacts = artifacts.collect { case (d, p, a, Some(f)) => a -> f }.toMap,
|
||||
fullArtifacts = Some(artifacts.map { case (d, p, a, f) => (d, p, a) -> f }.toMap),
|
||||
classifiers = classifiers,
|
||||
configs = configs,
|
||||
dependencies = dependencies,
|
||||
|
|
@ -210,7 +213,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
|||
val e = for {
|
||||
resolutions <- ResolutionRun.resolutions(resolutionParams, verbosityLevel, log)
|
||||
artifactsParams0 = artifactsParams(resolutions)
|
||||
artifacts <- ArtifactsRun.artifacts(artifactsParams0, verbosityLevel, log)
|
||||
artifacts <- ArtifactsRun.artifactsResult(artifactsParams0, verbosityLevel, log)
|
||||
} yield {
|
||||
val updateParams0 = updateParams(resolutions, artifacts)
|
||||
UpdateRun.update(updateParams0, verbosityLevel, log)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import coursier.cache.loggers.{FallbackRefreshDisplay, ProgressBarRefreshDisplay
|
|||
import coursier.core.Type
|
||||
import coursier.util.Artifact
|
||||
import sbt.util.Logger
|
||||
import coursier.core.Dependency
|
||||
import coursier.core.Publication
|
||||
|
||||
// private[coursier]
|
||||
object ArtifactsRun {
|
||||
|
|
@ -16,6 +18,13 @@ object ArtifactsRun {
|
|||
verbosityLevel: Int,
|
||||
log: Logger
|
||||
): Either[coursier.error.FetchError, Map[Artifact, File]] =
|
||||
artifactsResult(params, verbosityLevel, log).map(_.collect { case (_, _, a, Some(f)) => (a, f) }.toMap)
|
||||
|
||||
def artifactsResult(
|
||||
params: ArtifactsParams,
|
||||
verbosityLevel: Int,
|
||||
log: Logger
|
||||
): Either[coursier.error.FetchError, Seq[(Dependency, Publication, Artifact, Option[File])]] =
|
||||
// let's update only one module at once, for a better output
|
||||
// Downloads are already parallel, no need to parallelize further anyway
|
||||
Lock.lock.synchronized {
|
||||
|
|
@ -64,8 +73,8 @@ object ArtifactsRun {
|
|||
}
|
||||
)
|
||||
)
|
||||
.either()
|
||||
.map(_.toMap)
|
||||
.eitherResult()
|
||||
.map(_.fullDetailedArtifacts) // FIXME Misses extraArtifacts, that we don't use for now though
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,19 +137,41 @@ private[internal] object SbtUpdateReport {
|
|||
interProjectDependencies: Seq[Project],
|
||||
classifiersOpt: Option[Seq[Classifier]],
|
||||
artifactFileOpt: (Module, String, Attributes, Artifact) => Option[File],
|
||||
fullArtifactsOpt: Option[Map[(Dependency, Publication, Artifact), Option[File]]],
|
||||
log: Logger,
|
||||
keepPomArtifact: Boolean = false,
|
||||
includeSignatures: Boolean = false,
|
||||
classpathOrder: Boolean,
|
||||
): Vector[ModuleReport] = {
|
||||
val depArtifacts1 = res.dependencyArtifacts(classifiersOpt, classpathOrder)
|
||||
|
||||
val deps = classifiersOpt match {
|
||||
case Some(classifiers) =>
|
||||
res.dependencyArtifacts(Some(classifiers.toSeq), classpathOrder)
|
||||
case None =>
|
||||
res.dependencyArtifacts(None, classpathOrder)
|
||||
}
|
||||
|
||||
val depArtifacts1 = fullArtifactsOpt match {
|
||||
case Some(map) =>
|
||||
deps.map {
|
||||
case (d, p, a) =>
|
||||
val d0 = d.withAttributes(d.attributes.withClassifier(p.classifier))
|
||||
val f = map.get((d0, p, a)).flatten
|
||||
(d, p, a, f) // not d0
|
||||
}
|
||||
case None =>
|
||||
deps.map {
|
||||
case (d, p, a) =>
|
||||
(d, p, a, None)
|
||||
}
|
||||
}
|
||||
|
||||
val depArtifacts0 =
|
||||
if (keepPomArtifact)
|
||||
depArtifacts1
|
||||
else
|
||||
depArtifacts1.filter {
|
||||
case (_, pub, _) => pub.attributes != Attributes(Type.pom, Classifier.empty)
|
||||
case (_, pub, _, _) => pub.attributes != Attributes(Type.pom, Classifier.empty)
|
||||
}
|
||||
|
||||
val depArtifacts =
|
||||
|
|
@ -159,16 +181,16 @@ private[internal] object SbtUpdateReport {
|
|||
|
||||
if (notFound.isEmpty)
|
||||
depArtifacts0.flatMap {
|
||||
case (dep, pub, a) =>
|
||||
case (dep, pub, a, f) =>
|
||||
val sigPub = pub
|
||||
// not too sure about those
|
||||
.withExt(Extension(pub.ext.value))
|
||||
.withType(Type(pub.`type`.value))
|
||||
Seq((dep, pub, a)) ++
|
||||
a.extra.get("sig").toSeq.map((dep, sigPub, _))
|
||||
Seq((dep, pub, a, f)) ++
|
||||
a.extra.get("sig").toSeq.map((dep, sigPub, _, None))
|
||||
}
|
||||
else {
|
||||
for ((_, _, a) <- notFound)
|
||||
for ((_, _, a, _) <- notFound)
|
||||
log.error(s"No signature found for ${a.url}")
|
||||
sys.error(s"${notFound.length} signature(s) not found")
|
||||
}
|
||||
|
|
@ -178,7 +200,7 @@ private[internal] object SbtUpdateReport {
|
|||
val groupedDepArtifacts = {
|
||||
val m = depArtifacts.groupBy(_._1)
|
||||
val fromLib = depArtifacts.map(_._1).distinct.map { dep =>
|
||||
dep -> m.getOrElse(dep, Nil).map { case (_, pub, a) => (pub, a) }
|
||||
dep -> m.getOrElse(dep, Nil).map { case (_, pub, a, f) => (pub, a, f) }
|
||||
}
|
||||
val fromInterProj = interProjectDependencies
|
||||
.filter(p => p.module != thisModule._1)
|
||||
|
|
@ -249,11 +271,19 @@ private[internal] object SbtUpdateReport {
|
|||
Vector.empty
|
||||
}
|
||||
}
|
||||
val filesOpt = artifacts.map {
|
||||
case (pub, a, fileOpt) =>
|
||||
val fileOpt0 = fileOpt.orElse {
|
||||
if (fullArtifactsOpt.isEmpty) artifactFileOpt(proj.module, proj.version, pub.attributes, a)
|
||||
else None
|
||||
}
|
||||
(pub, a, fileOpt0)
|
||||
}
|
||||
moduleReport((
|
||||
dep,
|
||||
dependees,
|
||||
proj,
|
||||
artifacts.map { case (pub, a) => (pub, a, artifactFileOpt(proj.module, proj.version, pub.attributes, a)) }
|
||||
filesOpt
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
@ -266,6 +296,7 @@ private[internal] object SbtUpdateReport {
|
|||
configs: Map[Configuration, Set[Configuration]],
|
||||
classifiersOpt: Option[Seq[Classifier]],
|
||||
artifactFileOpt: (Module, String, Attributes, Artifact) => Option[File],
|
||||
fullArtifactsOpt: Option[Map[(Dependency, Publication, Artifact), Option[File]]],
|
||||
log: Logger,
|
||||
keepPomArtifact: Boolean = false,
|
||||
includeSignatures: Boolean = false,
|
||||
|
|
@ -288,6 +319,7 @@ private[internal] object SbtUpdateReport {
|
|||
interProjectDependencies,
|
||||
classifiersOpt,
|
||||
artifactFileOpt,
|
||||
fullArtifactsOpt,
|
||||
log,
|
||||
keepPomArtifact = keepPomArtifact,
|
||||
includeSignatures = includeSignatures,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ final case class UpdateParams(
|
|||
thisModule: (Module, String),
|
||||
shadedConfigOpt: Option[(String, Configuration)],
|
||||
artifacts: Map[Artifact, File],
|
||||
fullArtifacts: Option[Map[(Dependency, Publication, Artifact), Option[File]]],
|
||||
classifiers: Option[Seq[Classifier]],
|
||||
configs: Map[Configuration, Set[Configuration]],
|
||||
dependencies: Seq[(Configuration, Dependency)],
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ object UpdateRun {
|
|||
params.configs,
|
||||
params.classifiers,
|
||||
params.artifactFileOpt,
|
||||
params.fullArtifacts,
|
||||
log,
|
||||
includeSignatures = params.includeSignatures,
|
||||
classpathOrder = params.classpathOrder,
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ object UpdateTasks {
|
|||
(p.module, p.version),
|
||||
shadedConfigOpt,
|
||||
artifactFilesOrErrors0,
|
||||
None,
|
||||
classifiers,
|
||||
configs,
|
||||
dependencies,
|
||||
|
|
|
|||
Loading…
Reference in New Issue