diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-02-11 23:49:57 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-02-11 23:49:57 +0100 |
commit | add9664c9f3a97ab3a4b7b3a4b9a3a578fca3d3d (patch) | |
tree | 1084b64cd756633b9e9d08b412a7bf946733325d | |
parent | ce52be13c641b23e3000ed4b86d1352f0318c27b (diff) | |
parent | b816a83c8c3ac3fac740e3f475e8e773d59b9d46 (diff) | |
download | scala-add9664c9f3a97ab3a4b7b3a4b9a3a578fca3d3d.tar.gz scala-add9664c9f3a97ab3a4b7b3a4b9a3a578fca3d3d.tar.bz2 scala-add9664c9f3a97ab3a4b7b3a4b9a3a578fca3d3d.zip |
Merge pull request #3454 from Ichoran/issue/5994
SI-5994 battling implicits for String.lines
-rw-r--r-- | src/library/scala/sys/process/ProcessBuilder.scala | 40 | ||||
-rw-r--r-- | src/library/scala/sys/process/ProcessBuilderImpl.scala | 10 |
2 files changed, 36 insertions, 14 deletions
diff --git a/src/library/scala/sys/process/ProcessBuilder.scala b/src/library/scala/sys/process/ProcessBuilder.scala index 88c0cf8e58..ac86495001 100644 --- a/src/library/scala/sys/process/ProcessBuilder.scala +++ b/src/library/scala/sys/process/ProcessBuilder.scala @@ -30,9 +30,7 @@ import ProcessBuilder._ * "ls".! * * // Execute "ls" and assign a `Stream[String]` of its output to "contents". - * // Because [[scala.Predef]] already defines a `lines` method for `String`, - * // we use [[scala.sys.process.Process]]'s object companion to create it. - * val contents = Process("ls").lines + * val contents = Process("ls").lineStream * * // Here we use a `Seq` to make the parameter whitespace-safe * def contentsOf(dir: String): String = Seq("ls", dir).!! @@ -82,11 +80,11 @@ import ProcessBuilder._ * of the last one in the chain of execution. * - `!!`: blocks until all external commands exit, and returns a `String` * with the output generated. - * - `lines`: returns immediately like `run`, and the output being generared + * - `lineStream`: returns immediately like `run`, and the output being generated * is provided through a `Stream[String]`. Getting the next element of that * `Stream` may block until it becomes available. This method will throw an * exception if the return code is different than zero -- if this is not - * desired, use the `lines_!` method. + * desired, use the `lineStream_!` method. * * ==Handling Input and Output== * @@ -131,6 +129,14 @@ import ProcessBuilder._ * * Note: though it is not shown above, the equivalent of a shell's `;` would be * `###`. The reason for this name is that `;` is a reserved token in Scala. + * + * Note: the `lines` method, though deprecated, may conflict with the `StringLike` + * method of the same name. To avoid this, one may wish to call the builders in + * `Process` instead of importing `scala.sys.process._`. The example above would be + * {{{ + * import scala.sys.process.Process + * Process("find src -name *.scala -exec grep null {} ;") #| Process("xargs test -z") #&& Process("echo null-free") #|| Process("echo null detected") ! + * }}} */ trait ProcessBuilder extends Source with Sink { /** Starts the process represented by this builder, blocks until it exits, and @@ -165,7 +171,11 @@ trait ProcessBuilder extends Source with Sink { * with a non-zero value, the Stream will provide all lines up to termination * and then throw an exception. */ - def lines: Stream[String] + def lineStream: Stream[String] + + /** Deprecated (renamed). Use `lineStream` instead. */ + @deprecated("Use lineStream instead.", "2.11.0") + def lines: Stream[String] = lineStream /** Starts the process represented by this builder. The output is returned as * a Stream that blocks when lines are not available but the process has not @@ -173,7 +183,11 @@ trait ProcessBuilder extends Source with Sink { * process exits with a non-zero value, the Stream will provide all lines up * to termination and then throw an exception. */ - def lines(log: ProcessLogger): Stream[String] + def lineStream(log: ProcessLogger): Stream[String] + + /** Deprecated (renamed). Use `lineStream(log: ProcessLogger)` instead. */ + @deprecated("Use stream instead.", "2.11.0") + def lines(log: ProcessLogger): Stream[String] = lineStream(log) /** Starts the process represented by this builder. The output is returned as * a Stream that blocks when lines are not available but the process has not @@ -181,7 +195,11 @@ trait ProcessBuilder extends Source with Sink { * with a non-zero value, the Stream will provide all lines up to termination * but will not throw an exception. */ - def lines_! : Stream[String] + def lineStream_! : Stream[String] + + /** Deprecated (renamed). Use `lineStream_!` instead. */ + @deprecated("Use lineStream_! instead.", "2.11.0") + def lines_! : Stream[String] = lineStream_! /** Starts the process represented by this builder. The output is returned as * a Stream that blocks when lines are not available but the process has not @@ -189,7 +207,11 @@ trait ProcessBuilder extends Source with Sink { * process exits with a non-zero value, the Stream will provide all lines up * to termination but will not throw an exception. */ - def lines_!(log: ProcessLogger): Stream[String] + def lineStream_!(log: ProcessLogger): Stream[String] + + /** Deprecated (renamed). Use `lineStream_!(log: ProcessLogger)` instead. */ + @deprecated("Use stream_! instead.", "2.11.0") + def lines_!(log: ProcessLogger): Stream[String] = lineStream_!(log) /** Starts the process represented by this builder, blocks until it exits, and * returns the exit code. Standard output and error are sent to the console. diff --git a/src/library/scala/sys/process/ProcessBuilderImpl.scala b/src/library/scala/sys/process/ProcessBuilderImpl.scala index adf6d1e724..236baaf038 100644 --- a/src/library/scala/sys/process/ProcessBuilderImpl.scala +++ b/src/library/scala/sys/process/ProcessBuilderImpl.scala @@ -104,10 +104,10 @@ private[process] trait ProcessBuilderImpl { def !!< = slurp(None, withIn = true) def !!<(log: ProcessLogger) = slurp(Some(log), withIn = true) - def lines: Stream[String] = lines(withInput = false, nonZeroException = true, None) - def lines(log: ProcessLogger): Stream[String] = lines(withInput = false, nonZeroException = true, Some(log)) - def lines_! : Stream[String] = lines(withInput = false, nonZeroException = false, None) - def lines_!(log: ProcessLogger): Stream[String] = lines(withInput = false, nonZeroException = false, Some(log)) + def lineStream: Stream[String] = lineStream(withInput = false, nonZeroException = true, None) + def lineStream(log: ProcessLogger): Stream[String] = lineStream(withInput = false, nonZeroException = true, Some(log)) + def lineStream_! : Stream[String] = lineStream(withInput = false, nonZeroException = false, None) + def lineStream_!(log: ProcessLogger): Stream[String] = lineStream(withInput = false, nonZeroException = false, Some(log)) def ! = run(connectInput = false).exitValue() def !(io: ProcessIO) = run(io).exitValue() @@ -132,7 +132,7 @@ private[process] trait ProcessBuilderImpl { else scala.sys.error("Nonzero exit value: " + code) } - private[this] def lines( + private[this] def lineStream( withInput: Boolean, nonZeroException: Boolean, log: Option[ProcessLogger] |