mirror of https://github.com/sbt/sbt.git
test case demonstrating two ways of augmenting sbt's classpath. addExtra1 is the recommended way
This commit is contained in:
parent
5f8a73cc21
commit
37cedcca5f
|
|
@ -0,0 +1,45 @@
|
||||||
|
import sbt._
|
||||||
|
import Keys._
|
||||||
|
|
||||||
|
object B extends Build
|
||||||
|
{
|
||||||
|
lazy val root = Project("root", file(".")) settings(
|
||||||
|
autoScalaLibrary := false,
|
||||||
|
libraryDependencies += "log4j" % "log4j" % "1.2.16",
|
||||||
|
retrieveManaged := true,
|
||||||
|
commands ++= Seq(
|
||||||
|
addExtra("add1", addExtra1),
|
||||||
|
addExtra("add2", addExtra2),
|
||||||
|
checkExtra
|
||||||
|
)
|
||||||
|
)
|
||||||
|
def addExtra(name: String, f: (State, Seq[File]) => State) = Command.command(name) { s =>
|
||||||
|
f(s, (file("lib_managed") ** "*.jar").get)
|
||||||
|
}
|
||||||
|
def checkExtra = Command.command("check") { s =>
|
||||||
|
val loader = Class.forName("org.apache.log4j.Level").getClassLoader
|
||||||
|
val sbtLoader = classOf[sbt.Build].getClassLoader
|
||||||
|
assert(loader eq sbtLoader, "Different loader for sbt and extra: " + sbtLoader + " and " + loader)
|
||||||
|
s
|
||||||
|
}
|
||||||
|
def addExtra1(s: State, extra: Seq[File]): State =
|
||||||
|
{
|
||||||
|
val cs = s.configuration.provider.components()
|
||||||
|
val copied = cs.addToComponent("extra", extra.toArray)
|
||||||
|
if(copied) s.reload else s
|
||||||
|
}
|
||||||
|
def addExtra2(s: State, extra: Seq[File]): State =
|
||||||
|
{
|
||||||
|
val reload = State.defaultReload(s)
|
||||||
|
val currentID = reload.app
|
||||||
|
val currentExtra = currentID.classpathExtra
|
||||||
|
val newExtra = (currentExtra ++ extra).distinct
|
||||||
|
if(newExtra.length == currentExtra.length)
|
||||||
|
s
|
||||||
|
else
|
||||||
|
{
|
||||||
|
val newID = ApplicationID(currentID).copy(extra = extra)
|
||||||
|
s.setResult(Some(reload.copy(app = newID)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
-> check
|
||||||
|
> update
|
||||||
|
> add1
|
||||||
|
> check
|
||||||
|
|
||||||
|
> reboot full
|
||||||
|
-> check
|
||||||
|
|
||||||
|
> add2
|
||||||
|
> check
|
||||||
Loading…
Reference in New Issue