You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
package alfred.running
|
|
|
|
import alfred.BuildConfig
|
|
import alfred.BuildId
|
|
import java.io.File
|
|
import java.nio.file.Path
|
|
import java.time.ZonedDateTime
|
|
|
|
fun processBuilder(config: BuildConfig, logFile: File, rev: String): ProcessBuilder =
|
|
ProcessBuilder()
|
|
.redirectOutput(ProcessBuilder.Redirect.appendTo(logFile))
|
|
.redirectError(ProcessBuilder.Redirect.appendTo(logFile))
|
|
.apply {
|
|
environment().putAll(config.env)
|
|
environment()["ALFRED_LOG_FILE"] = logFile.absolutePath
|
|
environment()["ALFRED_REV"] = rev
|
|
}
|
|
|
|
typealias LogFile = File
|
|
|
|
fun LogFile.header(buildId: BuildId, rev: String, workspace: Path) {
|
|
this.append("At your service.")
|
|
this.append("Build $buildId, rev [$rev] started at ${ZonedDateTime.now()}")
|
|
this.append("Workspace directory is: $workspace\n")
|
|
}
|
|
|
|
fun LogFile.footer() {
|
|
this.append("Build finished at ${ZonedDateTime.now()}")
|
|
}
|
|
|
|
fun LogFile.append(content: String) =
|
|
this.appendText(
|
|
content.lines().joinToString(separator = "\n") {
|
|
if (it.trim().isEmpty()) {
|
|
""
|
|
} else {
|
|
"Alfred: $it"
|
|
}
|
|
} + "\n"
|
|
)
|