[Editor] Add some additional options (Cleaning/Terminating) to the Build main menu
This commit is contained in:
@@ -4,6 +4,7 @@ import javafx.beans.property.BooleanProperty
|
||||
import javafx.concurrent.Task
|
||||
|
||||
interface BuildPipelineService {
|
||||
fun build(): Task<Unit>
|
||||
val isRunningProperty: BooleanProperty
|
||||
fun build(): Task<Unit>
|
||||
fun clean()
|
||||
}
|
||||
@@ -51,6 +51,7 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
||||
|
||||
override fun build() = runAsync {
|
||||
latch?.locked?.takeIf { it }?.let {
|
||||
cancel()
|
||||
return@runAsync
|
||||
}
|
||||
|
||||
@@ -90,12 +91,16 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
||||
}
|
||||
|
||||
private fun prepareBuildDirectory(project: Project) {
|
||||
project.buildDirectory.delete()
|
||||
project.buildDirectory.deleteRecursively()
|
||||
|
||||
project.buildClassesDirectory.mkdirs()
|
||||
project.buildOutDirectory.mkdirs()
|
||||
}
|
||||
|
||||
override fun clean() {
|
||||
projectContext.project?.apply { buildDirectory.deleteRecursively() }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "Build"
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.bartlomiejpluta.base.editor.main.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.build.pipeline.BuildPipelineService
|
||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import com.bartlomiejpluta.base.editor.process.runner.app.ApplicationRunner
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import tornadofx.*
|
||||
|
||||
class MainMenuView : View() {
|
||||
@@ -57,7 +57,8 @@ class MainMenuView : View() {
|
||||
enableWhen(projectContext.projectProperty.isNotNull)
|
||||
|
||||
item("Compile") {
|
||||
enableWhen(buildPipelineService.isRunningProperty.not())
|
||||
enableWhen(buildPipelineService.isRunningProperty.not().and(applicationRunner.isRunningProperty.not()))
|
||||
|
||||
action {
|
||||
buildPipelineService.build()
|
||||
}
|
||||
@@ -65,10 +66,25 @@ class MainMenuView : View() {
|
||||
|
||||
item("Run") {
|
||||
enableWhen(applicationRunner.isRunningProperty.not())
|
||||
|
||||
action {
|
||||
applicationRunner.run()
|
||||
}
|
||||
}
|
||||
|
||||
item("Terminate") {
|
||||
enableWhen(applicationRunner.processProperty.isNotNull)
|
||||
|
||||
action {
|
||||
applicationRunner.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
item("Clean") {
|
||||
action {
|
||||
buildPipelineService.clean()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.bartlomiejpluta.base.editor.process.runner.app
|
||||
|
||||
import javafx.beans.binding.BooleanExpression
|
||||
import javafx.beans.property.ObjectProperty
|
||||
|
||||
interface ApplicationRunner {
|
||||
val isRunningProperty: BooleanExpression
|
||||
val processProperty: ObjectProperty<Process>
|
||||
fun run()
|
||||
fun terminate()
|
||||
}
|
||||
@@ -7,14 +7,12 @@ import com.bartlomiejpluta.base.editor.event.ClearProcessLogsEvent
|
||||
import com.bartlomiejpluta.base.editor.process.runner.jar.JarRunner
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.event.EventHandler
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
import tornadofx.*
|
||||
import tornadofx.FX.Companion.eventbus
|
||||
import tornadofx.getValue
|
||||
import tornadofx.runAsync
|
||||
import tornadofx.setValue
|
||||
import tornadofx.toProperty
|
||||
|
||||
@Component
|
||||
class DefaultApplicationRunner : ApplicationRunner {
|
||||
@@ -31,9 +29,12 @@ class DefaultApplicationRunner : ApplicationRunner {
|
||||
override val isRunningProperty = false.toProperty()
|
||||
private var isRunning by isRunningProperty
|
||||
|
||||
override val processProperty = SimpleObjectProperty<Process>()
|
||||
private var process by processProperty
|
||||
|
||||
override fun run() {
|
||||
projectContext.project?.let { project ->
|
||||
if (isRunning) {
|
||||
if (process != null) {
|
||||
return@let
|
||||
}
|
||||
|
||||
@@ -47,11 +48,15 @@ class DefaultApplicationRunner : ApplicationRunner {
|
||||
}
|
||||
}
|
||||
|
||||
override fun terminate() {
|
||||
process?.destroyForcibly()
|
||||
}
|
||||
|
||||
private fun runApplication(project: Project) {
|
||||
eventbus.fire(ClearProcessLogsEvent)
|
||||
|
||||
val builder = jarRunner.run(project.buildOutputJarFile)
|
||||
val process = builder.start()
|
||||
process = builder.start()
|
||||
|
||||
runAsync {
|
||||
process.inputStream.bufferedReader().forEachLine {
|
||||
@@ -67,6 +72,7 @@ class DefaultApplicationRunner : ApplicationRunner {
|
||||
|
||||
process.onExit().thenApply {
|
||||
eventbus.fire(AppendProcessLogsEvent(Severity.INFO, "\nProcess exited with code ${it.exitValue()}"))
|
||||
process = null
|
||||
isRunning = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user