[Editor] Make build pipeline can be run only one at the same time

This commit is contained in:
2021-02-26 15:59:34 +01:00
parent 95238b7e5b
commit 6971780f05
3 changed files with 28 additions and 5 deletions

View File

@@ -1,7 +1,9 @@
package com.bartlomiejpluta.base.editor.code.build.pipeline package com.bartlomiejpluta.base.editor.code.build.pipeline
import javafx.beans.property.BooleanProperty
import javafx.concurrent.Task import javafx.concurrent.Task
interface BuildPipelineService { interface BuildPipelineService {
fun build(): Task<Unit> fun build(): Task<Unit>
val isRunningProperty: BooleanProperty
} }

View File

@@ -10,10 +10,11 @@ import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent.Severity.
import com.bartlomiejpluta.base.editor.event.ClearCompilationLogEvent import com.bartlomiejpluta.base.editor.event.ClearCompilationLogEvent
import com.bartlomiejpluta.base.editor.project.context.ProjectContext import com.bartlomiejpluta.base.editor.project.context.ProjectContext
import com.bartlomiejpluta.base.editor.project.model.Project import com.bartlomiejpluta.base.editor.project.model.Project
import javafx.beans.property.SimpleObjectProperty
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import tornadofx.*
import tornadofx.FX.Companion.eventbus import tornadofx.FX.Companion.eventbus
import tornadofx.runAsync
import java.io.File import java.io.File
@Component @Component
@@ -34,16 +35,35 @@ class DefaultBuildPipelineService : BuildPipelineService {
@Autowired @Autowired
private lateinit var projectContext: ProjectContext private lateinit var projectContext: ProjectContext
// FIXME private val latchProperty = SimpleObjectProperty<Latch?>()
// There is runAsync used right here, however it does not prevent from private var latch by latchProperty
// multiple pipeline running. There should be some kind of assertion
// that enforces the pipeline to run only once in the same time. override val isRunningProperty = false.toProperty()
private var isRunning by isRunningProperty
init {
latchProperty.addListener { _, _, latch ->
when (latch) {
null -> isRunning = false
else -> isRunningProperty.bind(latch.lockedProperty())
}
}
}
override fun build() = runAsync { override fun build() = runAsync {
latch?.locked?.takeIf { it }?.let {
return@runAsync
}
latch = Latch()
try { try {
projectContext.project?.let(this@DefaultBuildPipelineService::runPipeline) projectContext.project?.let(this@DefaultBuildPipelineService::runPipeline)
} catch (e: BuildException) { } catch (e: BuildException) {
val event = AppendCompilationLogEvent(e.severity, e.message, e.location, e.tag) val event = AppendCompilationLogEvent(e.severity, e.message, e.location, e.tag)
eventbus.fire(event) eventbus.fire(event)
} finally {
latch?.release()
} }
Unit Unit

View File

@@ -56,6 +56,7 @@ class MainMenuView : View() {
enableWhen(projectContext.projectProperty.isNotNull) enableWhen(projectContext.projectProperty.isNotNull)
item("Compile") { item("Compile") {
enableWhen(buildPipelineService.isRunningProperty.not())
action { action {
buildPipelineService.build() buildPipelineService.build()
} }