@@ -16,7 +16,7 @@ trait PluginPhase extends MiniPhase {
16
16
def runsBefore : Set [Class [_ <: Phase ]] = Set .empty
17
17
}
18
18
19
- trait Plugin {
19
+ sealed trait Plugin {
20
20
/** The name of this plugin */
21
21
def name : String
22
22
@@ -28,36 +28,34 @@ trait Plugin {
28
28
* Research plugin receives a phase plan and return a new phase plan, while
29
29
* non-research plugin returns a list of phases to be inserted.
30
30
*/
31
- def research : Boolean = false
31
+ def research : Boolean = isInstanceOf [ ResearchPlugin ]
32
32
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
+ }
33
39
40
+ trait StandardPlugin extends Plugin {
34
41
/** Non-research plugins should override this method to return the phases
35
42
*
36
43
* @param options: commandline options to the plugin, `-P:plugname:opt1,opt2` becomes List(opt1, opt2)
37
44
* @return a list of phases to be added to the phase plan
38
45
*/
39
- def init (options : List [String ]): List [PluginPhase ] = ???
46
+ def init (options : List [String ]): List [PluginPhase ]
47
+ }
40
48
49
+ trait ResearchPlugin extends Plugin {
41
50
/** Research plugins should override this method to return the new phase plan
42
51
*
43
52
* @param options: commandline options to the plugin, `-P:plugname:opt1,opt2` becomes List(opt1, opt2)
44
53
* @param plan: the given phase plan
45
54
* @return the new phase plan
46
55
*/
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 ]]
54
57
}
55
58
56
- /** ...
57
- *
58
- * @author Lex Spoon
59
- * @version 1.0, 2007-5-21
60
- */
61
59
object Plugin {
62
60
63
61
private val PluginXML = " scalac-plugin.xml"
@@ -72,21 +70,6 @@ object Plugin {
72
70
new java.net.URLClassLoader (urls.toArray, compilerLoader)
73
71
}
74
72
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
-
90
73
type AnyClass = Class [_]
91
74
92
75
/** Use a class loader to load the plugin class.
@@ -115,6 +98,20 @@ object Plugin {
115
98
dirs : List [Path ],
116
99
ignoring : List [String ]): List [Try [AnyClass ]] =
117
100
{
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
+
118
115
// List[(jar, Try(descriptor))] in dir
119
116
def scan (d : Directory ) =
120
117
d.files.toList sortBy (_.name) filter (Jar isJarOrZip _) map (j => (j, loadDescriptionFromJar(j)))
@@ -134,7 +131,7 @@ object Plugin {
134
131
def loop (qs : List [Path ]): Try [PluginDescription ] = qs match {
135
132
case Nil => Failure (new MissingPluginException (ps))
136
133
case p :: rest =>
137
- if (p.isDirectory) loadDescriptionFromFile (p.toDirectory / PluginXML ) orElse loop(rest)
134
+ if (p.isDirectory) loadDescriptionFromDir (p.toDirectory) orElse loop(rest)
138
135
else if (p.isFile) loadDescriptionFromJar(p.toFile) orElse loop(rest)
139
136
else loop(rest)
140
137
}
0 commit comments