From 01030a197a53f3ebb4eca43a01c2d7a23b8ecd5f Mon Sep 17 00:00:00 2001 From: Dan Sanduleac Date: Wed, 10 Feb 2016 13:14:42 +0000 Subject: [PATCH] Add IvyRepoSpec which tests that source artifacts (in this case, with type=src, though in the same "compile" configuration) are resolved correctly when using IvyActions.updateClassifiers, and NOT resolved when using the normal IvyActions.updateEither. --- .../module-with-srcs/0.1.00/ivys/ivy.xml | 23 +++++ .../0.1.00/jars/libmodule.jar | Bin 0 -> 341 bytes .../0.1.00/srcs/libmodule-source.jar | Bin 0 -> 341 bytes .../librarymanagement/IvyRepoSpec.scala | 89 ++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100755 librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/ivys/ivy.xml create mode 100644 librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/jars/libmodule.jar create mode 100644 librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/srcs/libmodule-source.jar create mode 100644 librarymanagement/src/test/scala/sbt/internal/librarymanagement/IvyRepoSpec.scala diff --git a/librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/ivys/ivy.xml b/librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/ivys/ivy.xml new file mode 100755 index 000000000..ab045d5cb --- /dev/null +++ b/librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/ivys/ivy.xml @@ -0,0 +1,23 @@ + + + + + Just a test module that publishes both a binary jar and a src jar in the 'compile' configuration. + + + + + + + + + + + + + + + + + + diff --git a/librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/jars/libmodule.jar b/librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/jars/libmodule.jar new file mode 100644 index 0000000000000000000000000000000000000000..b21d53c7baf1086d25cdb54e4fe86d41ed542b27 GIT binary patch literal 341 zcmWIWW@Zs#;Nak3xD)E-!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1gx0>v$BCyF#%yMkUj+BFaQAZm_uOz literal 0 HcmV?d00001 diff --git a/librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/srcs/libmodule-source.jar b/librarymanagement/src/test/resources/test-ivy-repo/com.test/module-with-srcs/0.1.00/srcs/libmodule-source.jar new file mode 100644 index 0000000000000000000000000000000000000000..b21d53c7baf1086d25cdb54e4fe86d41ed542b27 GIT binary patch literal 341 zcmWIWW@Zs#;Nak3xD)E-!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1gx0>v$BCyF#%yMkUj+BFaQAZm_uOz literal 0 HcmV?d00001 diff --git a/librarymanagement/src/test/scala/sbt/internal/librarymanagement/IvyRepoSpec.scala b/librarymanagement/src/test/scala/sbt/internal/librarymanagement/IvyRepoSpec.scala new file mode 100644 index 000000000..9e15fbc01 --- /dev/null +++ b/librarymanagement/src/test/scala/sbt/internal/librarymanagement/IvyRepoSpec.scala @@ -0,0 +1,89 @@ +package sbt.internal.librarymanagement + +import org.scalatest.Inside +import sbt.internal.librarymanagement.impl.DependencyBuilders +import sbt.librarymanagement._ + +class IvyRepoSpec extends BaseIvySpecification with DependencyBuilders { + + val ourModuleID = ModuleID("com.example", "foo", "0.1.0", Some("compile")) + + def makeModuleForDepWithSources = { + // By default a module seems to only have [compile, test, runtime], yet deps automatically map to + // default->compile(default) ... so I guess we have to explicitly use e.g. "compile" + val dep = "com.test" % "module-with-srcs" % "0.1.00" % "compile" + + module( + ourModuleID, + Seq(dep), None //, UpdateOptions().withCachedResolution(true) + ) + } + + "ivyUpdate from ivy repository" should "resolve only binary artifact from module which also contains a sources artifact under the same configuration." in { + cleanIvyCache() + + val m = makeModuleForDepWithSources + + val report = ivyUpdate(m) + + import Inside._ + inside(report.configuration("compile").map(_.modules)) { + case Some(Seq(mr)) => + inside(mr.artifacts) { + case Seq((ar, _)) => + ar.`type` shouldBe "jar" + ar.extension shouldBe "jar" + } + } + } + + it should "resolve only sources artifact of an acceptable artifact type, \"src\", when calling updateClassifiers." in { + cleanIvyCache() + + val m = makeModuleForDepWithSources + + // the "default" configuration used in updateEither. + val c = makeUpdateConfiguration + + val ivyScala = m.moduleSettings.ivyScala + val srcTypes = Set("src") + val docTypes = Set("javadoc") + // These will be the default classifiers that SBT should try, in case a dependency is Maven. + // In this case though, they will be tried and should fail gracefully - only the + val attemptedClassifiers = Seq("sources", "javadoc") + + // The dep that we want to get the "classifiers" (i.e. sources / docs) for. + // We know it has only one source artifact in the "compile" configuration. + val dep = "com.test" % "module-with-srcs" % "0.1.00" % "compile" + + val clMod = { + import language.implicitConversions + implicit val key = (m: ModuleID) => (m.organization, m.name, m.revision) + val externalModules = Seq(dep) + // Note: need to extract ourModuleID so we can plug it in here, can't fish it back out of the IvySbt#Module (`m`) + GetClassifiersModule(ourModuleID, externalModules, Seq(Configurations.Compile), attemptedClassifiers) + } + + val gcm = GetClassifiersConfiguration(clMod, Map.empty, c.copy(artifactFilter = c.artifactFilter.invert), ivyScala, srcTypes, docTypes) + + val report2 = IvyActions.updateClassifiers(m.owner, gcm, UnresolvedWarningConfiguration(), LogicalClock.unknown, None, Vector(), log) + + import Inside._ + inside(report2.configuration("compile").map(_.modules)) { + case Some(Seq(mr)) => + inside(mr.artifacts) { + case Seq((ar, _)) => + ar.name shouldBe "libmodule-source" + ar.`type` shouldBe "src" + ar.extension shouldBe "jar" + } + } + } + + override lazy val resolvers: Seq[Resolver] = Seq(testIvy) + + lazy val testIvy = { + val repoUrl = getClass.getResource("/test-ivy-repo") + Resolver.url("Test Repo", repoUrl)(Resolver.ivyStylePatterns) + } +}