Take into account classifiers specified via attributes in Ivy repos

This commit is contained in:
Alexandre Archambault 2017-07-18 10:11:37 +02:00
parent a41c071943
commit 4e5971129b
9 changed files with 109 additions and 9 deletions

View File

@ -73,13 +73,32 @@ final case class IvyRepository(
val retained =
overrideClassifiers match {
case None =>
project.publications.collect {
case (conf, p)
if conf == "*" ||
conf == dependency.configuration ||
project.allConfigurations.getOrElse(dependency.configuration, Set.empty).contains(conf) =>
p
}
// FIXME Some duplication with what's done in MavenSource
if (dependency.attributes.classifier.nonEmpty)
// FIXME We're ignoring dependency.attributes.`type` in this case
project.publications.collect {
case (_, p) if p.classifier == dependency.attributes.classifier =>
p
}
else if (dependency.attributes.`type`.nonEmpty)
project.publications.collect {
case (_, p)
if p.classifier.isEmpty && (
p.`type` == dependency.attributes.`type` ||
(p.ext == dependency.attributes.`type` && project.packagingOpt.toSeq.contains(p.`type`)) // wow
) =>
p
}
else
project.publications.collect {
case (conf, p)
if conf == "*" ||
conf == dependency.configuration ||
project.allConfigurations.getOrElse(dependency.configuration, Set.empty).contains(conf) =>
p
}
case Some(classifiers) =>
val classifiersSet = classifiers.toSet
project.publications.collect {

View File

@ -0,0 +1,3 @@
package a
object A { val value = 42 }

View File

@ -0,0 +1,3 @@
package a
object ATest { val value = 43 }

View File

@ -0,0 +1,3 @@
package b
object B { val value = a.A.value }

View File

@ -0,0 +1,3 @@
package a
object BTest { val value = a.ATest.value }

View File

@ -0,0 +1,22 @@
val org = "io.get-coursier.tests"
val nme = "coursier-test-a"
val ver = "0.1-SNAPSHOT"
lazy val a = project
.settings(
organization := org,
name := nme,
publishArtifact.in(Test) := true,
version := ver
)
lazy val b = project
.settings(
classpathTypes += "test-jar",
libraryDependencies ++= Seq(
org %% nme % ver,
org %% nme % ver % "test" classifier "tests"
)
)

View File

@ -0,0 +1,11 @@
{
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
)
addSbtPlugin("io.get-coursier" % "sbt-coursier" % pluginVersion)
}

View File

@ -0,0 +1,2 @@
> a/publishLocal
> b/test

View File

@ -70,7 +70,7 @@ object IvyTests extends TestSuite {
val mainJarUrl = repoBase + "com.example/a_2.11/0.1.0-SNAPSHOT/jars/a_2.11.jar"
val testJarUrl = repoBase + "com.example/a_2.11/0.1.0-SNAPSHOT/jars/a_2.11-tests.jar"
* - CentralTests.withArtifacts(
"no conf or classifier" - CentralTests.withArtifacts(
dep = dep,
artifactType = "jar",
extraRepos = Seq(repo),
@ -83,7 +83,7 @@ object IvyTests extends TestSuite {
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
}
* - CentralTests.withArtifacts(
"test conf" - CentralTests.withArtifacts(
dep = dep.copy(configuration = "test"),
artifactType = "jar",
extraRepos = Seq(repo),
@ -99,6 +99,40 @@ object IvyTests extends TestSuite {
case other =>
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
}
"tests classifier" - {
val testsDep = dep.copy(attributes = Attributes("jar", "tests"))
* - CentralTests.withArtifacts(
deps = Set(dep, testsDep),
artifactType = "jar",
extraRepos = Seq(repo),
classifierOpt = None,
optional = true
) {
case Seq(artifact1, artifact2) =>
val urls = Set(
artifact1.url,
artifact2.url
)
assert(urls == Set(mainJarUrl, testJarUrl))
case other =>
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
}
* - CentralTests.withArtifacts(
dep = testsDep,
artifactType = "jar",
extraRepos = Seq(repo),
classifierOpt = None,
optional = true
) {
case Seq(artifact) =>
assert(artifact.url == testJarUrl)
case other =>
throw new Exception(s"Unexpected number of artifacts\n${other.mkString("\n")}")
}
}
}
}