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