fix factorio running check again??

This commit is contained in:
Adam 2022-04-24 21:01:16 +02:00
parent b4ba87e8e0
commit d79a30b1ec
2 changed files with 9 additions and 9 deletions

View file

@ -9,15 +9,11 @@ import org.gradle.process.ExecOperations
/** Checks if a process is running. Windows only. */
class ProcessRunningSpec(
private val executor: ExecOperations,
private val process: String,
private val ignoreCase: Boolean = true,
) : ExplainingSpec<Task> {
@Inject
fun executor(): ExecOperations {
throw UnsupportedOperationException()
}
override fun isSatisfiedBy(element: Task?): Boolean = whyUnsatisfied(element) == null
override fun whyUnsatisfied(element: Task?): String? {
@ -27,7 +23,7 @@ class ProcessRunningSpec(
else -> {
return ByteArrayOutputStream().use { outputStream ->
executor().exec {
executor.exec {
commandLine("tasklist") // Windows only for now...
standardOutput = outputStream
}

View file

@ -2,6 +2,7 @@ import dev.adamko.kafkatorio.gradle.asConsumer
import dev.adamko.kafkatorio.gradle.factorioModAttributes
import dev.adamko.kafkatorio.gradle.not
import dev.adamko.kafkatorio.task.ProcessRunningSpec
import org.gradle.kotlin.dsl.support.serviceOf
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
plugins {
@ -38,13 +39,14 @@ val deployModToClient by tasks.registering(Copy::class) {
//</editor-fold>
//<editor-fold desc="Factorio client lifecycle tasks">
fun isFactorioRunning(): Spec<Task> = ProcessRunningSpec("factorio.exe")
fun ExecOperations.isFactorioRunning(): Spec<Task> = ProcessRunningSpec(this, "factorio.exe")
val clientLaunch by tasks.registering(Exec::class) {
description = "Run Factorio Steam game client"
group = project.name
onlyIf(!isFactorioRunning())
onlyIf(!serviceOf<ExecOperations>().isFactorioRunning())
dependsOn(deployModToClient)
mustRunAfter(clientKill, ":modules:infra-factorio-server:processRun")
@ -60,7 +62,9 @@ val clientLaunch by tasks.registering(Exec::class) {
val clientKill by tasks.registering(Exec::class) {
description = "Run Factorio Steam game client"
group = project.name
onlyIf(isFactorioRunning())
onlyIf(serviceOf<ExecOperations>().isFactorioRunning())
commandLine = parseSpaceSeparatedArgs(""" taskkill /im factorio.exe """)
doFirst { logger.lifecycle("Killing factorio.exe") }
}