From 4e5971129b074479891d54302c5980b9a6a08041 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Tue, 18 Jul 2017 10:11:37 +0200 Subject: [PATCH] Take into account classifiers specified via attributes in Ivy repos --- .../scala/coursier/ivy/IvyRepository.scala | 33 ++++++++++++---- .../a/src/main/scala/a/A.scala | 3 ++ .../a/src/test/scala/a/ATest.scala | 3 ++ .../b/src/main/scala/b/B.scala | 3 ++ .../b/src/test/scala/b/BTest.scala | 3 ++ .../sbt-coursier/tests-classifier/build.sbt | 22 +++++++++++ .../tests-classifier/project/plugins.sbt | 11 ++++++ .../sbt-coursier/tests-classifier/test | 2 + .../test/scala/coursier/test/IvyTests.scala | 38 ++++++++++++++++++- 9 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/main/scala/a/A.scala create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/test/scala/a/ATest.scala create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/main/scala/b/B.scala create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/test/scala/b/BTest.scala create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/build.sbt create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/project/plugins.sbt create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/test diff --git a/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala b/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala index eea6fadc2..16c426ff8 100644 --- a/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala +++ b/core/shared/src/main/scala/coursier/ivy/IvyRepository.scala @@ -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 { diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/main/scala/a/A.scala b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/main/scala/a/A.scala new file mode 100644 index 000000000..fb97bc543 --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/main/scala/a/A.scala @@ -0,0 +1,3 @@ +package a + +object A { val value = 42 } diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/test/scala/a/ATest.scala b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/test/scala/a/ATest.scala new file mode 100644 index 000000000..c752e81d6 --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/a/src/test/scala/a/ATest.scala @@ -0,0 +1,3 @@ +package a + +object ATest { val value = 43 } diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/main/scala/b/B.scala b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/main/scala/b/B.scala new file mode 100644 index 000000000..504fea13e --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/main/scala/b/B.scala @@ -0,0 +1,3 @@ +package b + +object B { val value = a.A.value } diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/test/scala/b/BTest.scala b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/test/scala/b/BTest.scala new file mode 100644 index 000000000..a9f43cb9a --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/b/src/test/scala/b/BTest.scala @@ -0,0 +1,3 @@ +package a + +object BTest { val value = a.ATest.value } diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/build.sbt b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/build.sbt new file mode 100644 index 000000000..5941723c2 --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/build.sbt @@ -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" + ) + ) + diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/project/plugins.sbt b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/project/plugins.sbt new file mode 100644 index 000000000..152225a9e --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/project/plugins.sbt @@ -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) +} diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/test b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/test new file mode 100644 index 000000000..9e133c736 --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/tests-classifier/test @@ -0,0 +1,2 @@ +> a/publishLocal +> b/test diff --git a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala index 01f679bf0..4f526e466 100644 --- a/tests/jvm/src/test/scala/coursier/test/IvyTests.scala +++ b/tests/jvm/src/test/scala/coursier/test/IvyTests.scala @@ -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")}") + } + } } }