continuing work on dependency-management tests

This commit is contained in:
Mark Harrah 2011-04-15 19:52:45 -04:00
parent a15bd90309
commit 6715ab5917
32 changed files with 195 additions and 198 deletions

View File

@ -5,18 +5,19 @@ object ArtifactTest extends Build
{
lazy val projects = Seq(root)
lazy val root = Project("root", file(".")) settings(
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t))),
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))),
publishTo := Some(Resolver.file("Test Publish Repo", file("test-repo"))),
resolvers <<= (resolvers, publishTo)(_ ++ _.toList),
jarName in Compile := ArtifactName(base := artifactID, version = vers, tpe = classifier, ext = ext, cross = "", config = ""),
projectID := (if(retrieve) retrieveID else publishedID),
artifacts := artifact :: Nil
libraryDependencies ++= (if(retrieve) publishedID :: Nil else Nil),
// needed to add a jar with a different extension to the classpath
classpathFilter := "*." + ext,
check <<= checkTask
projectID <<= baseDirectory { base => (if(base / "retrieve" exists) retrieveID else publishedID) },
artifact in (Compile, packageBin) := mainArtifact,
libraryDependencies <<= (libraryDependencies, baseDirectory) { (deps, base) => deps ++ (if(base / "retrieve" exists) publishedID :: Nil else Nil) },
// needed to add a jar with a different type to the managed classpath
classpathTypes := Set(tpe),
check <<= checkTask(dependencyClasspath),
checkFull <<= checkTask(fullClasspath)
)
lazy val checkFull = TaskKey[Unit]("check-full")
lazy val check = TaskKey[Unit]("check")
// define strings for defining the artifact
@ -27,16 +28,16 @@ object ArtifactTest extends Build
def vers = "1.1"
def org = "test"
def artifact = Artifact(artifactID, tpe, ext, classifier)
def mainArtifact = Artifact(artifactID, tpe, ext, classifier)
// define the IDs to use for publishing and retrieving
def publishedID = org % artifactID % vers artifacts(artifact)
def publishedID = org % artifactID % vers artifacts(mainArtifact)
def retrieveID = org % "test-retrieve" % "2.0"
// check that the test class is on the compile classpath, either because it was compiled or because it was properly retrieved
def checkTask = (fullClasspath in Compile, scalaInstance) map { (cp, si) =>
val loader = classpath.ClasspathUtilities.toLoader(cp.files, si.loader)
try { Class.forName("test.Test", false, loader) }
def checkTask(classpath: TaskKey[Classpath]) = (classpath in Compile, scalaInstance) map { (cp, si) =>
val loader = sbt.classpath.ClasspathUtilities.toLoader(cp.files, si.loader)
try { Class.forName("test.Test", false, loader); () }
catch { case _: ClassNotFoundException | _: NoClassDefFoundError => error("Dependency not retrieved properly") }
}
}

View File

@ -1,13 +1,11 @@
# verify that check fails when test class is not present
-> check
# compile and jar test class
> package
# verify that check succeeds
> check
# verify that check-full succeeds
> check-full
# publish test jar to test repository
>publish
> publish
# delete test jar and verify check fails again
> clean
@ -15,6 +13,7 @@
# tell project definition to switch to retrieve mode
$ touch retrieve
> reload
# verify that artifact with extension, type, and classifier can be retreieved
> update
> check

View File

@ -0,0 +1,3 @@
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache")))
libraryDependencies += "org.testng" % "testng" % "5.7" classifier "jdk15"

View File

@ -1,2 +0,0 @@
project.name=Test Classifier
project.version=1.0

View File

@ -1,7 +0,0 @@
import sbt._
class Test(info: ProjectInfo) extends DefaultProject(info)
{
override def ivyCacheDirectory = Some(outputPath / "ivy-cache")
val testng = "org.testng" % "testng" % "5.7" classifier "jdk15"
}

View File

@ -0,0 +1,10 @@
// the default, but make it explicit
publishMavenStyle := true
publishTo <<= baseDirectory(bd => Some( Resolver.file("test-repo", bd / "repo") ) )
name := "test"
organization := "org.example"
version := "1.0"

View File

@ -0,0 +1,11 @@
publishMavenStyle := false
publishTo <<= baseDirectory { base =>
Some( Resolver.file("test-repo", base / "repo")(Patterns(false, Resolver.mavenStyleBasePattern)) )
}
name := "test-ivy"
organization := "org.example"
version := "1.0"

