~jan0sch/smederee
Showing details for patch 07de810915c900c08cb17a503451f1e5fa746aac.
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/ssh/DarcsSshCommand.scala new-smederee/modules/hub/src/main/scala/de/smederee/ssh/DarcsSshCommand.scala --- old-smederee/modules/hub/src/main/scala/de/smederee/ssh/DarcsSshCommand.scala 2025-02-02 00:54:21.491766761 +0000 +++ new-smederee/modules/hub/src/main/scala/de/smederee/ssh/DarcsSshCommand.scala 2025-02-02 00:54:21.491766761 +0000 @@ -45,6 +45,29 @@ @volatile protected var stderr: OutputStream = null @volatile protected var callback: ExitCallback = null + /** This method SHALL implement the custom logic for the ssh command. + * + * The `start` method MUST execute this within a [[java.lang.Thread]]! + * + * {{{ + * val thread = new Thread { + * override def run(): Unit = { + * val result = commandLogic(cmd) + * callback.onExit(result.exitCode) + * } + * } + * thread.start() + * }}} + * + * @param cmd + * A command that will be executed. + * @return + * The result of the given command. + * @todo + * De-couple this from the os-lib sometime in the future. + */ + protected def commandLogic(cmd: os.proc): os.CommandResult + override def destroy(channel: ChannelSession): Unit = () override def setErrorStream(errorStream: OutputStream): Unit = this.stderr = errorStream override def setExitCallback(callback: ExitCallback): Unit = this.callback = callback @@ -74,6 +97,23 @@ ) extends DarcsSshCommand { private val log = LoggerFactory.getLogger(classOf[DarcsApply]) + override protected def commandLogic(cmd: os.proc): os.CommandResult = { + val workingDirectory = darcsConfiguration.repositoriesDirectory.toPath + log.debug(s"DarcsApply: calling command: $cmd in directory $workingDirectory.") + cmd.call( + cwd = os.Path(workingDirectory), + stdin = this.stdin, + stdout = os.ProcessOutput { (bytes, _) => + log.trace("DarcsApply: STDOUT: {}", new String(bytes, "UTF-8")) + this.stdout.write(bytes) + }, + stderr = os.ProcessOutput { (bytes, _) => + log.trace("DarcsApply: STDERR: {}", new String(bytes, "UTF-8")) + this.stderr.write(bytes) + } + ) + } + override def start(channel: ChannelSession, env: Environment): Unit = { log.debug(s"DarcsApply for $owner/$repository") val repoDir = Paths.get(owner.toString, repository.toString) @@ -83,12 +123,13 @@ else List("apply", "--all", "--repodir", repoDir.toString) val cmd = os.proc(darcsConfiguration.executable.toString, options) - cmd.spawn( - cwd = os.Path(darcsConfiguration.repositoriesDirectory.toPath), - stdin = os.ProcessInput.makeSourceInput(this.stdin), - stdout = os.ProcessOutput((bytes, _) => this.stdout.write(bytes)), - stderr = os.ProcessOutput((bytes, _) => this.stderr.write(bytes)) - ) + val thread = new Thread { + override def run(): Unit = { + val result = commandLogic(cmd) + callback.onExit(result.exitCode) + } + } + thread.start() } } @@ -109,6 +150,23 @@ ) extends DarcsSshCommand { private val log = LoggerFactory.getLogger(classOf[DarcsTransferMode]) + override protected def commandLogic(cmd: os.proc): os.CommandResult = { + val workingDirectory = darcsConfiguration.repositoriesDirectory.toPath + log.debug(s"DarcsTransferMode: calling command: $cmd in directory $workingDirectory.") + cmd.call( + cwd = os.Path(workingDirectory), + stdin = this.stdin, + stdout = os.ProcessOutput { (bytes, _) => + log.trace("DarcsTransferMode: STDOUT: {}", new String(bytes, "UTF-8")) + this.stdout.write(bytes) + }, + stderr = os.ProcessOutput { (bytes, _) => + log.trace("DarcsTransferMode: STDERR: {}", new String(bytes, "UTF-8")) + this.stderr.write(bytes) + } + ) + } + override def start(channel: ChannelSession, env: Environment): Unit = { log.debug(s"DarcsTransferMode for $owner/$repository") val repoDir = Paths.get(owner.toString, repository.toString) @@ -116,12 +174,13 @@ darcsConfiguration.executable.toString, List("transfer-mode", "--repodir", repoDir.toString) ) - cmd.spawn( - cwd = os.Path(darcsConfiguration.repositoriesDirectory.toPath), - stdin = os.ProcessInput.makeSourceInput(this.stdin), - stdout = os.ProcessOutput((bytes, _) => this.stdout.write(bytes)), - stderr = os.ProcessOutput((bytes, _) => this.stderr.write(bytes)) - ) + val thread = new Thread { + override def run(): Unit = { + val result = commandLogic(cmd) + callback.onExit(result.exitCode) + } + } + thread.start() } }