@@ -16,7 +16,7 @@ trait PluginPhase extends MiniPhase {
1616 def runsBefore : Set [Class [_ <: Phase ]] = Set .empty
1717}
1818
19- trait Plugin {
19+ sealed trait Plugin {
2020 /** The name of this plugin */
2121 def name : String
2222
@@ -28,36 +28,34 @@ trait Plugin {
2828 * Research plugin receives a phase plan and return a new phase plan, while
2929 * non-research plugin returns a list of phases to be inserted.
3030 */
31- def research : Boolean = false
31+ def research : Boolean = isInstanceOf [ ResearchPlugin ]
3232
33+ /** A description of this plugin's options, suitable as a response
34+ * to the -help command-line option. Conventionally, the options
35+ * should be listed with the `-P:plugname:` part included.
36+ */
37+ val optionsHelp : Option [String ] = None
38+ }
3339
40+ trait StandardPlugin extends Plugin {
3441 /** Non-research plugins should override this method to return the phases
3542 *
3643 * @param options: commandline options to the plugin, `-P:plugname:opt1,opt2` becomes List(opt1, opt2)
3744 * @return a list of phases to be added to the phase plan
3845 */
39- def init (options : List [String ]): List [PluginPhase ] = ???
46+ def init (options : List [String ]): List [PluginPhase ]
47+ }
4048
49+ trait ResearchPlugin extends Plugin {
4150 /** Research plugins should override this method to return the new phase plan
4251 *
4352 * @param options: commandline options to the plugin, `-P:plugname:opt1,opt2` becomes List(opt1, opt2)
4453 * @param plan: the given phase plan
4554 * @return the new phase plan
4655 */
47- def init (options : List [String ], plan : List [List [Phase ]])(implicit ctx : Context ): List [List [Phase ]] = ???
48-
49- /** A description of this plugin's options, suitable as a response
50- * to the -help command-line option. Conventionally, the options
51- * should be listed with the `-P:plugname:` part included.
52- */
53- val optionsHelp : Option [String ] = None
56+ def init (options : List [String ], plan : List [List [Phase ]])(implicit ctx : Context ): List [List [Phase ]]
5457}
5558
56- /** ...
57- *
58- * @author Lex Spoon
59- * @version 1.0, 2007-5-21
60- */
6159object Plugin {
6260
6361 private val PluginXML = " scalac-plugin.xml"
@@ -72,21 +70,6 @@ object Plugin {
7270 new java.net.URLClassLoader (urls.toArray, compilerLoader)
7371 }
7472
75- /** Try to load a plugin description from the specified location.
76- */
77- private def loadDescriptionFromJar (jarp : Path ): Try [PluginDescription ] = {
78- // XXX Return to this once we have more ARM support
79- def read (is : InputStream ) =
80- if (is == null ) throw new PluginLoadException (jarp.path, s " Missing $PluginXML in $jarp" )
81- else PluginDescription .fromXML(is)
82-
83- val xmlEntry = new java.util.jar.JarEntry (PluginXML )
84- Try (read(new Jar (jarp.jpath.toFile).getEntryStream(xmlEntry)))
85- }
86-
87- private def loadDescriptionFromFile (f : Path ): Try [PluginDescription ] =
88- Try (PluginDescription .fromXML(new java.io.FileInputStream (f.jpath.toFile)))
89-
9073 type AnyClass = Class [_]
9174
9275 /** Use a class loader to load the plugin class.
@@ -115,6 +98,20 @@ object Plugin {
11598 dirs : List [Path ],
11699 ignoring : List [String ]): List [Try [AnyClass ]] =
117100 {
101+
102+ def loadDescriptionFromDir (f : Path ): Try [PluginDescription ] =
103+ Try (PluginDescription .fromXML(new java.io.FileInputStream ((f / PluginXML ).jpath.toFile)))
104+
105+ def loadDescriptionFromJar (jarp : Path ): Try [PluginDescription ] = {
106+ // XXX Return to this once we have more ARM support
107+ def read (is : InputStream ) =
108+ if (is == null ) throw new PluginLoadException (jarp.path, s " Missing $PluginXML in $jarp" )
109+ else PluginDescription .fromXML(is)
110+
111+ val xmlEntry = new java.util.jar.JarEntry (PluginXML )
112+ Try (read(new Jar (jarp.jpath.toFile).getEntryStream(xmlEntry)))
113+ }
114+
118115 // List[(jar, Try(descriptor))] in dir
119116 def scan (d : Directory ) =
120117 d.files.toList sortBy (_.name) filter (Jar isJarOrZip _) map (j => (j, loadDescriptionFromJar(j)))
@@ -134,7 +131,7 @@ object Plugin {
134131 def loop (qs : List [Path ]): Try [PluginDescription ] = qs match {
135132 case Nil => Failure (new MissingPluginException (ps))
136133 case p :: rest =>
137- if (p.isDirectory) loadDescriptionFromFile (p.toDirectory / PluginXML ) orElse loop(rest)
134+ if (p.isDirectory) loadDescriptionFromDir (p.toDirectory) orElse loop(rest)
138135 else if (p.isFile) loadDescriptionFromJar(p.toFile) orElse loop(rest)
139136 else loop(rest)
140137 }
0 commit comments