Port project/extra

This commit is contained in:
Eugene Yokota 2016-03-29 01:54:58 -04:00
parent 32d21d0685
commit d01f8d3c1b
3 changed files with 44 additions and 47 deletions

View File

@ -11,7 +11,7 @@ import sbt.io.Hash
import sbt.internal.util.Attributed
import sbt.internal.inc.ReflectUtilities
private[sbt] trait BuildDef {
trait BuildDef {
def projectDefinitions(baseDirectory: File): Seq[Project] = projects
def projects: Seq[Project] = ReflectUtilities.allVals[Project](this).values.toSeq
// TODO: Should we grab the build core setting shere or in a plugin?

View File

@ -0,0 +1,43 @@
lazy val root = (project in 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.internal.BuildDef].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)))
}
}

View File

@ -1,46 +0,0 @@
import sbt._
import Keys._
import Import._
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)))
}
}
}