mirror of https://github.com/sbt/sbt.git
load plugin classes in a single class loader across builds. fixes #329
This commit is contained in:
parent
0fbe987cd0
commit
bda151c3bd
|
|
@ -123,10 +123,10 @@ final class BuildLoader(
|
|||
full.setRoot(loaders.full),
|
||||
loaders.transformAll andThen transformAll
|
||||
)
|
||||
def updatePluginManagement(overrides: Set[ModuleID], loader: ClassLoader): BuildLoader =
|
||||
def updatePluginManagement(overrides: Set[ModuleID]): BuildLoader =
|
||||
{
|
||||
val mgmt = config.pluginManagement
|
||||
val newConfig = config.copy(pluginManagement = mgmt.copy(overrides = mgmt.overrides ++ overrides, loader = loader))
|
||||
val newConfig = config.copy(pluginManagement = mgmt.copy(overrides = mgmt.overrides ++ overrides))
|
||||
new BuildLoader(fail, state, newConfig, resolvers, builders, transformer, full, transformAll)
|
||||
}
|
||||
def components = new Components(resolvers.applyFun, builders.applyFun, transformer, full.applyFun, transformAll)
|
||||
|
|
|
|||
|
|
@ -249,10 +249,8 @@ object Load
|
|||
newLoaders transformAll build
|
||||
}
|
||||
def addOverrides(unit: BuildUnit, loaders: BuildLoader): BuildLoader =
|
||||
{
|
||||
val overrides = PluginManagement.extractOverrides(unit.plugins.fullClasspath)
|
||||
loaders.updatePluginManagement(overrides, unit.plugins.loader)
|
||||
}
|
||||
loaders updatePluginManagement PluginManagement.extractOverrides(unit.plugins.fullClasspath)
|
||||
|
||||
def addResolvers(unit: BuildUnit, isRoot: Boolean, loaders: BuildLoader): BuildLoader =
|
||||
unit.definitions.builds.flatMap(_.buildLoaders) match
|
||||
{
|
||||
|
|
@ -468,7 +466,9 @@ object Load
|
|||
def pluginDefinitionLoader(config: LoadBuildConfiguration, pluginClasspath: Seq[Attributed[File]]): (Seq[Attributed[File]], ClassLoader) =
|
||||
{
|
||||
val definitionClasspath = if(pluginClasspath.isEmpty) config.classpath else (pluginClasspath ++ config.classpath).distinct
|
||||
val pluginLoader = if(pluginClasspath.isEmpty) config.loader else ClasspathUtilities.toLoader(data(pluginClasspath), config.loader)
|
||||
val pm = config.pluginManagement
|
||||
def addToLoader() = pm.loader add Path.toURLs(data(pluginClasspath))
|
||||
val pluginLoader = if(pluginClasspath.isEmpty) pm.initialLoader else { addToLoader(); pm.loader }
|
||||
(definitionClasspath, pluginLoader)
|
||||
}
|
||||
def buildPluginDefinition(dir: File, s: State, config: LoadBuildConfiguration): Seq[Attributed[File]] =
|
||||
|
|
|
|||
|
|
@ -2,17 +2,20 @@ package sbt
|
|||
|
||||
import Keys.Classpath
|
||||
import Project.Setting
|
||||
import PluginManagement._
|
||||
|
||||
final case class PluginManagement(overrides: Set[ModuleID], applyOverrides: Set[ModuleID], loader: ClassLoader, initialLoader: ClassLoader)
|
||||
import java.net.{URL,URLClassLoader}
|
||||
|
||||
final case class PluginManagement(overrides: Set[ModuleID], applyOverrides: Set[ModuleID], loader: PluginClassLoader, initialLoader: ClassLoader)
|
||||
{
|
||||
def shift: PluginManagement =
|
||||
PluginManagement(Set.empty, overrides, initialLoader, initialLoader)
|
||||
PluginManagement(Set.empty, overrides, new PluginClassLoader(initialLoader), initialLoader)
|
||||
|
||||
def addOverrides(os: Set[ModuleID]): PluginManagement =
|
||||
copy(overrides = overrides ++ os)
|
||||
|
||||
def addOverrides(cp: Classpath): PluginManagement =
|
||||
addOverrides(PluginManagement extractOverrides cp)
|
||||
addOverrides(extractOverrides(cp))
|
||||
|
||||
def inject: Seq[Setting[_]] = Seq(
|
||||
Keys.dependencyOverrides ++= overrides
|
||||
|
|
@ -20,11 +23,16 @@ final case class PluginManagement(overrides: Set[ModuleID], applyOverrides: Set[
|
|||
}
|
||||
object PluginManagement
|
||||
{
|
||||
def apply(initialLoader: ClassLoader): PluginManagement = PluginManagement(Set.empty, Set.empty, initialLoader, initialLoader)
|
||||
def apply(initialLoader: ClassLoader): PluginManagement =
|
||||
PluginManagement(Set.empty, Set.empty, new PluginClassLoader(initialLoader), initialLoader)
|
||||
|
||||
def extractOverrides(classpath: Classpath): Set[ModuleID] =
|
||||
classpath flatMap { _.metadata get Keys.moduleID.key map keepOverrideInfo } toSet;
|
||||
|
||||
def keepOverrideInfo(m: ModuleID): ModuleID =
|
||||
ModuleID(m.organization, m.name, m.revision, crossVersion = m.crossVersion)
|
||||
|
||||
final class PluginClassLoader(p: ClassLoader) extends URLClassLoader(Array(), p) {
|
||||
def add(urls: Seq[URL]): Unit = synchronized { urls foreach addURL }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue