[Editor] Create :api module which provides a common classes for both :game module and user project's Java code developed with :editor
This commit is contained in:
14
api/build.gradle
Normal file
14
api/build.gradle
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'com.bartlomiejpluta.base'
|
||||||
|
version 'unspecified'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -47,15 +47,21 @@ dependencies {
|
|||||||
implementation 'org.springframework.boot:spring-boot-starter'
|
implementation 'org.springframework.boot:spring-boot-starter'
|
||||||
}
|
}
|
||||||
|
|
||||||
task copyGameEngine(type: Copy) {
|
task provideGameEngine(type: Copy) {
|
||||||
dependsOn(":game:build")
|
dependsOn(":game:build")
|
||||||
|
|
||||||
from project(':game').file('build/libs/game.jar')
|
from project(':game').file('build/libs/game.jar')
|
||||||
into file("build/resources/main/engine")
|
into file("build/resources/main/engine")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task provideApi(type: Copy) {
|
||||||
|
from project(':api').file('src/main/java')
|
||||||
|
into file('build/resources/main/api')
|
||||||
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
dependsOn(copyGameEngine)
|
dependsOn(provideGameEngine)
|
||||||
|
dependsOn(provideApi)
|
||||||
}
|
}
|
||||||
|
|
||||||
build {
|
build {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.build.compiler
|
package com.bartlomiejpluta.base.editor.code.build.compiler
|
||||||
|
|
||||||
|
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.event.UpdateCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.event.UpdateCompilationLogEvent
|
||||||
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.Resource
|
||||||
import org.codehaus.janino.CompilerFactory
|
import org.codehaus.janino.CompilerFactory
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import tornadofx.FX
|
import tornadofx.FX
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -15,15 +19,31 @@ import java.util.stream.Collectors.toList
|
|||||||
class JaninoCompiler : ScriptCompiler {
|
class JaninoCompiler : ScriptCompiler {
|
||||||
private val compilerFactory = CompilerFactory()
|
private val compilerFactory = CompilerFactory()
|
||||||
|
|
||||||
|
@Value("classpath:api/**/*.java")
|
||||||
|
private lateinit var apiFiles: Array<org.springframework.core.io.Resource>
|
||||||
|
|
||||||
override fun compile(sourceDirectory: FileSystemNode, targetDirectory: File) {
|
override fun compile(sourceDirectory: FileSystemNode, targetDirectory: File) {
|
||||||
val files = sourceDirectory.allChildren.map(FileSystemNode::file).filter(File::isFile)
|
val sources = sourceDirectory
|
||||||
|
.allChildren
|
||||||
|
.map(FileSystemNode::file)
|
||||||
|
.filter(File::isFile)
|
||||||
|
.map(::FileResource)
|
||||||
|
.toTypedArray<Resource>()
|
||||||
|
|
||||||
|
val api = apiFiles
|
||||||
|
.map(::ClasspathResource)
|
||||||
|
.toTypedArray()
|
||||||
|
|
||||||
|
val resources = sources + api
|
||||||
|
|
||||||
val compiler = compilerFactory.newCompiler()
|
val compiler = compilerFactory.newCompiler()
|
||||||
|
|
||||||
|
|
||||||
// FIXME:
|
// FIXME:
|
||||||
// For some reason the compiler's error handler does not want to catch
|
// For some reason the compiler's error handler does not want to catch
|
||||||
// syntax errors. The only way to catch it is just catching CompileExceptions
|
// syntax errors. The only way to catch it is just catching CompileExceptions
|
||||||
try {
|
try {
|
||||||
compiler.compile(files.toTypedArray())
|
compiler.compile(resources)
|
||||||
FX.eventbus.fire(UpdateCompilationLogEvent(UpdateCompilationLogEvent.Severity.INFO, "Compilation success"))
|
FX.eventbus.fire(UpdateCompilationLogEvent(UpdateCompilationLogEvent.Severity.INFO, "Compilation success"))
|
||||||
moveClassFilesToTargetDirectory(sourceDirectory.file, targetDirectory)
|
moveClassFilesToTargetDirectory(sourceDirectory.file, targetDirectory)
|
||||||
} catch (e: CompileException) {
|
} catch (e: CompileException) {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.code.build.model
|
||||||
|
|
||||||
|
import org.codehaus.commons.compiler.util.resource.Resource
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
class ClasspathResource(private val resource: org.springframework.core.io.Resource) : Resource {
|
||||||
|
|
||||||
|
override fun open(): InputStream = resource.inputStream
|
||||||
|
|
||||||
|
override fun getFileName(): String = resource.filename ?: ""
|
||||||
|
|
||||||
|
override fun lastModified(): Long = resource.lastModified()
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.code.build.model
|
||||||
|
|
||||||
|
import org.codehaus.commons.compiler.util.resource.Resource
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
class FileResource(private val file: File) : Resource {
|
||||||
|
|
||||||
|
override fun open(): InputStream = file.inputStream()
|
||||||
|
|
||||||
|
override fun getFileName(): String = file.name
|
||||||
|
|
||||||
|
override fun lastModified(): Long = file.lastModified()
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation project(":engine")
|
implementation project(":engine")
|
||||||
implementation project(":proto")
|
implementation project(":proto")
|
||||||
|
implementation project(":api")
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ include('engine')
|
|||||||
include('game')
|
include('game')
|
||||||
include('editor')
|
include('editor')
|
||||||
include('proto')
|
include('proto')
|
||||||
|
include('api')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user