Skip to content

Commit 634c001

Browse files
committed
Allow build tools to customize plugin classloader creation
An extension point analagous to `findMacroClassLoader`
1 parent d239bb2 commit 634c001

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/compiler/scala/tools/nsc/plugins/Plugin.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ object Plugin {
103103
* mitigate the cost of dynamic classloading as it has been
104104
* measured in https://github.com/scala/scala-dev/issues/458.
105105
*/
106-
private def loaderFor(locations: Seq[Path], disableCache: Boolean): ScalaClassLoader = {
106+
def loaderFor(locations: Seq[Path], disableCache: Boolean): ScalaClassLoader = {
107107
def newLoader = () => {
108108
val compilerLoader = classOf[Plugin].getClassLoader
109109
val urls = locations map (_.toURL)
@@ -155,7 +155,7 @@ object Plugin {
155155
paths: List[List[Path]],
156156
dirs: List[Path],
157157
ignoring: List[String],
158-
disableClassLoaderCache: Boolean): List[Try[AnyClass]] =
158+
findPluginClassloader: (Seq[Path] => ClassLoader)): List[Try[AnyClass]] =
159159
{
160160
// List[(jar, Try(descriptor))] in dir
161161
def scan(d: Directory) =
@@ -166,7 +166,7 @@ object Plugin {
166166
// scan plugin dirs for jars containing plugins, ignoring dirs with none and other jars
167167
val fromDirs: PDResults = dirs filter (_.isDirectory) flatMap { d =>
168168
scan(d.toDirectory) collect {
169-
case (j, Success(pd)) => Success((pd, loaderFor(Seq(j), disableClassLoaderCache)))
169+
case (j, Success(pd)) => Success((pd, findPluginClassloader(Seq(j))))
170170
}
171171
}
172172

@@ -183,7 +183,7 @@ object Plugin {
183183
loop(ps)
184184
}
185185
val fromPaths: PDResults = paths map (p => (p, findDescriptor(p))) map {
186-
case (p, Success(pd)) => Success((pd, loaderFor(p, disableClassLoaderCache)))
186+
case (p, Success(pd)) => Success((pd, findPluginClassloader(p)))
187187
case (_, Failure(e)) => Failure(e)
188188
}
189189

src/compiler/scala/tools/nsc/plugins/Plugins.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait Plugins { global: Global =>
3737
def injectDefault(s: String) = if (s.isEmpty) Defaults.scalaPluginPath else s
3838
asPath(settings.pluginsDir.value) map injectDefault map Path.apply
3939
}
40-
val maybes = Plugin.loadAllFrom(paths, dirs, settings.disable.value, settings.YcachePluginClassLoader.value == settings.CachePolicy.None.name)
40+
val maybes = Plugin.loadAllFrom(paths, dirs, settings.disable.value, findPluginClassLoader(_))
4141
val (goods, errors) = maybes partition (_.isSuccess)
4242
// Explicit parameterization of recover to avoid -Xlint warning about inferred Any
4343
errors foreach (_.recover[Any] {
@@ -53,6 +53,10 @@ trait Plugins { global: Global =>
5353
classes map (Plugin.instantiate(_, this))
5454
}
5555

56+
protected def findPluginClassLoader(classpath: Seq[Path]): ClassLoader = {
57+
Plugin.loaderFor(classpath, settings.YcachePluginClassLoader.value == settings.CachePolicy.None.name)
58+
}
59+
5660
protected lazy val roughPluginsList: List[Plugin] = loadRoughPluginsList()
5761

5862
/** Load all available plugins. Skips plugins that

0 commit comments

Comments
 (0)