[Editor] Create DatabaseAssembler and enable assembling database into output game.jar file
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.bartlomiejpluta.base.editor.code.build.database
|
||||
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
import java.io.File
|
||||
|
||||
interface DatabaseAssembler {
|
||||
fun assembly(project: Project, targetJar: File)
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.bartlomiejpluta.base.editor.code.build.database
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.build.exception.BuildException
|
||||
import com.bartlomiejpluta.base.editor.code.build.packager.JarPackager
|
||||
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||
import com.bartlomiejpluta.base.editor.database.service.DatabaseService
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
import java.io.File
|
||||
|
||||
@Component
|
||||
class H2DatabaseAssembler : DatabaseAssembler {
|
||||
|
||||
@Autowired
|
||||
private lateinit var databaseService: DatabaseService
|
||||
|
||||
@Autowired
|
||||
private lateinit var packager: JarPackager
|
||||
|
||||
override fun assembly(project: Project, targetJar: File) {
|
||||
try {
|
||||
tryToAssembly(project, targetJar)
|
||||
} catch (e: Exception) {
|
||||
throw BuildException(Severity.ERROR, TAG, e.message, e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryToAssembly(project: Project, targetJar: File) {
|
||||
val dump = project.buildDatabaseDumpFile
|
||||
dumpDatabase(dump)
|
||||
copyDumpToTargetJar(dump, targetJar)
|
||||
}
|
||||
|
||||
private fun dumpDatabase(dumpFile: File) {
|
||||
databaseService.run {
|
||||
val statement = prepareStatement("SCRIPT TO ?")
|
||||
statement.setString(1, dumpFile.absolutePath)
|
||||
statement.execute()
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyDumpToTargetJar(dumpFile: File, targetJar: File) {
|
||||
packager.copy(dumpFile, targetJar, "BOOT-INF/classes/database")
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "Database Assembler"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.editor.code.build.pipeline
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.build.compiler.Compiler
|
||||
import com.bartlomiejpluta.base.editor.code.build.database.DatabaseAssembler
|
||||
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.packager.JarPackager
|
||||
@@ -35,6 +36,9 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
||||
@Autowired
|
||||
private lateinit var projectAssembler: ProjectAssembler
|
||||
|
||||
@Autowired
|
||||
private lateinit var databaseAssembler: DatabaseAssembler
|
||||
|
||||
@Autowired
|
||||
private lateinit var projectContext: ProjectContext
|
||||
|
||||
@@ -94,10 +98,15 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Assembling game engine...", tag = TAG))
|
||||
engineProvider.provideBaseGameEngine(outputFile)
|
||||
|
||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Assembling project assets...", tag = TAG))
|
||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Assembling compiled classes...", tag = TAG))
|
||||
packager.pack(project.buildClassesDirectory, outputFile, "BOOT-INF/classes")
|
||||
|
||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Assembling project assets...", tag = TAG))
|
||||
projectAssembler.assembly(project, outputFile)
|
||||
|
||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Assembling database...", tag = TAG))
|
||||
databaseAssembler.assembly(project, outputFile)
|
||||
|
||||
val buildingTime = (System.currentTimeMillis() - startTime) / 1000.0
|
||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Build done [${buildingTime}s]", tag = TAG))
|
||||
}
|
||||
|
||||
@@ -96,10 +96,18 @@ class Project {
|
||||
var buildDependenciesDirectory by buildDependenciesDirectoryProperty
|
||||
private set
|
||||
|
||||
val buildDatabaseDumpDirectoryProperty = SimpleObjectProperty<File>()
|
||||
var buildDatabaseDumpDirectory by buildDatabaseDumpDirectoryProperty
|
||||
private set
|
||||
|
||||
val buildOutDirectoryProperty = SimpleObjectProperty<File>()
|
||||
var buildOutDirectory by buildOutDirectoryProperty
|
||||
private set
|
||||
|
||||
val buildDatabaseDumpFileProperty =
|
||||
createObjectBinding({ File(buildDatabaseDumpDirectory, DATABASE_DUMP_FILE) }, buildDatabaseDumpDirectoryProperty)
|
||||
val buildDatabaseDumpFile by buildDatabaseDumpFileProperty
|
||||
|
||||
val buildOutputJarFileProperty =
|
||||
createObjectBinding({ File(buildOutDirectory, PROJECT_OUTPUT_JAR_FILE) }, buildOutDirectoryProperty)
|
||||
val buildOutputJarFile by buildOutputJarFileProperty
|
||||
@@ -121,6 +129,7 @@ class Project {
|
||||
buildDirectory = File(it, BUILD_DIR)
|
||||
buildClassesDirectory = File(it, BUILD_CLASSES_DIR)
|
||||
buildDependenciesDirectory = File(it, BUILD_DEPENDENCIES_DIR)
|
||||
buildDatabaseDumpDirectory = File(it, BUILD_DATABASE_DUMP_DIR)
|
||||
buildOutDirectory = File(it, BUILD_OUT_DIR)
|
||||
}
|
||||
}
|
||||
@@ -151,6 +160,7 @@ class Project {
|
||||
companion object {
|
||||
const val PROJECT_FILE = "project.bep"
|
||||
const val DATABASE_FILE = "data"
|
||||
const val DATABASE_DUMP_FILE = "data.sql"
|
||||
const val PROJECT_OUTPUT_JAR_FILE = "game.jar"
|
||||
|
||||
const val MAPS_DIR = "maps"
|
||||
@@ -166,5 +176,6 @@ class Project {
|
||||
const val BUILD_CLASSES_DIR = "$BUILD_DIR/classes"
|
||||
const val BUILD_OUT_DIR = "$BUILD_DIR/out"
|
||||
const val BUILD_DEPENDENCIES_DIR = "$BUILD_DIR/dependencies"
|
||||
const val BUILD_DATABASE_DUMP_DIR = "$BUILD_DIR/db"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user