Skip to content

Commit 9b2a6b8

Browse files
committed
Remove dependency on xml in sys.process.
Added deprecated conversions in xml.Elem to preserve source compatibility.
1 parent d7b5275 commit 9b2a6b8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/library/scala/xml/Elem.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,31 @@ object Elem {
3535
case _: SpecialNode | _: Group => None
3636
case _ => Some((n.prefix, n.label, n.attributes, n.scope, n.child))
3737
}
38+
39+
import scala.sys.process._
40+
/** Implicitly convert a [[scala.xml.Elem]] into a
41+
* [[scala.sys.process.ProcessBuilder]]. This is done by obtaining the text
42+
* elements of the element, trimming spaces, and then converting the result
43+
* from string to a process. Importantly, tags are completely ignored, so
44+
* they cannot be used to separate parameters.
45+
*/
46+
@deprecated("To create a scala.sys.process.Process from an xml.Elem, please use Process(elem.text.trim).", "2.11.0")
47+
implicit def xmlToProcess(command: scala.xml.Elem): ProcessBuilder = Process(command.text.trim)
48+
49+
@deprecated("To create a scala.sys.process.Process from an xml.Elem, please use Process(elem.text.trim).", "2.11.0")
50+
implicit def processXml(p: Process.type) = new {
51+
/** Creates a [[scala.sys.process.ProcessBuilder]] from a Scala XML Element.
52+
* This can be used as a way to template strings.
53+
*
54+
* @example {{{
55+
* apply(<x> {dxPath.absolutePath} --dex --output={classesDexPath.absolutePath} {classesMinJarPath.absolutePath}</x>)
56+
* }}}
57+
*/
58+
def apply(command: Elem): ProcessBuilder = Process(command.text.trim)
59+
}
3860
}
3961

62+
4063
/** The case class `Elem` extends the `Node` class,
4164
* providing an immutable data object representing an XML element.
4265
*

0 commit comments

Comments
 (0)