summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2007-06-07 09:11:46 +0000
committerLex Spoon <lex@lexspoon.org>2007-06-07 09:11:46 +0000
commitd1aed7012af7439181c4696fb33f5f4337b83684 (patch)
tree5f57aa3c6860ada20b5e4ef00debe18acf5884c1 /src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
parent6739cacb9dbc1cbc3c459b87b8ba97923d687fbe (diff)
downloadscala-d1aed7012af7439181c4696fb33f5f4337b83684.tar.gz
scala-d1aed7012af7439181c4696fb33f5f4337b83684.tar.bz2
scala-d1aed7012af7439181c4696fb33f5f4337b83684.zip
Final merge from the plugins branch. The compiler
can now have plugins loaded at runtime via jars, and thus compiler components can be distributed indepedently of the central compiler.
Diffstat (limited to 'src/compiler/scala/tools/nsc/plugins/PluginDescription.scala')
-rw-r--r--src/compiler/scala/tools/nsc/plugins/PluginDescription.scala68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
new file mode 100644
index 0000000000..f7abda65aa
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
@@ -0,0 +1,68 @@
+package scala.tools.nsc.plugins
+import scala.xml.{Node,NodeSeq}
+import java.io.File
+
+/** A description of a compiler plugin, suitable for serialization
+ * to XML for inclusion in the plugin's .jar file.
+ *
+ * @author Lex Spoon
+ * @version 1.0, 2007-5-21
+ */
+abstract class PluginDescription {
+ /** A short name of the compiler, used to identify it in
+ * various contexts. The phase defined by the plugin
+ * should have the same name. */
+ val name: String
+
+
+ /** The name of the main class for the plugin */
+ val classname: String
+
+ /** An XML representation of this description. It can be
+ * read back using PluginDescription.fromXML . It should
+ * be stored inside the jor. */
+ def toXML: Node = {
+ <plugin>
+ <name>{name}</name>
+ <classname>{classname}</classname>
+ </plugin>
+ }
+}
+
+
+
+/** Utilities for the PluginDescription class.
+ *
+ * @author Lex Spoon
+ * @version 1.0, 2007-5-21
+ */
+object PluginDescription {
+ def fromXML(xml: Node): Option[PluginDescription] = {
+ // check the top-level tag
+ xml match {
+ case <plugin>{_*}</plugin> => ()
+ case _ => return None
+ }
+
+ /** Extract one field */
+ def getField(field: String): Option[String] = {
+ val text = (xml \\ field).text.trim
+ if (text == "") None else Some(text)
+ }
+
+ // extract the required fields
+ val name1 = getField("name") match {
+ case None => return None
+ case Some(str) => str
+ }
+ val classname1 = getField("classname") match {
+ case None => return None
+ case Some(str) => str
+ }
+
+ Some(new PluginDescription {
+ val name = name1
+ val classname = classname1
+ })
+ }
+}