8000 Avoid `sys.process`, use `java.lang.ProcessBuilder`. · scala/scala@9f0a931 · GitHub
[go: up one dir, main page]

Skip to cont 8000 ent

Commit 9f0a931

Browse files
committed
Avoid sys.process, use java.lang.ProcessBuilder.
1 parent d6debd4 commit 9f0a931

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/compiler/scala/tools/nsc/CompileSocket.scala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
package scala.tools.nsc
77

8-
import java.io.FileNotFoundException
8+
import java.io._
99
import java.security.SecureRandom
10-
import io.{ File, Path, Socket }
10+
11+
import io.{File, Path, Socket}
1112
import scala.tools.util.CompileOutputCommon
1213
import scala.reflect.internal.util.StringOps.splitWhere
13-
import scala.sys.process._
1414

1515
trait HasCompileSocket {
1616
def compileSocket: CompileSocket
@@ -92,15 +92,11 @@ class CompileSocket extends CompileOutputCommon {
9292
Seq(vmCommand) ++ vmArgs ++ Seq(serverClass) ++ serverClassArgs filterNot (_ == "")
9393

9494
/** Start a new server. */
95-
private def startNewServer(vmArgs: String) = {
95+
private def startNewServer(vmArgs: String): Unit = {
9696
val cmd = serverCommand((vmArgs split " ").toSeq)
97-
info("[Executing command: %s]" format cmd.mkString(" "))
97+
info(s"[Executing command: ${cmd.mkString(" ")}]")
9898

99-
// Hiding inadequate daemonized implementation from public API for now
100-
Process(cmd) match {
101-
case x: ProcessBuilder.AbstractBuilder => x.daemonized().run()
102-
case x => x.run()
103-
}
99+
new java.lang.ProcessBuilder(cmd.toArray: _*).inheritIO().start()
104100
}
105101

106102
/** The port identification file */

src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotRunner.scala

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import java.io.InputStreamReader
1010
import java.io.OutputStreamWriter
1111
import java.io.BufferedWriter
1212
import java.io.BufferedReader
13-
import scala.sys.process._
1413
import scala.concurrent.SyncVar
1514

1615
import model._
@@ -70,9 +69,9 @@ class DotRunner(settings: doc.Settings) {
7069

7170
class DotProcess(settings: doc.Settings) {
7271

73-
@ F5C2 volatile var error: Boolean = false // signal an error
74-
val inputString = new SyncVar[String] // used for the dot process input
75-
val outputString = new SyncVar[String] // used for the dot process output
72+
@volatile var error: Boolean = false // signal an error
73+
val inputString = new SyncVar[String] // used for the dot process input
74+
val outputString = new SyncVar[String] // used for the dot process output
7675
val errorBuffer: StringBuffer = new StringBuffer() // buffer used for both dot process error console AND logging
7776

7877
// set in only one place, in the main thread
@@ -86,12 +85,20 @@ class DotProcess(settings: doc.Settings) {
8685
templateInput = input
8786

8887
try {
89-
9088
// process creation
9189
if (process == null) {
92-
val procIO = new ProcessIO(inputFn(_), outputFn(_), errorFn(_))
93-
val processBuilder: ProcessBuilder = Seq(settings.docDiagramsDotPath.value, "-Tsvg")
94-
process = processBuilder.run(procIO)
90+
val processBuilder = new ProcessBuilder(settings.docDiagramsDotPath.value, "-Tsvg")
91+
process = processBuilder.start()
92+
93+
def spawn(f: Runnable): Unit = {
94+
val thread = new Thread(f)
95+
thread.setDaemon(true)
96+
thread.start()
97+
}
98+
99+
spawn { () => inputFn(process.getOutputStream()) }
100+
spawn { () => outputFn(process.getInputStream()) }
101+
spawn { () => errorFn(process.getErrorStream()) }
95102
}
96103

97104
// pass the input and wait for the output

0 commit comments

Comments
 (0)
0