Working workspace builder
This commit is contained in:
parent
c06244465c
commit
48c45fa51c
@ -32,7 +32,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "hep.dataforge"
|
group = "hep.dataforge"
|
||||||
version = "0.1.1-dev-2"
|
version = "0.1.1-dev-3"
|
||||||
|
|
||||||
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
|
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
|
||||||
jvm {
|
jvm {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package hep.dataforge.scripting
|
package hep.dataforge.scripting
|
||||||
|
|
||||||
|
import hep.dataforge.context.Context
|
||||||
import hep.dataforge.context.Global
|
import hep.dataforge.context.Global
|
||||||
import hep.dataforge.workspace.Workspace
|
import hep.dataforge.workspace.Workspace
|
||||||
import hep.dataforge.workspace.WorkspaceBuilder
|
import hep.dataforge.workspace.WorkspaceBuilder
|
||||||
@ -12,14 +13,14 @@ import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
|
|||||||
|
|
||||||
object Builders {
|
object Builders {
|
||||||
|
|
||||||
fun buildWorkspace(source: SourceCode): Workspace {
|
fun buildWorkspace(source: SourceCode, context: Context = Global): Workspace {
|
||||||
val builder = WorkspaceBuilder(Global)
|
val builder = WorkspaceBuilder(context)
|
||||||
|
|
||||||
val workspaceScriptConfiguration = ScriptCompilationConfiguration {
|
val workspaceScriptConfiguration = ScriptCompilationConfiguration {
|
||||||
baseClass(Any::class)
|
baseClass(Any::class)
|
||||||
implicitReceivers(WorkspaceBuilder::class)
|
implicitReceivers(WorkspaceBuilder::class)
|
||||||
jvm{
|
jvm {
|
||||||
dependenciesFromCurrentContext()
|
dependenciesFromCurrentContext(wholeClasspath = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,9 +28,16 @@ object Builders {
|
|||||||
implicitReceivers(builder)
|
implicitReceivers(builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
val res = BasicJvmScriptingHost().eval(source, workspaceScriptConfiguration, evaluationConfiguration)
|
BasicJvmScriptingHost().eval(source, workspaceScriptConfiguration, evaluationConfiguration).onFailure {
|
||||||
res.reports.forEach{ scriptDiagnostic ->
|
it.reports.forEach { scriptDiagnostic ->
|
||||||
scriptDiagnostic.exception?.let { throw it }
|
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()
|
return builder.build()
|
||||||
|
Loading…
Reference in New Issue
Block a user