From d8dfb6ec6334bfbf4f78fd97b8af2de8441cf7db Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 21 Jan 2011 05:02:52 +0000 Subject: A little debugging infrastructure for sys.process. --- src/library/scala/sys/process/package.scala | 63 ++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/sys/process/package.scala b/src/library/scala/sys/process/package.scala index 0185b1a8f0..9421bff88d 100644 --- a/src/library/scala/sys/process/package.scala +++ b/src/library/scala/sys/process/package.scala @@ -6,29 +6,52 @@ ** |/ ** \* */ -package scala.sys +// Developer note: +// scala -J-Dscala.process.debug +// for process debugging output. +// +package scala.sys { + package object process extends ProcessImplicits { + def javaVmArguments: List[String] = { + import collection.JavaConversions._ -package object process extends ProcessImplicits { - // These are in a nested object instead of at the package level - // due to the issues described in tickets #3160 and #3836. - private[process] object processInternal { - type =?>[-A, +B] = PartialFunction[A, B] - type Closeable = java.io.Closeable - type File = java.io.File - type IOException = java.io.IOException - type InputStream = java.io.InputStream - type JProcess = java.lang.Process - type JProcessBuilder = java.lang.ProcessBuilder - type OutputStream = java.io.OutputStream - type SyncVar[T] = scala.concurrent.SyncVar[T] - type URL = java.net.URL - - def onInterrupt[T](handler: => T): Throwable =?> T = { - case _: InterruptedException => handler + java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toList } + } + // private val shell: String => Array[String] = + // if (isWin) Array("cmd.exe", "/C", _) + // else Array("sh", "-c", _) + + package process { + // These are in a nested object instead of at the package level + // due to the issues described in tickets #3160 and #3836. + private[process] object processInternal { + final val processDebug = props contains "scala.process.debug" + // final val processDebug = true + dbg("Initializing process package.") + + type =?>[-A, +B] = PartialFunction[A, B] + type Closeable = java.io.Closeable + type File = java.io.File + type IOException = java.io.IOException + type InputStream = java.io.InputStream + type JProcess = java.lang.Process + type JProcessBuilder = java.lang.ProcessBuilder + type OutputStream = java.io.OutputStream + type SyncVar[T] = scala.concurrent.SyncVar[T] + type URL = java.net.URL + + def onInterrupt[T](handler: => T): Throwable =?> T = { + case _: InterruptedException => handler + } + + def ioFailure[T](handler: IOException => T): Throwable =?> T = { + case e: IOException => handler(e) + } - def ioFailure[T](handler: IOException => T): Throwable =?> T = { - case e: IOException => handler(e) + def dbg(msgs: Any*) = if (processDebug) { + Console.println("[process] " + (msgs mkString " ")) + } } } } -- cgit v1.2.3