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.

This commit is contained in:
Dan Sanduleac 2016-02-10 13:14:42 +00:00
parent fcd52ee283
commit 01030a197a
4 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="com.test" module="module-with-srcs" revision="0.1.00" status="release" publication="20160107130136">
<description>
Just a test module that publishes both a binary jar and a src jar in the 'compile' configuration.
</description>
</info>
<configurations>
<conf name="compile" visibility="public" description=""/>
<conf name="runtime" visibility="public" description="" extends="compile"/>
<conf name="test" visibility="public" description="" extends="runtime"/>
<conf name="provided" visibility="public" description=""/>
<conf name="optional" visibility="public" description=""/>
<conf name="default" visibility="public" description="" extends="runtime"/>
<conf name="pom" visibility="public" description=""/>
</configurations>
<publications>
<artifact name="libmodule" type="jar" ext="jar" conf="compile"/>
<artifact name="libmodule-source" type="src" ext="jar" conf="compile"/>
</publications>
<dependencies>
</dependencies>
</ivy-module>

View File

@ -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)
}
}