Add support for compile-time dependencies in :API
This commit is contained in:
@@ -10,5 +10,10 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation "org.joml:joml:${jomlVersion}"
|
||||||
|
}
|
||||||
|
|
||||||
|
task relayDependencies(type: Copy) {
|
||||||
|
from configurations.runtimeClasspath
|
||||||
|
into file("build/dependencies")
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,6 @@ javafx {
|
|||||||
modules = ['javafx.controls', 'javafx.graphics']
|
modules = ['javafx.controls', 'javafx.graphics']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
kotlinOptions.jvmTarget = "14"
|
kotlinOptions.jvmTarget = "14"
|
||||||
}
|
}
|
||||||
@@ -57,6 +55,13 @@ task provideGameEngine(type: Copy) {
|
|||||||
into file("build/resources/main/engine")
|
into file("build/resources/main/engine")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task provideApiDependencies(type: Copy) {
|
||||||
|
dependsOn(":api:relayDependencies")
|
||||||
|
|
||||||
|
from project(':api').file('build/dependencies')
|
||||||
|
into file("build/resources/main/dependencies")
|
||||||
|
}
|
||||||
|
|
||||||
task provideApi(type: Copy) {
|
task provideApi(type: Copy) {
|
||||||
from project(':api').file('src/main/java')
|
from project(':api').file('src/main/java')
|
||||||
into file('build/resources/main/api')
|
into file('build/resources/main/api')
|
||||||
@@ -76,6 +81,7 @@ task provideApi(type: Copy) {
|
|||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
dependsOn(provideGameEngine)
|
dependsOn(provideGameEngine)
|
||||||
|
dependsOn(provideApiDependencies)
|
||||||
dependsOn(provideApi)
|
dependsOn(provideApi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ import com.bartlomiejpluta.base.editor.file.model.FileSystemNode
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
interface Compiler {
|
interface Compiler {
|
||||||
fun compile(sourceDirectory: FileSystemNode, targetDirectory: File)
|
fun compile(sourceDirectory: FileSystemNode, targetDirectory: File, classPath: Array<File> = emptyArray())
|
||||||
}
|
}
|
||||||
@@ -22,8 +22,8 @@ class JaninoCompiler : Compiler {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var apiProvider: APIProvider
|
private lateinit var apiProvider: APIProvider
|
||||||
|
|
||||||
override fun compile(sourceDirectory: FileSystemNode, targetDirectory: File) = try {
|
override fun compile(sourceDirectory: FileSystemNode, targetDirectory: File, classPath: Array<File>) = try {
|
||||||
tryToCompile(sourceDirectory, targetDirectory)
|
tryToCompile(sourceDirectory, targetDirectory, classPath)
|
||||||
|
|
||||||
/* Because Janino parser does not provide error handler for parsers:
|
/* Because Janino parser does not provide error handler for parsers:
|
||||||
*
|
*
|
||||||
@@ -42,12 +42,14 @@ class JaninoCompiler : Compiler {
|
|||||||
throw BuildException(Severity.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, classPath: Array<File>) {
|
||||||
val compilationUnits = prepareCompilationUnits(sourceDirectory)
|
val compilationUnits = prepareCompilationUnits(sourceDirectory)
|
||||||
|
|
||||||
compilerFactory.newCompiler().apply {
|
compilerFactory.newCompiler().apply {
|
||||||
setDestinationDirectory(targetDirectory, false)
|
setDestinationDirectory(targetDirectory, false)
|
||||||
|
|
||||||
|
setClassPath(classPath)
|
||||||
|
|
||||||
setWarningHandler { handle, message, location ->
|
setWarningHandler { handle, message, location ->
|
||||||
eventbus.fire(AppendBuildLogsEvent(Severity.WARNING, "$message ($handle)", location, "Compiler"))
|
eventbus.fire(AppendBuildLogsEvent(Severity.WARNING, "$message ($handle)", location, "Compiler"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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.code.dependency.DependenciesProvider
|
||||||
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
import com.bartlomiejpluta.base.editor.common.logs.enumeration.Severity
|
||||||
import com.bartlomiejpluta.base.editor.event.AppendBuildLogsEvent
|
import com.bartlomiejpluta.base.editor.event.AppendBuildLogsEvent
|
||||||
import com.bartlomiejpluta.base.editor.event.ClearBuildLogsEvent
|
import com.bartlomiejpluta.base.editor.event.ClearBuildLogsEvent
|
||||||
@@ -19,6 +20,9 @@ import tornadofx.FX.Companion.eventbus
|
|||||||
@Component
|
@Component
|
||||||
class DefaultBuildPipelineService : BuildPipelineService {
|
class DefaultBuildPipelineService : BuildPipelineService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var dependenciesProvider: DependenciesProvider
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var compiler: Compiler
|
private lateinit var compiler: Compiler
|
||||||
|
|
||||||
@@ -76,8 +80,11 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
|||||||
val outputFile = project.buildOutputJarFile
|
val outputFile = project.buildOutputJarFile
|
||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
|
|
||||||
|
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Providing compile-time dependencies...", tag = TAG))
|
||||||
|
val dependencies = dependenciesProvider.provideDependenciesTo(project.buildDependenciesDirectory)
|
||||||
|
|
||||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Compiling sources...", tag = TAG))
|
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Compiling sources...", tag = TAG))
|
||||||
compiler.compile(project.codeFSNode, project.buildClassesDirectory)
|
compiler.compile(project.codeFSNode, project.buildClassesDirectory, dependencies.toTypedArray())
|
||||||
|
|
||||||
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Assembling game engine...", tag = TAG))
|
eventbus.fire(AppendBuildLogsEvent(Severity.INFO, "Assembling game engine...", tag = TAG))
|
||||||
engineProvider.provideBaseGameEngine(outputFile)
|
engineProvider.provideBaseGameEngine(outputFile)
|
||||||
@@ -95,6 +102,7 @@ class DefaultBuildPipelineService : BuildPipelineService {
|
|||||||
|
|
||||||
project.buildClassesDirectory.mkdirs()
|
project.buildClassesDirectory.mkdirs()
|
||||||
project.buildOutDirectory.mkdirs()
|
project.buildOutDirectory.mkdirs()
|
||||||
|
project.buildDependenciesDirectory.mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun clean() {
|
override fun clean() {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.code.dependency
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.core.io.Resource
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class DependenciesProvider {
|
||||||
|
|
||||||
|
@Value("classpath:dependencies/*.jar")
|
||||||
|
private lateinit var dependencies: Array<Resource>
|
||||||
|
|
||||||
|
fun provideDependenciesTo(root: File) = dependencies
|
||||||
|
.filter { it.filename != null }
|
||||||
|
.map {
|
||||||
|
File(root, it.filename!!).apply {
|
||||||
|
it.inputStream.transferTo(outputStream())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,6 +64,10 @@ class Project {
|
|||||||
var buildClassesDirectory by buildClassesDirectoryProperty
|
var buildClassesDirectory by buildClassesDirectoryProperty
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
val buildDependenciesDirectoryProperty = SimpleObjectProperty<File>()
|
||||||
|
var buildDependenciesDirectory by buildDependenciesDirectoryProperty
|
||||||
|
private set
|
||||||
|
|
||||||
val buildOutDirectoryProperty = SimpleObjectProperty<File>()
|
val buildOutDirectoryProperty = SimpleObjectProperty<File>()
|
||||||
var buildOutDirectory by buildOutDirectoryProperty
|
var buildOutDirectory by buildOutDirectoryProperty
|
||||||
private set
|
private set
|
||||||
@@ -82,6 +86,7 @@ class Project {
|
|||||||
codeDirectory = File(it, CODE_DIR)
|
codeDirectory = File(it, CODE_DIR)
|
||||||
buildDirectory = File(it, BUILD_DIR)
|
buildDirectory = File(it, BUILD_DIR)
|
||||||
buildClassesDirectory = File(it, BUILD_CLASSES_DIR)
|
buildClassesDirectory = File(it, BUILD_CLASSES_DIR)
|
||||||
|
buildDependenciesDirectory = File(it, BUILD_DEPENDENCIES_DIR)
|
||||||
buildOutDirectory = File(it, BUILD_OUT_DIR)
|
buildOutDirectory = File(it, BUILD_OUT_DIR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,5 +113,6 @@ class Project {
|
|||||||
const val BUILD_DIR = "build"
|
const val BUILD_DIR = "build"
|
||||||
const val BUILD_CLASSES_DIR = "$BUILD_DIR/classes"
|
const val BUILD_CLASSES_DIR = "$BUILD_DIR/classes"
|
||||||
const val BUILD_OUT_DIR = "$BUILD_DIR/out"
|
const val BUILD_OUT_DIR = "$BUILD_DIR/out"
|
||||||
|
const val BUILD_DEPENDENCIES_DIR = "$BUILD_DIR/dependencies"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user