mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-17 23:17:38 +00:00
Move some more build logic to buildSrc
Look, I don't enjoy having 600 LOC long build.gradle files, it's just very easy to do! This at least moves some of the complexity elsewhere, so the build script is a little more declarative.
This commit is contained in:
34
buildSrc/src/main/kotlin/cc/tweaked/gradle/ProcessHelpers.kt
Normal file
34
buildSrc/src/main/kotlin/cc/tweaked/gradle/ProcessHelpers.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package cc.tweaked.gradle
|
||||
|
||||
import org.codehaus.groovy.runtime.ProcessGroovyMethods
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
|
||||
internal object ProcessHelpers {
|
||||
fun startProcess(vararg command: String): Process {
|
||||
// Something randomly passes in "GIT_DIR=" as an environment variable which clobbers everything else. Don't
|
||||
// inherit the environment array!
|
||||
return Runtime.getRuntime().exec(command, arrayOfNulls(0))
|
||||
}
|
||||
|
||||
fun captureOut(vararg command: String): String {
|
||||
val process = startProcess(*command)
|
||||
val result = ProcessGroovyMethods.getText(process)
|
||||
if (process.waitFor() != 0) throw IOException("Command exited with a non-0 status")
|
||||
return result
|
||||
}
|
||||
|
||||
fun captureLines(vararg command: String): List<String> {
|
||||
return captureLines(startProcess(*command))
|
||||
}
|
||||
|
||||
fun captureLines(process: Process): List<String> {
|
||||
val out = BufferedReader(InputStreamReader(process.inputStream)).use { reader ->
|
||||
reader.lines().filter { it.isNotEmpty() }.toList()
|
||||
}
|
||||
ProcessGroovyMethods.closeStreams(process)
|
||||
if (process.waitFor() != 0) throw IOException("Command exited with a non-0 status")
|
||||
return out
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user