Revert "Load global plugins in their own class loader and replace the base loader with that. Fixes #272."

This reverts commit 8cb7e23011.

Conflicts:
	main/src/main/scala/sbt/Load.scala
This commit is contained in:
Dan Sanduleac 2014-05-19 16:08:53 +01:00
parent 2dc910ba0b
commit 87e9250cb2
8 changed files with 8 additions and 63 deletions

View File

@ -73,25 +73,17 @@ object Load {
}
def buildGlobalSettings(base: File, files: Seq[File], config: sbt.LoadBuildConfiguration): ClassLoader => Seq[Setting[_]] =
{
val eval = mkEval(data(config.classpath), base, defaultEvalOptions)
val eval = mkEval(data(config.globalPluginClasspath), base, defaultEvalOptions)
val imports = BuildUtil.baseImports ++ BuildUtil.importAllRoot(config.globalPluginNames)
loader => EvaluateConfigurations(eval, files, imports)(loader).settings
}
def loadGlobal(state: State, base: File, global: File, config: sbt.LoadBuildConfiguration): sbt.LoadBuildConfiguration =
if (base != global && global.exists) {
val gp = GlobalPlugin.load(global, state, config)
val pm = setGlobalPluginLoader(gp, config.pluginManagement)
val cp = (gp.data.fullClasspath ++ config.classpath).distinct
config.copy(globalPlugin = Some(gp), pluginManagement = pm, classpath = cp)
config.copy(globalPlugin = Some(gp))
} else
config
private[this] def setGlobalPluginLoader(gp: GlobalPlugin, pm: PluginManagement): PluginManagement =
{
val newLoader = ClasspathUtilities.toLoader(data(gp.data.fullClasspath), pm.initialLoader)
pm.copy(initialLoader = newLoader)
}
def defaultDelegates: sbt.LoadedBuild => Scope => Seq[Scope] = (lb: sbt.LoadedBuild) => {
val rootProject = getRootProject(lb.units)
def resolveRef(project: Reference): ResolvedReference = Scope.resolveReference(lb.root, rootProject, project)
@ -688,7 +680,6 @@ object Load {
DiscoveredProjects(root.headOption, nonRoot, rawFiles)
}
@deprecated("No longer used.", "0.13.0")
def globalPluginClasspath(globalPlugin: Option[GlobalPlugin]): Seq[Attributed[File]] =
globalPlugin match {
case Some(cp) => cp.data.fullClasspath
@ -733,7 +724,7 @@ object Load {
!(dir * -GlobFilter(DefaultTargetName)).get.isEmpty
}
def noPlugins(dir: File, config: sbt.LoadBuildConfiguration): sbt.LoadedPlugins =
loadPluginDefinition(dir, config, PluginData(config.classpath, None, None))
loadPluginDefinition(dir, config, PluginData(config.globalPluginClasspath, None, None))
def buildPlugins(dir: File, s: State, config: sbt.LoadBuildConfiguration): sbt.LoadedPlugins =
loadPluginDefinition(dir, config, buildPluginDefinition(dir, s, config))
@ -903,11 +894,8 @@ final case class LoadBuildConfiguration(
globalPlugin: Option[GlobalPlugin],
extraBuilds: Seq[URI],
log: Logger) {
@deprecated("Use `classpath`.", "0.13.0")
lazy val globalPluginClasspath = classpath
@deprecated("Use `pluginManagement.initialLoader`.", "0.13.0")
lazy val globalPluginLoader = pluginManagement.initialLoader
lazy val globalPluginNames = if (classpath.isEmpty) Nil else Load.getPluginNames(classpath, pluginManagement.initialLoader)
lazy val (globalPluginClasspath, globalPluginLoader) = Load.pluginDefinitionLoader(this, Load.globalPluginClasspath(globalPlugin))
lazy val globalPluginNames = if (globalPluginClasspath.isEmpty) Nil else Load.getPluginNames(globalPluginClasspath, globalPluginLoader)
}
final class IncompatiblePluginsException(msg: String, cause: Throwable) extends Exception(msg, cause)

View File

@ -1,4 +0,0 @@
# tests that a source file in $sbt.global.base/plugins/ is available to the build definition in project/
# dummy to ensure project gets loaded
> name

View File

@ -1,21 +0,0 @@
import sbt._
import sbt.Keys._
object MyBuild extends Build {
lazy val mySettings = Defaults.defaultSettings ++ Seq(
name := "my-test-proj",
organization := "com.example",
check <<= update map checkVersion,
version := "0.1.0-SNAPSHOT")
lazy val proj = Project("my-test-proj", file("."), settings = mySettings)
lazy val check = taskKey[Unit]("Verifies that the junit dependency has the older version (4.5)")
def checkVersion(report: UpdateReport) {
for(mod <- report.allModules) {
if(mod.name == "junit") assert(mod.revision == "4.5", s"JUnit version (${mod.revision}) was not overridden")
}
}
}

View File

@ -1,3 +0,0 @@
// use a small java library instead of a plugin to avoid incompatibilities when upgrading
// use an old version to check that it will override a newer version in a build definition
libraryDependencies += "junit" % "junit" % "4.5"

View File

@ -1,2 +0,0 @@
// the version should be overridden by the global plugin
libraryDependencies += "junit" % "junit" % "4.8"

View File

@ -1,17 +1,4 @@
$ copy-file changes/Build.scala project/Build.scala
> reload
# tests that a source file in $sbt.global.base/plugins/ is available to the build definition in project/
# ensure that a new global dependency gets picked up
$ copy-file changes/global-plugins.sbt global/plugins/plugins.sbt
> reload
# check that the class can be loaded
> eval Class.forName("org.junit.Test")
# check that it is on the classpath
> eval (x => ()) : (org.junit.Test => Unit)
# ensure that the global plugin version overrides the local version
$ copy-file changes/plugins.sbt project/plugins.sbt
> reload
> check
# dummy to ensure project gets loaded
> name