Working workspace builder
This commit is contained in:
parent
c06244465c
commit
48c45fa51c
@ -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 {
|
||||
|
@ -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()
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user