move processbuilder into service

master
Josha von Gizycki 4 weeks ago
parent 6f4326502c
commit fc284607a7

@ -10,7 +10,8 @@ import java.util.concurrent.TimeUnit
class GitRunner(
val builds: Builds,
val handles: Handles,
val workspaces: Workspaces
val workspaces: Workspaces,
val processes: Processes
) {
val scriptsDir = ".alfred"
@ -42,7 +43,7 @@ class GitRunner(
private fun clone(ctx: BuildContext, wsPath: Path) {
logger.info("build ${ctx.buildId}: cloning ${ctx.config.gitRepo} into $wsPath")
val process = processBuilder(ctx.config, ctx.logFile, "")
val process = processes.builder(ctx.config, ctx.logFile, "")
.command("git", "clone", ctx.config.gitRepo, ".")
.directory(wsPath.toFile())
.start()
@ -50,7 +51,7 @@ class GitRunner(
val cloneSuccess = process.waitFor(ctx.config.gitCloneTimeout, TimeUnit.SECONDS)
logger.info("build ${ctx.buildId}: checkout rev ${ctx.rev}")
processBuilder(ctx.config, ctx.logFile, "")
processes.builder(ctx.config, ctx.logFile, "")
.command("git", "checkout", ctx.rev)
.directory(wsPath.toFile())
.start()
@ -73,7 +74,7 @@ class GitRunner(
ctx.logFile.append("\nRunning build file: $script\n")
val scriptProcess = processBuilder(ctx.config, ctx.logFile, ctx.rev)
val scriptProcess = processes.builder(ctx.config, ctx.logFile, ctx.rev)
.command(scriptFile.absolutePath)
.directory(wsPath.toFile())
.start()

@ -0,0 +1,18 @@
package alfred.web.core
import org.springframework.stereotype.Service
@Service
class Processes {
fun builder(config: BuildConfig, logFile: LogFile, rev: String): ProcessBuilder =
ProcessBuilder()
.redirectOutput(ProcessBuilder.Redirect.appendTo(logFile.backingFile))
.redirectError(ProcessBuilder.Redirect.appendTo(logFile.backingFile))
.apply {
environment().putAll(config.env)
environment()["ALFRED_LOG_FILE"] = logFile.backingFile.absolutePath
environment()["ALFRED_REV"] = rev
}
}

@ -9,7 +9,8 @@ import java.nio.file.Paths
@Service
class ScriptRunner(
val builds: Builds,
val handles: Handles
val handles: Handles,
val processes: Processes
) {
fun run(buildId: BuildId, rev: String): ProcessInfo {
@ -21,7 +22,7 @@ class ScriptRunner(
logFile.header(buildId, rev, Paths.get(config.gitWorkspace))
val process = processBuilder(config, logFile, rev)
val process = processes.builder(config, logFile, rev)
.command(config.script)
.start()
handles.add(Handle(process.toHandle(), buildId))

@ -1,11 +0,0 @@
package alfred.web.core
fun processBuilder(config: BuildConfig, logFile: LogFile, rev: String): ProcessBuilder =
ProcessBuilder()
.redirectOutput(ProcessBuilder.Redirect.appendTo(logFile.backingFile))
.redirectError(ProcessBuilder.Redirect.appendTo(logFile.backingFile))
.apply {
environment().putAll(config.env)
environment()["ALFRED_LOG_FILE"] = logFile.backingFile.absolutePath
environment()["ALFRED_REV"] = rev
}
Loading…
Cancel
Save