Port project/provided

This commit is contained in:
Eugene Yokota 2016-03-29 02:04:16 -04:00
parent 060f06d23e
commit 576bb4d42f
2 changed files with 36 additions and 33 deletions

View File

@ -0,0 +1,36 @@
lazy val superRoot = (project in file("super")).
dependsOn(rootRef)
lazy val root = (project in file(".")).
dependsOn(sub % "provided->test").
settings(
rootSettings
)
lazy val sub = project
lazy val rootRef = LocalProject("root")
def rootSettings = Defaults.defaultSettings :+ ( TaskKey[Unit]("check") <<= checkTask )
def checkTask = (fullClasspath in (rootRef, Compile), fullClasspath in (rootRef, Runtime), fullClasspath in (rootRef, Test), fullClasspath in (sub, Test), fullClasspath in (superRoot, Compile)) map { (rc, rr, rt, st, pr) =>
check0(st, "sub test", true)
check0(pr, "superRoot main", false)
check0(rc, "root main", true)
check0(rr, "root runtime", false)
check0(rt, "root test", true)
}
def check0(cp: Seq[Attributed[File]], label: String, shouldSucceed: Boolean): Unit =
{
val loader = classpath.ClasspathUtilities.toLoader(cp.files)
println("Checking " + label)
val err = try { Class.forName("org.example.ProvidedTest", false, loader); None }
catch { case e: Exception => Some(e) }
(err, shouldSucceed) match
{
case (None, true) | (Some(_), false) => ()
case (None, false) => sys.error("Expected failure")
case (Some(x), true) => throw x
}
}

View File

@ -1,33 +0,0 @@
import sbt._
import Import._
import Keys._
object P extends Build
{
lazy val superRoot = Project("super-root", file("super")) dependsOn(root)
lazy val root: Project = Project("root", file("."), settings = rootSettings, dependencies = (sub % "provided->test") :: Nil)
lazy val sub = Project("sub", file("sub"))
def rootSettings = Defaults.defaultSettings :+ ( TaskKey[Unit]("check") <<= checkTask )
def checkTask = (fullClasspath in (root, Compile), fullClasspath in (root, Runtime), fullClasspath in (root, Test), fullClasspath in (sub, Test), fullClasspath in (superRoot, Compile)) map { (rc, rr, rt, st, pr) =>
check0(st, "sub test", true)
check0(pr, "super main", false)
check0(rc, "root main", true)
check0(rr, "root runtime", false)
check0(rt, "root test", true)
}
def check0(cp: Seq[Attributed[File]], label: String, shouldSucceed: Boolean): Unit =
{
val loader = classpath.ClasspathUtilities.toLoader(cp.files)
println("Checking " + label)
val err = try { Class.forName("org.example.ProvidedTest", false, loader); None }
catch { case e: Exception => Some(e) }
(err, shouldSucceed) match
{
case (None, true) | (Some(_), false) => ()
case (None, false) => sys.error("Expected failure")
case (Some(x), true) => throw x
}
}
}