Working workspace builder

This commit is contained in:
Alexander Nozik 2019-02-10 09:49:16 +03:00
parent c06244465c
commit 48c45fa51c
2 changed files with 16 additions and 8 deletions

View File

@ -32,7 +32,7 @@ allprojects {
}
group = "hep.dataforge"
version = "0.1.1-dev-2"
version = "0.1.1-dev-3"
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
jvm {

View File

@ -1,5 +1,6 @@
package hep.dataforge.scripting
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.workspace.Workspace
import hep.dataforge.workspace.WorkspaceBuilder
@ -12,14 +13,14 @@ import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
object Builders {
fun buildWorkspace(source: SourceCode): Workspace {
val builder = WorkspaceBuilder(Global)
fun buildWorkspace(source: SourceCode, context: Context = Global): Workspace {
val builder = WorkspaceBuilder(context)
val workspaceScriptConfiguration = ScriptCompilationConfiguration {
baseClass(Any::class)
implicitReceivers(WorkspaceBuilder::class)
jvm{
dependenciesFromCurrentContext()
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
}
@ -27,9 +28,16 @@ object Builders {
implicitReceivers(builder)
}
val res = BasicJvmScriptingHost().eval(source, workspaceScriptConfiguration, evaluationConfiguration)
res.reports.forEach{ scriptDiagnostic ->
scriptDiagnostic.exception?.let { throw it }
BasicJvmScriptingHost().eval(source, workspaceScriptConfiguration, evaluationConfiguration).onFailure {
it.reports.forEach { scriptDiagnostic ->
when (scriptDiagnostic.severity) {
ScriptDiagnostic.Severity.FATAL, ScriptDiagnostic.Severity.ERROR ->
context.logger.error(scriptDiagnostic.exception) { scriptDiagnostic.toString() }
ScriptDiagnostic.Severity.WARNING -> context.logger.warn { scriptDiagnostic.toString() }
ScriptDiagnostic.Severity.INFO -> context.logger.info { scriptDiagnostic.toString() }
ScriptDiagnostic.Severity.DEBUG -> context.logger.debug { scriptDiagnostic.toString() }
}
}
}
return builder.build()