summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/plugins/Plugins.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-09-07 22:16:58 +0000
committerPaul Phillips <paulp@improving.org>2009-09-07 22:16:58 +0000
commitaef123719dbe81b20fe3eed6390df9d62fd24a0b (patch)
tree0148ea23a2d709ac7173edf3e87122bb9d580eb3 /src/compiler/scala/tools/nsc/plugins/Plugins.scala
parent3335e037a83edef65eb3c6fa75be23c0d0a46aab (diff)
downloadscala-aef123719dbe81b20fe3eed6390df9d62fd24a0b.tar.gz
scala-aef123719dbe81b20fe3eed6390df9d62fd24a0b.tar.bz2
scala-aef123719dbe81b20fe3eed6390df9d62fd24a0b.zip
Reverts scala.io.* to its natural state, and th...
Reverts scala.io.* to its natural state, and the rest of trunk to using java.io.File. Anyone who wants to salvage any usable bits is of course welcome to do so, so long as they also assume responsibility for those bits.
Diffstat (limited to 'src/compiler/scala/tools/nsc/plugins/Plugins.scala')
-rw-r--r--src/compiler/scala/tools/nsc/plugins/Plugins.scala146
1 files changed, 93 insertions, 53 deletions
diff --git a/src/compiler/scala/tools/nsc/plugins/Plugins.scala b/src/compiler/scala/tools/nsc/plugins/Plugins.scala
index a67218ee01..1163ae5a6a 100644
--- a/src/compiler/scala/tools/nsc/plugins/Plugins.scala
+++ b/src/compiler/scala/tools/nsc/plugins/Plugins.scala
@@ -8,7 +8,7 @@
package scala.tools.nsc
package plugins
-import scala.io.{ File, Path }
+import java.io.File
/** Support for run-time loading of compiler plugins.
*
@@ -16,9 +16,7 @@ import scala.io.{ File, Path }
* @version 1.1, 2009/1/2
* Updated 2009/1/2 by Anders Bach Nielsen: Added features to implement SIP 00002
*/
-trait Plugins
-{
- self: Global =>
+trait Plugins { self: Global =>
/** Load a rough list of the plugins. For speed, it
* does not instantiate a compiler run. Therefore it cannot
@@ -26,17 +24,24 @@ trait Plugins
* filtered from the final list of plugins.
*/
protected def loadRoughPluginsList(): List[Plugin] = {
- val jars = settings.plugin.value map Path.apply
- val dirs = (settings.pluginsDir.value split File.pathSeparator).toList map Path.apply
- val classes = Plugin.loadAllFrom(jars, dirs, settings.disable.value)
-
- classes foreach (c => Plugin.instantiate(c, this))
+ val jars = settings.plugin.value.map(new File(_))
+ val dirs =
+ for (name <- settings.pluginsDir.value.split(File.pathSeparator).toList)
+ yield new File(name)
for (plugClass <- Plugin.loadAllFrom(jars, dirs, settings.disable.value))
yield Plugin.instantiate(plugClass, this)
}
- protected lazy val roughPluginsList: List[Plugin] = loadRoughPluginsList
+ private var roughPluginsListCache: Option[List[Plugin]] = None
+
+ protected def roughPluginsList: List[Plugin] =
+ roughPluginsListCache match {
+ case Some(list) => list
+ case None =>
+ roughPluginsListCache = Some(loadRoughPluginsList)
+ roughPluginsListCache.get
+ }
/** Load all available plugins. Skips plugins that
* either have the same name as another one, or which
@@ -49,70 +54,105 @@ trait Plugins
plugNames: Set[String],
phaseNames: Set[String]): List[Plugin] =
{
- if (plugins.isEmpty) return Nil // early return
-
- val plug :: tail = plugins
- val plugPhaseNames = Set(plug.components map (_.phaseName): _*)
- def withoutPlug = pick(tail, plugNames, plugPhaseNames)
- def withPlug = plug :: pick(tail, plugNames + plug.name, phaseNames ++ plugPhaseNames)
- lazy val commonPhases = phaseNames intersect plugPhaseNames
-
- def note(msg: String): Unit = if (settings.verbose.value) inform(msg format plug.name)
- def fail(msg: String) = { note(msg) ; withoutPlug }
-
- if (plugNames contains plug.name)
- fail("[skipping a repeated plugin: %s]")
- else if (settings.disable.value contains plug.name)
- fail("[disabling plugin: %s]")
- else if (!commonPhases.isEmpty)
- fail("[skipping plugin %s because it repeats phase names: " + (commonPhases mkString ", ") + "]")
- else {
- note("[loaded plugin %s]")
- withPlug
+ plugins match {
+ case Nil => Nil
+ case plug :: rest =>
+ val plugPhaseNames = Set.empty ++ plug.components.map(_.phaseName)
+ def withoutPlug = pick(rest, plugNames, plugPhaseNames)
+ def withPlug =
+ (plug ::
+ pick(rest,
+ plugNames+plug.name,
+ phaseNames++plugPhaseNames))
+
+ if (plugNames.contains(plug.name)) {
+ if (settings.verbose.value)
+ inform("[skipping a repeated plugin: " + plug.name + "]")
+ withoutPlug
+ } else if (settings.disable.value contains(plug.name)) {
+ if (settings.verbose.value)
+ inform("[disabling plugin: " + plug.name + "]")
+ withoutPlug
+ } else {
+ val commonPhases = phaseNames.intersect(plugPhaseNames)
+ if (!commonPhases.isEmpty) {
+ if (settings.verbose.value)
+ inform("[skipping plugin " + plug.name +
+ "because it repeats phase names: " +
+ commonPhases.mkString(", ") + "]")
+ withoutPlug
+ } else {
+ if (settings.verbose.value)
+ inform("[loaded plugin " + plug.name + "]")
+ withPlug
+ }
+ }
}
}
- val plugs = pick(roughPluginsList, Set(), phasesSet map (_.phaseName) toSet)
+ val plugs =
+ pick(roughPluginsList,
+ Set.empty,
+ Set.empty ++ phasesSet.map(_.phaseName))
- /** Verify requirements are present. */
- for (req <- settings.require.value ; if !(plugs exists (_.name == req)))
+ for (req <- settings.require.value; if !plugs.exists(p => p.name==req))
error("Missing required plugin: " + req)
- /** Process plugin options. */
- def namec(plug: Plugin) = plug.name + ":"
- def optList(xs: List[String], p: Plugin) = xs filter (_ startsWith namec(p))
- def doOpts(p: Plugin): List[String] =
- optList(settings.pluginOptions.value, p) map (_ stripPrefix namec(p))
- for (p <- plugs) {
- val opts = doOpts(p)
+ for (plug <- plugs) {
+ val nameColon = plug.name + ":"
+ val opts = for {
+ raw <- settings.pluginOptions.value
+ if raw.startsWith(nameColon)
+ } yield raw.substring(nameColon.length)
+
if (!opts.isEmpty)
- p.processOptions(opts, error)
+ plug.processOptions(opts, error)
}
- /** Verify no non-existent plugin given with -P */
- for (opt <- settings.pluginOptions.value ; if plugs forall (p => optList(List(opt), p).isEmpty))
- error("bad option: -P:" + opt)
+ for {
+ opt <- settings.pluginOptions.value
+ if !plugs.exists(p => opt.startsWith(p.name + ":"))
+ } error("bad option: -P:" + opt)
plugs
}
- lazy val plugins: List[Plugin] = loadPlugins
+ private var pluginsCache: Option[List[Plugin]] = None
+
+ def plugins: List[Plugin] = {
+ if (pluginsCache.isEmpty)
+ pluginsCache = Some(loadPlugins)
+ pluginsCache.get
+ }
/** A description of all the plugins that are loaded */
- def pluginDescriptions: String =
- roughPluginsList map (x => "%s - %s".format(x.name, x.description)) mkString "\n"
+ def pluginDescriptions: String = {
+ val messages =
+ for (plugin <- roughPluginsList)
+ yield plugin.name + " - " + plugin.description
+ messages.mkString("\n")
+ }
/**
* Extract all phases supplied by plugins and add them to the phasesSet.
* @see phasesSet
*/
- protected def computePluginPhases(): Unit =
- phasesSet ++= (plugins flatMap (_.components))
+ protected def computePluginPhases() {
+ val plugPhases = plugins.flatMap(_.components)
+ for (pPhase <- plugPhases) {
+ phasesSet += pPhase
+ }
+ }
/** Summary of the options for all loaded plugins */
- def pluginOptionsHelp: String =
- (for (plug <- roughPluginsList ; help <- plug.optionsHelp) yield {
- "Options for plugin %s:\n%s\n".format(plug.name, help)
- }) mkString
+ def pluginOptionsHelp: String = {
+ val buf = new StringBuffer
+ for (plug <- roughPluginsList; help <- plug.optionsHelp) {
+ buf append ("Options for plugin " + plug.name + ":\n")
+ buf append help
+ buf append "\n"
+ }
+ buf.toString
+ }
}