mirror of https://github.com/sbt/sbt.git
migrate a few more dependency management integration tests
This commit is contained in:
parent
58d9f3b0a0
commit
5b6f6a16e1
|
|
@ -0,0 +1,25 @@
|
||||||
|
import sbt._
|
||||||
|
import Keys._
|
||||||
|
|
||||||
|
object ExcludeScala extends Build
|
||||||
|
{
|
||||||
|
lazy val projects = Seq(root)
|
||||||
|
lazy val root = Project("root", file(".")) settings(
|
||||||
|
libraryDependencies <++= baseDirectory(dependencies),
|
||||||
|
scalaVersion := "2.8.1",
|
||||||
|
autoScalaLibrary <<= baseDirectory(base => !(base / "noscala").exists ),
|
||||||
|
scalaOverride <<= fullClasspath in Compile map { cp =>
|
||||||
|
val existing = cp.files.filter(_.getName contains "scala-library")
|
||||||
|
val loader = classpath.ClasspathUtilities.toLoader(existing)
|
||||||
|
// check that the 2.8.1 scala-library is on the classpath and not 2.7.7
|
||||||
|
Class.forName("scala.collection.immutable.List", false, loader)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
lazy val scalaOverride = TaskKey[Unit]("scala-override")
|
||||||
|
|
||||||
|
def dependencies(base: File) =
|
||||||
|
if( ( base / "sbinary").exists )
|
||||||
|
("org.scala-tools.sbinary" % "sbinary_2.7.7" % "0.3") :: Nil
|
||||||
|
else
|
||||||
|
Nil
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,13 @@
|
||||||
> no-scala
|
> scala-override
|
||||||
> update
|
|
||||||
> no-scala
|
$ touch sbinary
|
||||||
|
> reload
|
||||||
|
> scala-override
|
||||||
|
|
||||||
|
$ touch noscala
|
||||||
|
> reload
|
||||||
|
> scala-override
|
||||||
|
|
||||||
|
$ delete sbinary
|
||||||
|
> reload
|
||||||
|
-> scala-override
|
||||||
|
|
@ -6,23 +6,20 @@ object TestProject extends Build
|
||||||
lazy val projects = Seq(root)
|
lazy val projects = Seq(root)
|
||||||
lazy val root = Project("root", file(".")) settings(
|
lazy val root = Project("root", file(".")) settings(
|
||||||
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))),
|
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))),
|
||||||
libraryDependencies += transitive("javax.mail" % "mail" % "1.4.1"),
|
libraryDependencies <+= baseDirectory(transitive("javax.mail" % "mail" % "1.4.1")),
|
||||||
TaskKey("check-transitive") <<= check(true),
|
TaskKey("check-transitive") <<= check(true),
|
||||||
TaskKey("check-intransitive") <<= check(false)
|
TaskKey("check-intransitive") <<= check(false)
|
||||||
)
|
)
|
||||||
|
|
||||||
def transitive(dep: ModuleID) =
|
def transitive(dep: ModuleID)(base: File) =
|
||||||
{
|
if((base / "transitive").exists) dep else dep.intransitive()
|
||||||
println("transitive(" + dep + ") = " + file("transitive").exists)
|
|
||||||
if(file("transitive").exists) dep else dep.intransitive()
|
|
||||||
}
|
|
||||||
|
|
||||||
private def check(transitive: Boolean) =
|
private def check(transitive: Boolean) =
|
||||||
(dependencyClasspath in Compile) map { downloaded =>
|
(dependencyClasspath in Compile) map { downloaded =>
|
||||||
val jars = downloaded.size
|
val jars = downloaded.size
|
||||||
if(transitive)
|
if(transitive)
|
||||||
if(jars <= 1) error("Transitive dependencies not downloaded")
|
if(jars <= 2) error("Transitive dependencies not downloaded") else ()
|
||||||
else
|
else
|
||||||
if(jars > 1) error("Transitive dependencies downloaded (" + downloaded.files.mkString(", ") + ")")
|
if(jars > 2) error("Transitive dependencies downloaded (" + downloaded.files.mkString(", ") + ")") else ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
# load the project definition with transitive dependencies enabled
|
# load the project definition with transitive dependencies enabled
|
||||||
# and check that they are not downloaded
|
# and check that they are not downloaded
|
||||||
$ pause
|
#$ pause
|
||||||
$ touch transitive
|
$ touch transitive
|
||||||
$ pause
|
|
||||||
|
#$ pause
|
||||||
> reload
|
> reload
|
||||||
$ pause
|
#$ pause
|
||||||
|
|
||||||
> check-transitive
|
> check-transitive
|
||||||
-> check-intransitive
|
-> check-intransitive
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import sbt._
|
||||||
|
import Keys._
|
||||||
|
|
||||||
|
object Test extends Build
|
||||||
|
{
|
||||||
|
lazy val projects = Seq(root)
|
||||||
|
lazy val root = Project("root", file(".")) settings(
|
||||||
|
libraryDependencies += "net.liftweb" % "lift-webkit" % "1.0" intransitive(),
|
||||||
|
libraryDependencies += "org.scalacheck" % "scalacheck" % "1.5" intransitive(),
|
||||||
|
transitiveClassifiers := Seq("sources"),
|
||||||
|
TaskKey("check-sources") <<= updateClassifiers map checkSources,
|
||||||
|
TaskKey("check-binaries") <<= update map checkBinaries
|
||||||
|
)
|
||||||
|
def getSources(report: UpdateReport) = report.matching(artifactFilter(`classifier` = "sources") )
|
||||||
|
def checkSources(report: UpdateReport) =
|
||||||
|
{
|
||||||
|
val srcs = getSources(report)
|
||||||
|
if(srcs.isEmpty) error("No sources retrieved") else if(srcs.size != 2) error("Incorrect sources retrieved:\n\t" + srcs.mkString("\n\t"))
|
||||||
|
}
|
||||||
|
def checkBinaries(report: UpdateReport) =
|
||||||
|
{
|
||||||
|
val srcs = getSources(report)
|
||||||
|
if(!srcs.isEmpty) error("Sources retrieved:\n\t" + srcs.mkString("\n\t"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
project.name=Test
|
|
||||||
project.version=1.0
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
import sbt._
|
|
||||||
|
|
||||||
class Test(info: ProjectInfo) extends DefaultProject(info)
|
|
||||||
{
|
|
||||||
val sourcesOnly = "net.liftweb" % "lift-webkit" % "1.0" % "sources" sources() intransitive()
|
|
||||||
val sourcesAndJar = "org.scalacheck" % "scalacheck" % "1.5" withSources()
|
|
||||||
def expectedCompile = Set("scalacheck-1.5.jar", "scalacheck-1.5-sources.jar")
|
|
||||||
def expectedSources = Set("lift-webkit-1.0-sources.jar")
|
|
||||||
lazy val check = task
|
|
||||||
{
|
|
||||||
val compilePath = names(compileClasspath.get)
|
|
||||||
val sources = names(fullClasspath(Configurations.Sources).get)
|
|
||||||
if(!same(expectedCompile, compilePath))
|
|
||||||
Some("Expected compile classpath " + expectedCompile.mkString(", ") + " differs from actual: " + compilePath.mkString(", "))
|
|
||||||
else if(!same(expectedSources, sources))
|
|
||||||
Some("Expected sources " + expectedSources.mkString(", ") + " differ from actual: " + sources.mkString(", "))
|
|
||||||
else
|
|
||||||
None
|
|
||||||
}
|
|
||||||
def names(path: Iterable[Path]): Set[String] = Set() ++ path.map(_.asFile.getName)
|
|
||||||
def same(expected: Set[String], actual: Set[String]) = (expected -- actual).isEmpty
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
> update
|
> check-binaries
|
||||||
> check
|
> show update-classifiers
|
||||||
|
> check-sources
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
import sbt._
|
||||||
|
import Keys._
|
||||||
|
|
||||||
|
object TestProject extends Build
|
||||||
|
{
|
||||||
|
lazy val projects = Seq(root)
|
||||||
|
lazy val root = Project("root", file(".")) settings(
|
||||||
|
libraryDependencies += "slinky" % "slinky" % "2.1" % "test" from "http://slinky2.googlecode.com/svn/artifacts/2.1/slinky.jar",
|
||||||
|
TaskKey("check-in-test") <<= checkClasspath(Test),
|
||||||
|
TaskKey("check-in-compile") <<= checkClasspath(Compile)
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val checkInTest = checkClasspath(testClasspath)
|
||||||
|
lazy val checkInCompile = checkClasspath(compileClasspath)
|
||||||
|
private def checkClasspath(conf: Configuration) =
|
||||||
|
fullClasspath in conf map { cp =>
|
||||||
|
try
|
||||||
|
{
|
||||||
|
val loader = ClasspathUtilities.toLoader(cp)
|
||||||
|
Class.forName("slinky.http.Application", false, loader)
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
case _: ClassNotFoundException => error("Dependency not downloaded.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
project.name=Test
|
|
||||||
project.version=1.0
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
import sbt._
|
|
||||||
|
|
||||||
import java.net.{URL, URLClassLoader}
|
|
||||||
|
|
||||||
class TestProject(info: ProjectInfo) extends DefaultProject(info)
|
|
||||||
{
|
|
||||||
override def useMavenConfigurations = true
|
|
||||||
val direct = "slinky" % "slinky" % "2.1" % "test->default" from "http://slinky2.googlecode.com/svn/artifacts/2.1/slinky.jar"
|
|
||||||
lazy val checkInTest = checkClasspath(testClasspath)
|
|
||||||
lazy val checkInCompile = checkClasspath(compileClasspath)
|
|
||||||
private def checkClasspath(cp: PathFinder) =
|
|
||||||
task
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("slinky.http.Application", false, new URLClassLoader(cp.get.map(_.asURL).toList.toArray))
|
|
||||||
None
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
case _: ClassNotFoundException =>
|
|
||||||
Some("Dependency not downloaded.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue