summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/plugins/Plugin.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/Plugin.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/Plugin.scala')
-rw-r--r--src/compiler/scala/tools/nsc/plugins/Plugin.scala91
1 files changed, 48 insertions, 43 deletions
diff --git a/src/compiler/scala/tools/nsc/plugins/Plugin.scala b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
index a7b686e750..3013199c36 100644
--- a/src/compiler/scala/tools/nsc/plugins/Plugin.scala
+++ b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
@@ -7,7 +7,7 @@
package scala.tools.nsc
package plugins
-import scala.io.{ File, Path }
+import java.io.File
import java.net.URLClassLoader
import java.util.jar.JarFile
import java.util.zip.ZipException
@@ -63,44 +63,39 @@ abstract class Plugin {
* @author Lex Spoon
* @version 1.0, 2007-5-21
*/
-object Plugin
-{
- private val PluginXML = "scalac-plugin.xml"
-
+object Plugin {
/** Create a class loader with the specified file plus
* the loader that loaded the Scala compiler.
*/
- private def loaderFor(jarfiles: Seq[Path]): ClassLoader = {
+ private def loaderFor(jarfiles: Seq[File]): ClassLoader = {
val compilerLoader = classOf[Plugin].getClassLoader
- val jarurls = jarfiles map (_.toURL)
-
- new URLClassLoader(jarurls.toArray, compilerLoader)
+ val jarurls = jarfiles.map(_.toURL).toArray
+ new URLClassLoader(jarurls, compilerLoader)
}
/** Try to load a plugin description from the specified
* file, returning None if it does not work. */
- private def loadDescription(jarfile: Path): Option[PluginDescription] =
- // XXX Return to this once we have some ARM support
- if (!jarfile.exists) None
- else try {
- val jar = new JarFile(jarfile.jfile)
+ private def loadDescription(jarfile: File): Option[PluginDescription] = {
+ if (!jarfile.exists) return None
+ try {
+ val jar = new JarFile(jarfile)
try {
- (jar getEntry PluginXML) match {
- case null => None
- case entry =>
- val in = jar getInputStream entry
- val packXML = XML load in
- in.close()
-
- PluginDescription fromXML packXML
- }
+ val ent = jar.getEntry("scalac-plugin.xml")
+ if (ent == null) return None
+
+ val inBytes = jar.getInputStream(ent)
+ val packXML = XML.load(inBytes)
+ inBytes.close()
+
+ PluginDescription.fromXML(packXML)
+ } finally {
+ jar.close()
}
- finally jar.close()
- }
- catch {
+ } catch {
case _: ZipException => None
}
+ }
type AnyClass = Class[_]
@@ -108,13 +103,16 @@ object Plugin
* if the jar file has no plugin in it or if the plugin
* is badly formed.
*/
- def loadFrom(jarfile: Path, loader: ClassLoader): Option[AnyClass] = {
+ def loadFrom(jarfile: File, loader: ClassLoader): Option[AnyClass] = {
val pluginInfo = loadDescription(jarfile).get
- try Some(loader loadClass pluginInfo.classname) catch {
- case _: ClassNotFoundException =>
- println("Warning: class not found for plugin in %s (%s)".format(jarfile, pluginInfo.classname))
- None
+ try {
+ Some(loader.loadClass(pluginInfo.classname))
+ } catch {
+ case _:ClassNotFoundException =>
+ println("Warning: class not found for plugin in " + jarfile +
+ " (" + pluginInfo.classname + ")")
+ None
}
}
@@ -123,28 +121,35 @@ object Plugin
* directories specified. Skips all plugins in <code>ignoring</code>.
* A single classloader is created and used to load all of them.
*/
- def loadAllFrom(
- jars: List[Path],
- dirs: List[Path],
- ignoring: List[String]): List[AnyClass] =
+ def loadAllFrom(jars: List[File],
+ dirs: List[File],
+ ignoring: List[String]): List[AnyClass] =
{
- val alljars = jars ::: (for {
+ val alljars = new ListBuffer[File]
+
+ alljars ++= jars
+
+ for {
dir <- dirs if dir.isDirectory
- entry <- dir.toDirectory.files.toList sortWith (_.name <= _.name)
- if entry.name.toLowerCase endsWith ".jar"
+ entries = dir.listFiles
+ if entries ne null
+ entry <- entries.toList.sort(_.getName <= _.getName)
+ if entry.toString.toLowerCase endsWith ".jar"
pdesc <- loadDescription(entry)
if !(ignoring contains pdesc.name)
- } yield entry)
+ } alljars += entry
- val loader = loaderFor(alljars)
- alljars map (loadFrom(_, loader)) flatten
+ val loader = loaderFor(alljars.toList)
+ alljars.toList.map(f => loadFrom(f,loader)).flatMap(x => x)
}
/** Instantiate a plugin class, given the class and
* the compiler it is to be used in.
*/
def instantiate(clazz: AnyClass, global: Global): Plugin = {
- val constructor = clazz getConstructor classOf[Global]
- (constructor newInstance global).asInstanceOf[Plugin]
+ //println("instantiating "+clazz)
+ //println(clazz.getDeclaredConstructors)
+ val constructor = clazz.getConstructor(classOf[Global])
+ constructor.newInstance(global).asInstanceOf[Plugin]
}
}