Back to a simpler artifact model in resolver

This commit is contained in:
Alexandre Archambault 2015-06-25 00:18:46 +01:00
parent de3b704731
commit e6ec32f33a
9 changed files with 28 additions and 75 deletions

View File

@ -98,17 +98,13 @@ case class Coursier(scope: List[String],
}
def repr(dep: Dependency) = {
val (type0, classifier) = dep.artifacts match {
case maven: Artifacts.Maven => (maven.`type`, maven.classifier)
}
// dep.version can be an interval, whereas the one from project can't
val version = res.projectsCache.get(dep.moduleVersion).map(_._2.version).getOrElse(dep.version)
val extra =
if (version == dep.version) ""
else s" ($version for ${dep.version})"
s"${dep.module.organization}:${dep.module.name}:$type0:${Some(classifier).filter(_.nonEmpty).map(_+":").mkString}$version$extra"
s"${dep.module.organization}:${dep.module.name}:${dep.artifact.`type`}:${Some(dep.artifact.classifier).filter(_.nonEmpty).map(_+":").mkString}$version$extra"
}
val trDeps = res.dependencies.toList.sortBy(repr)

View File

@ -21,7 +21,7 @@ case class ArtifactDownloader(root: String, cache: File, logger: Option[Artifact
def artifact(module: Module,
version: String,
artifact: Artifacts.Artifact,
artifact: Dependency.MavenArtifact,
cachePolicy: CachePolicy): EitherT[Task, String, File] = {
val relPath =
@ -95,19 +95,8 @@ case class ArtifactDownloader(root: String, cache: File, logger: Option[Artifact
project: Project,
cachePolicy: CachePolicy = CachePolicy.Default): Task[Seq[String \/ File]] = {
val artifacts0 =
dependency.artifacts match {
case s: Artifacts.Sufficient => s.artifacts
case p: Artifacts.WithProject => p.artifacts(project)
}
val tasks =
artifacts0 .map { artifact0 =>
// Important: using version from project, as the one from dependency can be an interval
artifact(dependency.module, project.version, artifact0, cachePolicy = cachePolicy).run
}
Task.gatherUnordered(tasks)
// Important: using version from project, as the one from dependency can be an interval
artifact(dependency.module, project.version, dependency.artifact, cachePolicy = cachePolicy).run.map(Seq(_))
}
}

View File

@ -32,34 +32,15 @@ sealed abstract class Scope(val name: String)
case class Dependency(module: Module,
version: String,
scope: Scope,
artifacts: Artifacts,
artifact: Dependency.MavenArtifact,
exclusions: Set[(String, String)],
optional: Boolean) {
def moduleVersion = (module, version)
}
sealed trait Artifacts
object Artifacts {
/**
* May become a bit more complicated with Ivy support,
* but should still point at one single artifact.
*/
case class Artifact(`type`: String,
classifier: String)
sealed trait WithProject extends Artifacts {
def artifacts(project: Project): Seq[Artifact]
}
sealed trait Sufficient extends Artifacts {
def artifacts: Seq[Artifact]
}
case class Maven(`type`: String,
classifier: String) extends Sufficient {
def artifacts: Seq[Artifact] = Seq(Artifact(`type`, classifier))
}
object Dependency {
case class MavenArtifact(`type`: String,
classifier: String)
}
case class Project(module: Module,

View File

@ -70,9 +70,7 @@ object Resolver {
type DepMgmtKey = (String, String, String)
def dependencyManagementKey(dep: Dependency): DepMgmtKey =
dep.artifacts match {
case Artifacts.Maven(type0, _) => (dep.module.organization, dep.module.name, type0)
}
(dep.module.organization, dep.module.name, dep.artifact.`type`)
def dependencyManagementAdd(m: Map[DepMgmtKey, Dependency], dep: Dependency): Map[DepMgmtKey, Dependency] = {
val key = dependencyManagementKey(dep)
if (m.contains(key)) m else m + (key -> dep)
@ -121,13 +119,10 @@ object Resolver {
name = substituteProps(dep.module.name)
),
version = substituteProps(dep.version),
artifacts = dep.artifacts match {
case maven: Artifacts.Maven =>
maven.copy(
`type` = substituteProps(maven.`type`),
classifier = substituteProps(maven.classifier)
)
},
artifact = dep.artifact.copy(
`type` = substituteProps(dep.artifact.`type`),
classifier = substituteProps(dep.artifact.classifier)
),
scope = Parse.scope(substituteProps(dep.scope.name)),
exclusions = dep.exclusions
.map{case (org, name) => (substituteProps(org), substituteProps(name))}

View File

@ -85,7 +85,7 @@ object Xml {
mod,
version0,
scopeOpt getOrElse defaultScope,
Artifacts.Maven(typeOpt getOrElse defaultType, classifierOpt getOrElse defaultClassifier),
Dependency.MavenArtifact(typeOpt getOrElse defaultType, classifierOpt getOrElse defaultClassifier),
exclusions.map(mod => (mod.organization, mod.name)).toSet,
optional
)

View File

@ -1,6 +1,9 @@
import scalaz.EitherT
import scalaz.concurrent.Task
/**
* Pulls definitions from coursier.core, with default arguments.
*/
package object coursier {
type Dependency = core.Dependency
@ -8,19 +11,16 @@ package object coursier {
def apply(module: Module,
version: String,
scope: Scope = Scope.Other(""), // Substituted by Resolver with its own default scope (compile)
artifacts: Artifacts = Artifacts.Maven(),
artifact: MavenArtifact = MavenArtifact(),
exclusions: Set[(String, String)] = Set.empty,
optional: Boolean = false): Dependency =
core.Dependency(module, version, scope, artifacts, exclusions, optional)
}
core.Dependency(module, version, scope, artifact, exclusions, optional)
type Artifacts = core.Artifacts
object Artifacts {
type Maven = core.Artifacts.Maven
object Maven {
type MavenArtifact = core.Dependency.MavenArtifact
object MavenArtifact {
def apply(`type`: String = "jar",
classifier: String = ""): Maven =
core.Artifacts.Maven(`type`, classifier)
classifier: String = ""): MavenArtifact =
core.Dependency.MavenArtifact(`type`, classifier)
}
}

View File

@ -12,12 +12,8 @@ object CentralTests extends TestSuite {
repository.mavenCentral
)
def repr(dep: Dependency) = {
val (type0, classifier) = dep.artifacts match {
case maven: Artifacts.Maven => (maven.`type`, maven.classifier)
}
s"${dep.module.organization}:${dep.module.name}:$type0:${Some(classifier).filter(_.nonEmpty).map(_+":").mkString}${dep.version}"
}
def repr(dep: Dependency) =
s"${dep.module.organization}:${dep.module.name}:${dep.artifact.`type`}:${Some(dep.artifact.classifier).filter(_.nonEmpty).map(_+":").mkString}${dep.version}"
def resolutionCheck(module: Module, version: String) =
async {

View File

@ -21,7 +21,7 @@ object PomParsingTests extends TestSuite {
</dependency>
"""
val expected = \/-(Dependency(Module("comp", "lib"), "2.1", artifacts = Artifacts.Maven(classifier = "extra")))
val expected = \/-(Dependency(Module("comp", "lib"), "2.1", artifact = Dependency.MavenArtifact(classifier = "extra")))
val result = Xml.dependency(xmlParse(depNode).right.get)

View File

@ -218,10 +218,6 @@ object App {
)
def depItem(dep: Dependency, finalVersionOpt: Option[String]) = {
val (type0, classifier) = dep.artifacts match {
case maven: Artifacts.Maven => (maven.`type`, maven.classifier)
}
<.tr(
^.`class` := (if (res.errors.contains(dep.moduleVersion)) "danger" else ""),
<.td(dep.module.organization),
@ -229,8 +225,8 @@ object App {
<.td(finalVersionOpt.fold(dep.version)(finalVersion => s"$finalVersion (for ${dep.version})")),
<.td(Seq[Seq[TagMod]](
if (dep.scope == Scope.Compile) Seq() else Seq(infoLabel(dep.scope.name)),
if (type0.isEmpty || type0 == "jar") Seq() else Seq(infoLabel(type0)),
if (classifier.isEmpty) Seq() else Seq(infoLabel(classifier)),
if (dep.artifact.`type`.isEmpty || dep.artifact.`type` == "jar") Seq() else Seq(infoLabel(dep.artifact.`type`)),
if (dep.artifact.classifier.isEmpty) Seq() else Seq(infoLabel(dep.artifact.classifier)),
Some(dep.exclusions).filter(_.nonEmpty).map(excls => infoPopOver("Exclusions", excls.toList.sorted.map{case (org, name) => s"$org:$name"}.mkString("; "))).toSeq,
if (dep.optional) Seq(infoLabel("optional")) else Seq(),
res.errors.get(dep.moduleVersion).map(errs => errorPopOver("Error", errs.mkString("; "))).toSeq