From 48c45fa51ca72be20979e91f3938d6dc3d9287bd Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 10 Feb 2019 09:49:16 +0300 Subject: [PATCH] Working workspace builder --- build.gradle.kts | 2 +- .../hep/dataforge/scripting/Builders.kt | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2daffdb1..6b033c87 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,7 +32,7 @@ allprojects { } group = "hep.dataforge" - version = "0.1.1-dev-2" + version = "0.1.1-dev-3" extensions.findByType()?.apply { jvm { diff --git a/dataforge-scripting/src/jvmMain/kotlin/hep/dataforge/scripting/Builders.kt b/dataforge-scripting/src/jvmMain/kotlin/hep/dataforge/scripting/Builders.kt index 452b3fe2..ee1af3df 100644 --- a/dataforge-scripting/src/jvmMain/kotlin/hep/dataforge/scripting/Builders.kt +++ b/dataforge-scripting/src/jvmMain/kotlin/hep/dataforge/scripting/Builders.kt @@ -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()