Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pablf committed Feb 16, 2024
1 parent 551277d commit 8f81f26
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,33 @@ private[process] trait ProcessPlatformSpecific extends ProcessInterface { self:
import ProcessPlatformSpecific._

private var killed = false
/*self.process.on("exit", { (_: js.Dynamic) =>
alive = false
})*/

def waitForUnsafe: Int = self.process.exitCode
protected def waitForUnsafe: Int = self.process.exitCode

def isAliveUnsafe: Boolean = !killed
def destroyUnsafe(): Unit = {
protected def isAliveUnsafe: Boolean = !killed
protected def destroyUnsafe(): Unit = {
val wasKilled = self.process.kill()
killed = wasKilled
}

def destroyForciblyUnsafe: JProcess = {
protected def destroyForciblyUnsafe: JProcess = {
self.process.kill()
self.process
}

def pidUnsafe: Long = {
protected def pidUnsafe: Long = {
val pid = self.process.pid
if (js.isUndefined(pid)) null.asInstanceOf[Long] else pid.asInstanceOf[Int].toLong
}

lazy val stdinInternal = ProcessPlatformSpecific.JSOutputStream(self.process.stdin)
lazy val stdoutInternal = ProcessPlatformSpecific.JSInputStream(self.process.stdout)
lazy val stderrInternal = ProcessPlatformSpecific.JSInputStream(self.process.stderr)
def getInputStream: InputStream = stdoutInternal
def getOutputStream: OutputStream = stdinInternal
def getErrorStream: InputStream = stderrInternal
protected lazy val stdinInternal = ProcessPlatformSpecific.JSOutputStream(self.process.stdin)
protected lazy val stdoutInternal = ProcessPlatformSpecific.JSInputStream(self.process.stdout)
protected lazy val stderrInternal = ProcessPlatformSpecific.JSInputStream(self.process.stderr)
protected def getInputStream: InputStream = stdoutInternal
protected def getOutputStream: OutputStream = stdinInternal
protected def getErrorStream: InputStream = stderrInternal

def get: Option[OutputStream] = Some(stdinInternal)
protected def get: Option[OutputStream] = Some(stdinInternal)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ private[process] trait ProcessPlatformSpecific { self: Process =>

import ProcessPlatformSpecific._

def waitForUnsafe: Int = self.process.waitFor()
protected def waitForUnsafe: Int = self.process.waitFor()

def isAliveUnsafe: Boolean = self.process.isAlive()
def destroyUnsafe(): Unit = self.process.destroy()
def destroyForciblyUnsafe: JProcess = self.process.destroyForcibly()
protected def isAliveUnsafe: Boolean = self.process.isAlive()
protected def destroyUnsafe(): Unit = self.process.destroy()
protected def destroyForciblyUnsafe: JProcess = self.process.destroyForcibly()

def pidUnsafe: Long = self.process.pid
protected def pidUnsafe: Long = self.process.pid

def getInputStream: InputStream = self.process.getInputStream()
def getOutputStream: OutputStream = self.process.getOutputStream()
def getErrorStream: InputStream = self.process.getErrorStream()
def get: Option[OutputStream] = None
protected def getInputStream: InputStream = self.process.getInputStream()
protected def getOutputStream: OutputStream = self.process.getOutputStream()
protected def getErrorStream: InputStream = self.process.getErrorStream()
protected def get: Option[OutputStream] = None

def destroyHandle(handle: ProcessHandle): Boolean = handle.destroy()
def destroyForciblyHandle(handle: ProcessHandle): Boolean = handle.destroyForcibly()
def isAliveHandle(handle: ProcessHandle): Boolean = handle.isAlive()
def onExitHandle(handle: ProcessHandle) = handle.onExit()
protected def destroyHandle(handle: ProcessHandle): Boolean = handle.destroy()
protected def destroyForciblyHandle(handle: ProcessHandle): Boolean = handle.destroyForcibly()
protected def isAliveHandle(handle: ProcessHandle): Boolean = handle.isAlive()
protected def onExitHandle(handle: ProcessHandle) = handle.onExit()

/**
* Kills the entire process tree and will wait until completed. Equivalent to SIGTERM on Unix platforms.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ private[process] trait ProcessPlatformSpecific { self: Process =>

import ProcessPlatformSpecific._

def waitForUnsafe: Int = self.process.waitFor()
protected def waitForUnsafe: Int = self.process.waitFor()

def isAliveUnsafe: Boolean = self.process.isAlive()
def destroyUnsafe(): Unit = self.process.destroy()
def destroyForciblyUnsafe: JProcess = self.process.destroyForcibly()
protected def isAliveUnsafe: Boolean = self.process.isAlive()
protected def destroyUnsafe(): Unit = self.process.destroy()
protected def destroyForciblyUnsafe: JProcess = self.process.destroyForcibly()

def pidUnsafe: Long = findFirstNumber(self.process.toString()).toLong
protected def pidUnsafe: Long = findFirstNumber(self.process.toString()).toLong

private def findFirstNumber(str: String): String =
str.headOption match {
Expand All @@ -45,10 +45,10 @@ private[process] trait ProcessPlatformSpecific { self: Process =>
case Some(c) => if (!c.isDigit) "" else s"$c${getFirstNumber(str.tail)}"
}

def getInputStream: InputStream = self.process.getInputStream()
def getOutputStream: OutputStream = self.process.getOutputStream()
def getErrorStream: InputStream = self.process.getErrorStream()
def get: Option[OutputStream] = Some(getOutputStream)
protected def getInputStream: InputStream = self.process.getInputStream()
protected def getOutputStream: OutputStream = self.process.getOutputStream()
protected def getErrorStream: InputStream = self.process.getErrorStream()
protected def get: Option[OutputStream] = Some(getOutputStream)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import ProcessPlatformSpecific._

private[process] trait ProcessInterface {

def waitForUnsafe: Int
protected def waitForUnsafe: Int

def isAliveUnsafe: Boolean
def destroyUnsafe(): Unit
def destroyForciblyUnsafe: JProcess
protected def isAliveUnsafe: Boolean
protected def destroyUnsafe(): Unit
protected def destroyForciblyUnsafe: JProcess

def pidUnsafe: Long
protected def pidUnsafe: Long

}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ object CommandSpec extends ZIOProcessBaseSpec with SpecProperties {
_ <- commandQueue.offer(Chunk.fromArray(s"process.exit(0)${sep}".getBytes(StandardCharsets.UTF_8)))
_ <- fiber.join
} yield assertCompletes
} @@ TestAspect.withLiveClock @@ TestAspect.jvmOnly,
} @@ TestAspect.withLiveClock @@ TestAspect.exceptJS,
test("get pid of a running process") {
for {
process <- Command("ls").run
Expand Down

0 comments on commit 8f81f26

Please sign in to comment.