[Editor] Make Compilation Logs generic as Logs Pane
This commit is contained in:
@@ -3,9 +3,8 @@ package com.bartlomiejpluta.base.editor.code.build.compiler
|
|||||||
import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
||||||
import com.bartlomiejpluta.base.editor.code.build.model.ClasspathResource
|
import com.bartlomiejpluta.base.editor.code.build.model.ClasspathResource
|
||||||
import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||||
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent.Severity.ERROR
|
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent.Severity.WARNING
|
|
||||||
import org.codehaus.commons.compiler.CompileException
|
import org.codehaus.commons.compiler.CompileException
|
||||||
import org.codehaus.commons.compiler.util.resource.FileResource
|
import org.codehaus.commons.compiler.util.resource.FileResource
|
||||||
import org.codehaus.commons.compiler.util.resource.Resource
|
import org.codehaus.commons.compiler.util.resource.Resource
|
||||||
@@ -39,7 +38,7 @@ class JaninoCompiler : Compiler {
|
|||||||
val locationIndex = e.location?.toString()?.length?.plus(2) ?: 0
|
val locationIndex = e.location?.toString()?.length?.plus(2) ?: 0
|
||||||
val message = e.message?.substring(locationIndex)
|
val message = e.message?.substring(locationIndex)
|
||||||
|
|
||||||
throw BuildException(ERROR, "Compiler", e.location, message, e)
|
throw BuildException(Severity.ERROR, "Compiler", e.location, message, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryToCompile(sourceDirectory: FileSystemNode, targetDirectory: File) {
|
private fun tryToCompile(sourceDirectory: FileSystemNode, targetDirectory: File) {
|
||||||
@@ -49,7 +48,7 @@ class JaninoCompiler : Compiler {
|
|||||||
setDestinationDirectory(targetDirectory, false)
|
setDestinationDirectory(targetDirectory, false)
|
||||||
|
|
||||||
setWarningHandler { handle, message, location ->
|
setWarningHandler { handle, message, location ->
|
||||||
eventbus.fire(AppendCompilationLogEvent(WARNING, "$message ($handle)", location, "Compiler"))
|
eventbus.fire(AppendCompilationLogEvent(Severity.WARNING, "$message ($handle)", location, "Compiler"))
|
||||||
}
|
}
|
||||||
|
|
||||||
compile(compilationUnits)
|
compile(compilationUnits)
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.build.exception
|
package com.bartlomiejpluta.base.editor.code.build.exception
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
import org.codehaus.commons.compiler.Location
|
import org.codehaus.commons.compiler.Location
|
||||||
|
|
||||||
class BuildException(
|
class BuildException(
|
||||||
val severity: AppendCompilationLogEvent.Severity,
|
val severity: Severity,
|
||||||
val tag: String,
|
val tag: String,
|
||||||
val location: Location?,
|
val location: Location?,
|
||||||
message: String?,
|
message: String?,
|
||||||
override val cause: Throwable
|
override val cause: Throwable
|
||||||
) : Exception() {
|
) : Exception() {
|
||||||
constructor(severity: AppendCompilationLogEvent.Severity, tag: String, message: String?, cause: Throwable)
|
constructor(severity: Severity, tag: String, message: String?, cause: Throwable)
|
||||||
: this(severity, tag, null, message, cause)
|
: this(severity, tag, null, message, cause)
|
||||||
|
|
||||||
override val message = message ?: ""
|
override val message = message ?: ""
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.build.game
|
package com.bartlomiejpluta.base.editor.code.build.game
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent.Severity.ERROR
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ class DefaultGameEngineProvider : GameEngineProvider {
|
|||||||
try {
|
try {
|
||||||
tryToProvide(targetJar)
|
tryToProvide(targetJar)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw BuildException(ERROR, "Engine Provider", e.message, e)
|
throw BuildException(Severity.ERROR, "Engine Provider", e.message, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
|||||||
import com.bartlomiejpluta.base.editor.code.build.game.GameEngineProvider
|
import com.bartlomiejpluta.base.editor.code.build.game.GameEngineProvider
|
||||||
import com.bartlomiejpluta.base.editor.code.build.packager.JarPackager
|
import com.bartlomiejpluta.base.editor.code.build.packager.JarPackager
|
||||||
import com.bartlomiejpluta.base.editor.code.build.project.ProjectAssembler
|
import com.bartlomiejpluta.base.editor.code.build.project.ProjectAssembler
|
||||||
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent.Severity.INFO
|
|
||||||
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
|
||||||
@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired
|
|||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
import tornadofx.FX.Companion.eventbus
|
import tornadofx.FX.Companion.eventbus
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class DefaultBuildPipelineService : BuildPipelineService {
|
class DefaultBuildPipelineService : BuildPipelineService {
|
||||||
@@ -73,21 +72,21 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
|||||||
eventbus.fire(ClearCompilationLogEvent)
|
eventbus.fire(ClearCompilationLogEvent)
|
||||||
prepareBuildDirectory(project)
|
prepareBuildDirectory(project)
|
||||||
|
|
||||||
val outputFile = File(project.buildOutDirectory, OUTPUT_JAR_NAME)
|
val outputFile = project.buildOutputJarFile
|
||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
|
|
||||||
eventbus.fire(AppendCompilationLogEvent(INFO, "Compiling sources...", tag = TAG))
|
eventbus.fire(AppendCompilationLogEvent(Severity.INFO, "Compiling sources...", tag = TAG))
|
||||||
compiler.compile(project.codeFSNode, project.buildClassesDirectory)
|
compiler.compile(project.codeFSNode, project.buildClassesDirectory)
|
||||||
|
|
||||||
eventbus.fire(AppendCompilationLogEvent(INFO, "Assembling game engine...", tag = TAG))
|
eventbus.fire(AppendCompilationLogEvent(Severity.INFO, "Assembling game engine...", tag = TAG))
|
||||||
engineProvider.provideBaseGameEngine(outputFile)
|
engineProvider.provideBaseGameEngine(outputFile)
|
||||||
|
|
||||||
eventbus.fire(AppendCompilationLogEvent(INFO, "Assembling project assets...", tag = TAG))
|
eventbus.fire(AppendCompilationLogEvent(Severity.INFO, "Assembling project assets...", tag = TAG))
|
||||||
packager.pack(project.buildClassesDirectory, outputFile, "BOOT-INF/classes")
|
packager.pack(project.buildClassesDirectory, outputFile, "BOOT-INF/classes")
|
||||||
projectAssembler.assembly(project, outputFile)
|
projectAssembler.assembly(project, outputFile)
|
||||||
|
|
||||||
val buildingTime = (System.currentTimeMillis() - startTime) / 1000.0
|
val buildingTime = (System.currentTimeMillis() - startTime) / 1000.0
|
||||||
eventbus.fire(AppendCompilationLogEvent(INFO, "Done [${buildingTime}s]", tag = TAG))
|
eventbus.fire(AppendCompilationLogEvent(Severity.INFO, "Done [${buildingTime}s]", tag = TAG))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareBuildDirectory(project: Project) {
|
private fun prepareBuildDirectory(project: Project) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.bartlomiejpluta.base.editor.code.build.project
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
||||||
import com.bartlomiejpluta.base.editor.code.build.packager.JarPackager
|
import com.bartlomiejpluta.base.editor.code.build.packager.JarPackager
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
@@ -18,7 +18,7 @@ class DefaultProjectAssembler : ProjectAssembler {
|
|||||||
try {
|
try {
|
||||||
tryToAssembly(project, targetJar)
|
tryToAssembly(project, targetJar)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw BuildException(AppendCompilationLogEvent.Severity.ERROR, "Project Assembler", e.message, e)
|
throw BuildException(Severity.ERROR, "Project Assembler", e.message, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.component
|
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.code.stylesheet.CompilerLogsStylesheet
|
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
|
||||||
import javafx.scene.Cursor
|
|
||||||
import javafx.scene.layout.StackPane
|
|
||||||
import javafx.scene.paint.Color
|
|
||||||
import javafx.scene.text.Text
|
|
||||||
import org.codehaus.commons.compiler.Location
|
|
||||||
import org.fxmisc.richtext.StyledTextArea
|
|
||||||
import tornadofx.addClass
|
|
||||||
|
|
||||||
class CompilationLogs(private val locationClick: (location: Location) -> Unit) : StackPane() {
|
|
||||||
private val editor = StyledTextArea("compiler-logs",
|
|
||||||
{ text, style -> text.addClass(style) },
|
|
||||||
CompilationLogStyle.NO_STYLE,
|
|
||||||
{ text, style -> style.apply(text) }
|
|
||||||
).apply { isEditable = false }
|
|
||||||
|
|
||||||
init {
|
|
||||||
children += editor
|
|
||||||
}
|
|
||||||
|
|
||||||
fun appendEntry(message: String, severity: AppendCompilationLogEvent.Severity, location: Location?, tag: String?) {
|
|
||||||
val locationRef = CompilationLogStyle(location = location, onClick = locationClick)
|
|
||||||
val severityStyle = CompilationLogStyle(severity = severity)
|
|
||||||
|
|
||||||
tag?.let { editor.insert(editor.length, "[$it] ", severityStyle) }
|
|
||||||
editor.insert(editor.length, location?.toString() ?: "", locationRef)
|
|
||||||
editor.insert(editor.length, (location?.let { ": " } ?: "") + message, CompilationLogStyle(severity = severity))
|
|
||||||
editor.insert(editor.length, "\n", CompilationLogStyle.NO_STYLE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clear() = editor.clear()
|
|
||||||
|
|
||||||
override fun getUserAgentStylesheet(): String = CompilerLogsStylesheet().base64URL.toExternalForm()
|
|
||||||
|
|
||||||
class CompilationLogStyle(
|
|
||||||
private val location: Location? = null,
|
|
||||||
private val severity: AppendCompilationLogEvent.Severity? = null,
|
|
||||||
private val onClick: (Location) -> Unit = {}
|
|
||||||
) {
|
|
||||||
|
|
||||||
fun apply(text: Text) = when {
|
|
||||||
severity != null -> message(text, severity)
|
|
||||||
location != null -> location(text, location)
|
|
||||||
else -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun message(text: Text, severity: AppendCompilationLogEvent.Severity) {
|
|
||||||
text.fill = when (severity) {
|
|
||||||
AppendCompilationLogEvent.Severity.WARNING -> Color.ORANGE
|
|
||||||
AppendCompilationLogEvent.Severity.ERROR -> Color.RED
|
|
||||||
AppendCompilationLogEvent.Severity.INFO -> text.fill
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun location(text: Text, location: Location) {
|
|
||||||
text.cursor = Cursor.HAND
|
|
||||||
text.fill = Color.BLUE
|
|
||||||
text.isUnderline = true
|
|
||||||
text.setOnMouseClicked {
|
|
||||||
onClick(location)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val NO_STYLE = CompilationLogStyle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.view
|
package com.bartlomiejpluta.base.editor.code.view
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.code.component.CompilationLogs
|
import com.bartlomiejpluta.base.editor.common.logs.component.LogsPane
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.event.AppendCompilationLogEvent
|
||||||
import com.bartlomiejpluta.base.editor.event.ClearCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.event.ClearCompilationLogEvent
|
||||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||||
@@ -15,7 +15,7 @@ class CompilerLogsView : View() {
|
|||||||
private val projectContext: ProjectContext by di()
|
private val projectContext: ProjectContext by di()
|
||||||
private val mainController: MainController by di()
|
private val mainController: MainController by di()
|
||||||
|
|
||||||
private val compilationLogs = CompilationLogs(this::locationClick)
|
private val compilationLogs = LogsPane(this::locationClick)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
subscribe<AppendCompilationLogEvent> { event ->
|
subscribe<AppendCompilationLogEvent> { event ->
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.common.logs.component
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
|
import com.bartlomiejpluta.base.editor.common.logs.style.LogsPaneStyle
|
||||||
|
import com.bartlomiejpluta.base.editor.common.logs.stylesheet.LogsPaneStylesheet
|
||||||
|
import javafx.scene.layout.StackPane
|
||||||
|
import org.codehaus.commons.compiler.Location
|
||||||
|
import org.fxmisc.richtext.StyledTextArea
|
||||||
|
import tornadofx.addClass
|
||||||
|
|
||||||
|
class LogsPane(private val locationClick: (location: Location) -> Unit) : StackPane() {
|
||||||
|
private val editor = StyledTextArea("logs-pane",
|
||||||
|
{ text, style -> text.addClass(style) },
|
||||||
|
LogsPaneStyle.NO_STYLE,
|
||||||
|
{ text, style -> style.apply(text) }
|
||||||
|
).apply { isEditable = false }
|
||||||
|
|
||||||
|
init {
|
||||||
|
children += editor
|
||||||
|
}
|
||||||
|
|
||||||
|
fun appendEntry(message: String, severity: Severity, location: Location?, tag: String?) {
|
||||||
|
val locationRef = LogsPaneStyle(location = location, onClick = locationClick)
|
||||||
|
val severityStyle = LogsPaneStyle(severity = severity)
|
||||||
|
|
||||||
|
tag?.let { editor.insert(editor.length, "[$it] ", severityStyle) }
|
||||||
|
editor.insert(editor.length, location?.toString() ?: "", locationRef)
|
||||||
|
editor.insert(editor.length, (location?.let { ": " } ?: "") + message, LogsPaneStyle(severity = severity))
|
||||||
|
editor.insert(editor.length, "\n", LogsPaneStyle.NO_STYLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() = editor.clear()
|
||||||
|
|
||||||
|
override fun getUserAgentStylesheet(): String = LogsPaneStylesheet().base64URL.toExternalForm()
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.common.logs.enumeration
|
||||||
|
|
||||||
|
enum class Severity {
|
||||||
|
INFO,
|
||||||
|
WARNING,
|
||||||
|
ERROR
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.common.logs.style
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
|
import javafx.scene.Cursor
|
||||||
|
import javafx.scene.paint.Color
|
||||||
|
import javafx.scene.text.Text
|
||||||
|
import org.codehaus.commons.compiler.Location
|
||||||
|
|
||||||
|
class LogsPaneStyle(
|
||||||
|
private val location: Location? = null,
|
||||||
|
private val severity: Severity? = null,
|
||||||
|
private val onClick: (Location) -> Unit = {}
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun apply(text: Text) = when {
|
||||||
|
severity != null -> message(text, severity)
|
||||||
|
location != null -> location(text, location)
|
||||||
|
else -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun message(text: Text, severity: Severity) {
|
||||||
|
text.fill = when (severity) {
|
||||||
|
Severity.WARNING -> Color.ORANGE
|
||||||
|
Severity.ERROR -> Color.RED
|
||||||
|
Severity.INFO -> text.fill
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun location(text: Text, location: Location) {
|
||||||
|
text.cursor = Cursor.HAND
|
||||||
|
text.fill = Color.BLUE
|
||||||
|
text.isUnderline = true
|
||||||
|
text.setOnMouseClicked {
|
||||||
|
onClick(location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val NO_STYLE = LogsPaneStyle()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.stylesheet
|
package com.bartlomiejpluta.base.editor.common.logs.stylesheet
|
||||||
|
|
||||||
import javafx.scene.text.FontWeight
|
import javafx.scene.text.FontWeight
|
||||||
import tornadofx.Stylesheet
|
import tornadofx.Stylesheet
|
||||||
import tornadofx.cssclass
|
import tornadofx.cssclass
|
||||||
|
|
||||||
class CompilerLogsStylesheet : Stylesheet() {
|
class LogsPaneStylesheet : Stylesheet() {
|
||||||
companion object {
|
companion object {
|
||||||
val compilerLogs by cssclass()
|
val logsPane by cssclass()
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
compilerLogs {
|
logsPane {
|
||||||
fontFamily = "monospace"
|
fontFamily = "monospace"
|
||||||
fontWeight = FontWeight.MEDIUM
|
fontWeight = FontWeight.MEDIUM
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.bartlomiejpluta.base.editor.event
|
package com.bartlomiejpluta.base.editor.event
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
import org.codehaus.commons.compiler.Location
|
import org.codehaus.commons.compiler.Location
|
||||||
import tornadofx.EventBus
|
import tornadofx.EventBus
|
||||||
import tornadofx.FXEvent
|
import tornadofx.FXEvent
|
||||||
@@ -9,12 +10,4 @@ data class AppendCompilationLogEvent(
|
|||||||
val message: String,
|
val message: String,
|
||||||
val location: Location? = null,
|
val location: Location? = null,
|
||||||
val tag: String? = null
|
val tag: String? = null
|
||||||
) :
|
) : FXEvent(EventBus.RunOn.ApplicationThread)
|
||||||
FXEvent(EventBus.RunOn.ApplicationThread) {
|
|
||||||
|
|
||||||
enum class Severity {
|
|
||||||
INFO,
|
|
||||||
WARNING,
|
|
||||||
ERROR
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user