summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/plugins
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-06-19 17:02:27 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-06-20 15:46:25 -0700
commitedee7dbfce89841cecdba3996492d3741f9e803e (patch)
tree46888e80747bdf7cdfde8181c51b8038c1b98faf /src/compiler/scala/tools/nsc/plugins
parent739cc9d1ad8b7d1def468299c9cdc6e9ebb2d143 (diff)
downloadscala-edee7dbfce89841cecdba3996492d3741f9e803e.tar.gz
scala-edee7dbfce89841cecdba3996492d3741f9e803e.tar.bz2
scala-edee7dbfce89841cecdba3996492d3741f9e803e.zip
Remove dependency on xml in plugin loading.
Diffstat (limited to 'src/compiler/scala/tools/nsc/plugins')
-rw-r--r--src/compiler/scala/tools/nsc/plugins/Plugin.scala7
-rw-r--r--src/compiler/scala/tools/nsc/plugins/PluginDescription.scala63
2 files changed, 31 insertions, 39 deletions
diff --git a/src/compiler/scala/tools/nsc/plugins/Plugin.scala b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
index a584a4ed5d..4fd6ba7d9d 100644
--- a/src/compiler/scala/tools/nsc/plugins/Plugin.scala
+++ b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
@@ -14,7 +14,6 @@ import java.util.zip.ZipException
import scala.collection.mutable.ListBuffer
import scala.util.{ Try, Success, Failure }
-import scala.xml.XML
/** Information about a plugin loaded from a jar file.
*
@@ -81,14 +80,14 @@ object Plugin {
private def loadDescriptionFromJar(jarp: Path): Try[PluginDescription] = {
// XXX Return to this once we have more ARM support
def read(is: Option[InputStream]) = is match {
- case None => throw new RuntimeException(s"Missing $PluginXML in $jarp")
- case _ => PluginDescription fromXML (XML load is.get)
+ case None => throw new RuntimeException(s"Missing $PluginXML in $jarp")
+ case Some(is) => PluginDescription.fromXML(is)
}
Try(new Jar(jarp.jfile).withEntryStream(PluginXML)(read))
}
private def loadDescriptionFromFile(f: Path): Try[PluginDescription] =
- Try(XML loadFile f.jfile) map (PluginDescription fromXML _)
+ Try(PluginDescription.fromXML(new java.io.FileInputStream(f.jfile)))
type AnyClass = Class[_]
diff --git a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
index 27693d1a45..bf78c93fcc 100644
--- a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
+++ b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
@@ -6,57 +6,50 @@
package scala.tools.nsc
package plugins
-import scala.xml.Node
+import scala.reflect.internal.util.StringContextStripMarginOps
/** 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
- * @param name A short name of the plugin, used to identify it in
- * various contexts. The phase defined by the plugin
- * should have the same name.
- * @param classname The name of the main Plugin class.
+ * @author Adriaan Moors
+ * @version 2.0, 2013
+ * @param name A short name of the plugin, used to identify it in
+ * various contexts. The phase defined by the plugin
+ * should have the same name.
+ * @param classname The name of the main Plugin class.
*/
case class PluginDescription(name: String, classname: String) {
-
- /** An XML representation of this description. It can be
- * read back using `PluginDescription.fromXML`.
+ /** An XML representation of this description.
* It should be stored inside the jar archive file.
*/
- def toXML: Node = {
- <plugin>
- <name>{name}</name>
- <classname>{classname}</classname>
- </plugin>
- }
+ def toXML: String =
+ sm"""<plugin>
+ | <name>${name}</name>
+ | <classname>${classname}</classname>
+ |</plugin>"""
}
/** Utilities for the PluginDescription class.
*
- * @author Lex Spoon
- * @version 1.0, 2007-5-21
+ * @author Lex Spoon
+ * @version 1.0, 2007-5-21
+ * @author Adriaan Moors
+ * @version 2.0, 2013
*/
object PluginDescription {
+ private def text(ns: org.w3c.dom.NodeList): String =
+ if (ns.getLength == 1) ns.item(0).getTextContent.trim
+ else throw new RuntimeException("Bad plugin descriptor.")
+
+ def fromXML(xml: java.io.InputStream): PluginDescription = {
+ import javax.xml.parsers.DocumentBuilderFactory
+ val root = DocumentBuilderFactory.newInstance.newDocumentBuilder.parse(xml).getDocumentElement
+ root.normalize()
+ if (root.getNodeName != "plugin")
+ throw new RuntimeException("Plugin descriptor root element must be <plugin>.")
- def fromXML(xml: Node): PluginDescription = {
- // extract one field
- def getField(field: String): Option[String] = {
- val text = (xml \\ field).text.trim
- if (text == "") None else Some(text)
- }
- def extracted = {
- val name = "name"
- val claas = "classname"
- val vs = Map(name -> getField(name), claas -> getField(claas))
- if (vs.values exists (_.isEmpty)) fail()
- else PluginDescription(name = vs(name).get, classname = vs(claas).get)
- }
- def fail() = throw new RuntimeException("Bad plugin descriptor.")
- // check the top-level tag
- xml match {
- case <plugin>{_*}</plugin> => extracted
- case _ => fail()
- }
+ PluginDescription(text(root.getElementsByTagName("name")), text(root.getElementsByTagName("classname")))
}
}