View File

@ -1,7 +0,0 @@
import sbt._
class TestPublish(info: ProjectInfo) extends DefaultProject(info)
{
override def managedStyle = ManagedStyle.Ivy
val publishTo = Resolver.file("test-repo", path("repo").asFile)(Patterns(false, Resolver.mavenStyleBasePattern))
}

View File

@ -0,0 +1,17 @@
publishMavenStyle := false
resolvers <<= baseDirectory { base =>
Resolver.file("test-repo", base / "repo")(Patterns(false, Resolver.mavenStyleBasePattern)) :: Nil
}
libraryDependencies ++= Seq(
"org.example" %% "test-ivy" % "1.0",
"org.example" %% "test-ivy" % "1.0" % "test",
"org.example" %% "test-ivy" % "1.0" % "runtime"
)
name := "test-ivy-use"
organization := "test"
version := "1.0"

View File

@ -1,11 +0,0 @@
import sbt._
class TestUse(info: ProjectInfo) extends DefaultProject(info)
{
override def managedStyle = ManagedStyle.Ivy
val testLocal = Resolver.file("test-repo", path("repo").asFile)(Patterns(false, Resolver.mavenStyleBasePattern))
val mavenC = "org.example" %% "test-ivy" % "1.0"
val mavenT = "org.example" %% "test-ivy" % "1.0" % "test"
val mavenR = "org.example" %% "test-ivy" % "1.0" % "runtime"
}

View File

@ -0,0 +1,15 @@
resolvers <<= baseDirectory { base =>
Resolver.file("test-repo", base / "repo") :: Nil
}
libraryDependencies ++= Seq(
"org.example" %% "test" % "1.0",
"org.example" %% "test" % "1.0" % "test",
"org.example" %% "test" % "1.0" % "runtime"
)
name := "test-use"
organization := "test"
version := "1.0"

View File

@ -1,10 +0,0 @@
import sbt._
class TestUse(info: ProjectInfo) extends DefaultProject(info)
{
val testLocal = Resolver.file("test-repo", path("repo").asFile)
val mavenC = "org.example" %% "test" % "1.0"
val mavenT = "org.example" %% "test" % "1.0" % "test"
val mavenR = "org.example" %% "test" % "1.0" % "runtime"
}

View File

@ -1,3 +0,0 @@
project.name=test
project.organization=org.example
project.version=1.0

View File

@ -1,7 +0,0 @@
import sbt._
class TestPublish(info: ProjectInfo) extends DefaultProject(info)
{
override def managedStyle = ManagedStyle.Maven // the default, but make it explicit
val publishTo = Resolver.file("test-repo", path("repo").asFile)
}

View File

@ -1,43 +1,30 @@
# publish a jar with Published with managedStyle = ManagedStyle.Maven
# publish a jar with Published with publishManagedStyle = true
$ copy-file changes/maven/Published.scala src/main/scala/Published.scala
> publish
# get and compile against each published jar with managedStyle = ManagedStyle.Maven
# get and compile against each published jar with publishManagedStyle = true
> set project.name test-use
> set project.organization test
$ delete src project/build lib_managed
$ copy-file changes/maven/TestUse.scala project/build/TestUse.scala
$ delete src build.sbt target
$ copy-file changes/maven/TestUse.sbt build.sbt
> reload
$ copy-file changes/maven/Use.scala src/main/scala/Use.scala
-> compile
> update
> compile
# publish a jar with PublishedIvy with managedStyle = ManagedStyle.Ivy
> set project.name test-ivy
> set project.organization org.example
$ delete src project/build lib_managed repo
$ copy-file changes/ivy/TestPublish.scala project/build/TestPublish.scala
# publish a jar with PublishedIvy with publishManagedStyle = false
$ delete src build.sbt target repo
$ copy-file changes/ivy/TestPublish.sbt build.sbt
> reload
$ copy-file changes/ivy/Published.scala src/main/scala/Published.scala
> publish
# get and compile against each published jar with managedStyle = ManagedStyle.Ivy
# get and compile against each published jar with publishManagedStyle = false
> set project.name test-ivy-use
> set project.organization test
$ delete src project/build lib_managed
$ copy-file changes/ivy/TestUse.scala project/build/TestUse.scala
$ delete src build.sbt target
$ copy-file changes/ivy/TestUse.sbt build.sbt
> reload
$ copy-file changes/ivy/Use.scala src/main/scala/Use.scala
-> compile
> update
> compile

