[Editor] Create Project Assembler
From now on, the project assets are assembled to the output *.jar file.
This commit is contained in:
@@ -6,9 +6,9 @@ import java.io.File
|
||||
@Component
|
||||
class DefaultGameEngineProvider : GameEngineProvider {
|
||||
|
||||
override fun provideBaseGameEngine(target: File) {
|
||||
override fun provideBaseGameEngine(targetJar: File) {
|
||||
javaClass.getResourceAsStream("/engine/game.jar").use { ris ->
|
||||
target.outputStream().use { fos ->
|
||||
targetJar.outputStream().use { fos ->
|
||||
ris.copyTo(fos)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ import java.io.File
|
||||
|
||||
interface JarPackager {
|
||||
fun pack(sourceDirectory: File, targetJar: File, root: String = ".")
|
||||
fun copy(file: File, targetJar: File, root: String = ".")
|
||||
}
|
||||
@@ -20,11 +20,22 @@ class ZipBasedJarPackager : JarPackager {
|
||||
FileSystems.newFileSystem(uri, env).use { jar ->
|
||||
Files.walk(source)
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach {
|
||||
val path = jar.getPath(Paths.get(root, source.relativize(it).toString()).normalize().toString())
|
||||
Files.createDirectories(path.parent)
|
||||
Files.copy(it, path, StandardCopyOption.REPLACE_EXISTING)
|
||||
.forEach { file ->
|
||||
val path = jar.getPath(Paths.get(root, source.relativize(file).toString()).normalize().toString())
|
||||
path.parent?.let { Files.createDirectories(it) }
|
||||
Files.copy(file, path, StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun copy(file: File, targetJar: File, root: String) {
|
||||
val env = mapOf("create" to "true")
|
||||
val zip = targetJar.toPath()
|
||||
val uri = URI.create("jar:" + zip.toUri())
|
||||
|
||||
FileSystems.newFileSystem(uri, env).use { jar ->
|
||||
val path = jar.getPath(Paths.get(root, file.name).normalize().toString())
|
||||
file.inputStream().use { fis -> Files.copy(fis, path) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.editor.code.build.pipeline
|
||||
import com.bartlomiejpluta.base.editor.code.build.compiler.ScriptCompiler
|
||||
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.project.ProjectAssembler
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
@@ -21,6 +22,9 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
||||
@Autowired
|
||||
private lateinit var engineProvider: GameEngineProvider
|
||||
|
||||
@Autowired
|
||||
private lateinit var projectAssembler: ProjectAssembler
|
||||
|
||||
@Autowired
|
||||
private lateinit var projectContext: ProjectContext
|
||||
|
||||
@@ -33,6 +37,7 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
||||
compiler.compile(it.codeFSNode, it.buildClassesDirectory)
|
||||
engineProvider.provideBaseGameEngine(outputFile)
|
||||
packager.pack(it.buildClassesDirectory, outputFile, "BOOT-INF/classes")
|
||||
projectAssembler.assembly(it, outputFile)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.bartlomiejpluta.base.editor.code.build.project
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.build.packager.JarPackager
|
||||
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 DefaultProjectAssembler : ProjectAssembler {
|
||||
|
||||
@Autowired
|
||||
private lateinit var packager: JarPackager
|
||||
|
||||
override fun assembly(project: Project, targetJar: File) {
|
||||
packager.pack(project.mapsDirectory, targetJar, "BOOT-INF/classes/project/maps")
|
||||
packager.pack(project.tileSetsDirectory, targetJar, "BOOT-INF/classes/project/tilesets")
|
||||
packager.pack(project.imagesDirectory, targetJar, "BOOT-INF/classes/project/images")
|
||||
packager.copy(project.projectFile, targetJar, "BOOT-INF/classes/project")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.bartlomiejpluta.base.editor.code.build.project
|
||||
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
import java.io.File
|
||||
|
||||
interface ProjectAssembler {
|
||||
fun assembly(project: Project, targetJar: File)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class DefaultProjectContext : ProjectContext {
|
||||
project?.let {
|
||||
it.sourceDirectory.mkdirs()
|
||||
|
||||
FileOutputStream(File(it.sourceDirectory, "project.bep")).use { fos ->
|
||||
FileOutputStream(it.projectFile).use { fos ->
|
||||
projectSerializer.serialize(it, fos)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
||||
import javafx.beans.binding.Bindings
|
||||
import javafx.beans.binding.Bindings.createObjectBinding
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import tornadofx.getValue
|
||||
@@ -19,6 +19,9 @@ class Project {
|
||||
val sourceDirectoryProperty = SimpleObjectProperty<File>()
|
||||
val sourceDirectory by sourceDirectoryProperty
|
||||
|
||||
val projectFileProperty = createObjectBinding({ File(sourceDirectory, PROJECT_FILE) }, sourceDirectoryProperty)
|
||||
val projectFile by projectFileProperty
|
||||
|
||||
val maps = observableListOf<GameMapAsset>()
|
||||
val tileSets = observableListOf<TileSetAsset>()
|
||||
val images = observableListOf<ImageAsset>()
|
||||
@@ -40,7 +43,7 @@ class Project {
|
||||
val codeDirectoryProperty = SimpleObjectProperty<File>()
|
||||
var codeDirectory by codeDirectoryProperty
|
||||
private set
|
||||
val codeFSNodeProperty = Bindings.createObjectBinding({ FileSystemNode(codeDirectory) }, codeDirectoryProperty)
|
||||
val codeFSNodeProperty = createObjectBinding({ FileSystemNode(codeDirectory) }, codeDirectoryProperty)
|
||||
val codeFSNode by codeFSNodeProperty
|
||||
|
||||
// Build directories
|
||||
@@ -79,6 +82,7 @@ class Project {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PROJECT_FILE = "project.bep"
|
||||
const val MAPS_DIR = "maps"
|
||||
const val TILESETS_DIR = "tilesets"
|
||||
const val IMAGES_DIR = "images"
|
||||
|
||||
Reference in New Issue
Block a user