View File

@ -0,0 +1,28 @@
import sbt._
import Keys._
object TestProject extends Build
{
lazy val projects = Seq(root)
lazy val root = Project("root", file(".")) settings(
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))),
libraryDependencies += transitive("javax.mail" % "mail" % "1.4.1"),
TaskKey("check-transitive") <<= check(true),
TaskKey("check-intransitive") <<= check(false)
)
def transitive(dep: ModuleID) =
{
println("transitive(" + dep + ") = " + file("transitive").exists)
if(file("transitive").exists) dep else dep.intransitive()
}
private def check(transitive: Boolean) =
(dependencyClasspath in Compile) map { downloaded =>
val jars = downloaded.size
if(transitive)
if(jars <= 1) error("Transitive dependencies not downloaded")
else
if(jars > 1) error("Transitive dependencies downloaded (" + downloaded.files.mkString(", ") + ")")
}
}

View File

@ -1,2 +0,0 @@
project.name=Exclude Transitive
project.version=1.0

View File

@ -1,26 +0,0 @@
import sbt._
class TestProject(info: ProjectInfo) extends DefaultProject(info)
{
def transitive(dep: ModuleID) = if("transitive".asFile.exists) dep else dep.intransitive()
val javaMail = transitive("javax.mail" % "mail" % "1.4.1")
lazy val checkTransitive = task { check(true) }
lazy val checkIntransitive = task { check(false) }
private def check(transitive: Boolean) =
{
val downloaded = compileClasspath.get
val jars = downloaded.size
if(transitive)
{
if(jars > 1) None
else Some("Transitive dependencies not downloaded")
}
else
{
if(jars == 1) None
else Some("Transitive dependencies downloaded (" + downloaded.mkString(", ") + ")")
}
}
}

View File

@ -1,10 +1,10 @@
# load the project definition with transitive dependencies enabled
# and check that they are not downloaded
$ pause
$ touch transitive
$ pause
> reload
> update
$ pause
> check-transitive
-> check-intransitive
@ -17,7 +17,5 @@ $ delete ivy-cache
$ delete transitive
> reload
> update
-> check-transitive
> check-intransitive

View File

@ -0,0 +1,15 @@
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache")))
publishMavenStyle := false
publishTo <<= baseDirectory { base =>
Some(Resolver.file("test-repo", base / "repo" / "test")(Resolver.defaultIvyPatterns))
}
projectID <<= projectID { _.extra("e:color" -> "red") }
organization := "org.scala-tools.sbt"
version := "1.0"
name := "define-color"

View File

@ -0,0 +1,17 @@
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache")) )
publishMavenStyle := false
resolvers <<= baseDirectory( base =>
Resolver.file("test-repo", base / "repo" / "test")(Resolver.defaultIvyPatterns) :: Nil
)
libraryDependencies <<= baseDirectory { base =>
val color = IO.read(base / "color")
val dep = "org.scala-tools.sbt" %% "define-color" % "1.0" extra("e:color" -> color)
dep :: Nil
}
organization := "org.example"
name := "use-color"

View File

@ -1,13 +0,0 @@
import sbt._
class UseColor(info: ProjectInfo) extends DefaultProject(info)
{
override def ivyCacheDirectory = Some(outputPath / "ivy-cache")
override def managedStyle = ManagedStyle.Ivy
val repo = Resolver.file("test-repo", ("repo" / "test").asFile)
def color = FileUtilities.readString("color".asFile, log).right.getOrElse(error("No color specified"))
override def libraryDependencies = Set(
"org.scala-tools.sbt" %% "test-ivy-extra" %"1.0" extra("e:color" -> color)
)
}

View File

@ -1,3 +0,0 @@
project.name=test-ivy-extra
project.version=1.0
project.organization=org.scala-tools.sbt

View File

@ -1,10 +0,0 @@
import sbt._
class DefineColor(info: ProjectInfo) extends DefaultProject(info)
{
override def ivyCacheDirectory = Some(outputPath / "ivy-cache")
override def managedStyle = ManagedStyle.Ivy
val publishTo = Resolver.file("test-repo", ("repo" / "test").asFile)
override def projectID = super.projectID extra("e:color" -> "red")
}

View File

@ -1,12 +1,12 @@
> publish
> set project.name UseColor
$ delete project/build/
$ copy-file changes/UseColor.scala project/build/UseColor.scala
$ delete DefineColor.sbt
$ copy-file changes/UseColor.sbt UseColor.sbt
$ copy-file changes/blue color
> reload
-> update
$ copy-file changes/red color
> reload
> update

View File

@ -0,0 +1,40 @@
import sbt._
import Keys._
import scala.xml._
object InfoTest extends Build
{
lazy val projects = Seq(root)
lazy val root = Project("root", file(".")) settings(
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))),
ivyXML <<= (baseDirectory, organization, moduleID) apply inlineXML,
TaskKey("check-download") <<= checkDownload,
delivered <<= deliverLocal map XML.loadFile,
TaskKey("check-info") <<= checkInfo
)
lazy val delivered = TaskKey[NodeSeq]("delivered")
def inlineXML(baseDirectory: File, organization: String, moduleID: String): NodeSeq =
if(baseDirectory / "info" exists)
(<info organisation={organization} module={moduleID} revision="1.0">
<license name="Two-clause BSD-style" url="http://github.com/szeiger/scala-query/blob/master/LICENSE.txt" />
<description homepage="http://github.com/szeiger/scala-query/">
ScalaQuery is a type-safe database query API for Scala.
</description>
</info>
<dependency org="org.scalacheck" name="scalacheck" rev="1.5"/>)
else
<dependency org="org.scalacheck" name="scalacheck" rev="1.5"/>
def customInfo = file("info").exists
def checkDownload = (dependencyClasspath in Compile) map { cp => if(cp.isEmpty) error("Dependency not downloaded") }
def checkInfo = delivered map { d =>
if((d \ "info").isEmpty)
error("No info tag generated")
else if(customInfo)
if( !deliveredWithCustom(d) ) error("Expected 'license' and 'description' tags in info tag, got: \n" + (d \ "info"))
else
if( deliveredWithCustom(d) ) error("Expected empty 'info' tag, got: \n" + (d \ "info"))
}
def deliveredWithCustom(d: NodeSeq) = !(d \ "info" \ "license").isEmpty && !(d \ "info" \ "description").isEmpty
}

View File

@ -1,3 +0,0 @@
project.name=test
project.org=test
project.version=1.0

View File

@ -1,34 +0,0 @@
import sbt._
class InfoTest(info: ProjectInfo) extends DefaultProject(info)
{
override def ivyCacheDirectory = Some(outputPath / "ivy-cache")
override def ivyXML =
if(customInfo)
(<info organisation={organization} module={moduleID} revision="1.0">
<license name="Two-clause BSD-style" url="http://github.com/szeiger/scala-query/blob/master/LICENSE.txt" />
<description homepage="http://github.com/szeiger/scala-query/">
ScalaQuery is a type-safe database query API for Scala.
</description>
</info>
<dependency org="org.scalacheck" name="scalacheck" rev="1.5"/>)
else
<dependency org="org.scalacheck" name="scalacheck" rev="1.5"/>
def customInfo = "info".asFile.exists
lazy val checkDownload = task { if(compileClasspath.get.isEmpty) Some("Dependency not downloaded") else None }
lazy val checkInfo = task {
if((delivered \ "info").isEmpty)
Some("No info tag generated")
else if(customInfo)
if( deliveredWithCustom ) None else Some("Expected 'license' and 'description' tags in info tag, got: \n" + (delivered \ "info"))
else
if( deliveredWithCustom ) Some("Expected empty 'info' tag, got: \n" + (delivered \ "info")) else None
}
def deliveredWithCustom = !(delivered \ "info" \ "license").isEmpty && !(delivered \ "info" \ "description").isEmpty
def delivered = scala.xml.XML.loadFile(ivyFile)
def ivyFile = (outputPath * "ivy*.xml").get.toList.head.asFile
}

View File

@ -1,13 +1,9 @@
> update
> check-download
> deliver-local
> check-info
> clean
> clean-lib
$ touch info
> reload
> update
> check-download
> deliver-local
> check-info

View File

@ -0,0 +1 @@
libraryDependencies += "org.scala-tools.testing" %% "specs" % "1.6.1" intransitive()

View File

@ -1,9 +1,7 @@
> ++2.7.5
> update
> ++ 2.7.5
> test-only Success
-> test-only Failure
> ++2.7.7
> update
> ++ 2.7.7
> test-only Success
-> test-only Failure