Add compatibility with templates from script-runtime...
and add script-runtime to the compilation classpath by default
This commit is contained in:
+15
@@ -14,6 +14,11 @@ private const val ERROR_MSG_PREFIX = "Unable to construct script definition: "
|
|||||||
private const val ILLEGAL_CONFIG_ANN_ARG =
|
private const val ILLEGAL_CONFIG_ANN_ARG =
|
||||||
"Illegal argument compilationConfiguration of the KotlinScript annotation: expecting an object or default-constructed class derived from ScriptCompilationConfiguration"
|
"Illegal argument compilationConfiguration of the KotlinScript annotation: expecting an object or default-constructed class derived from ScriptCompilationConfiguration"
|
||||||
|
|
||||||
|
private const val SCRIPT_RUNTIME_TEMPLATES_PACKAGE = "kotlin.script.templates.standard"
|
||||||
|
|
||||||
|
@KotlinScript
|
||||||
|
private abstract class DummyScriptTemplate
|
||||||
|
|
||||||
fun createCompilationConfigurationFromTemplate(
|
fun createCompilationConfigurationFromTemplate(
|
||||||
baseClassType: KotlinType,
|
baseClassType: KotlinType,
|
||||||
hostConfiguration: ScriptingHostConfiguration,
|
hostConfiguration: ScriptingHostConfiguration,
|
||||||
@@ -33,6 +38,16 @@ fun createCompilationConfigurationFromTemplate(
|
|||||||
val loadedBaseClassType = if (baseClass == baseClassType.fromClass) baseClassType else KotlinType(baseClass)
|
val loadedBaseClassType = if (baseClass == baseClassType.fromClass) baseClassType else KotlinType(baseClass)
|
||||||
|
|
||||||
val mainAnnotation = baseClass.findAnnotation<KotlinScript>()
|
val mainAnnotation = baseClass.findAnnotation<KotlinScript>()
|
||||||
|
?: run {
|
||||||
|
// transitions to the new scripting API:
|
||||||
|
// substituting annotations for standard templates from script-runtime
|
||||||
|
when (baseClass.qualifiedName) {
|
||||||
|
"$SCRIPT_RUNTIME_TEMPLATES_PACKAGE.SimpleScriptTemplate",
|
||||||
|
"$SCRIPT_RUNTIME_TEMPLATES_PACKAGE.ScriptTemplateWithArgs",
|
||||||
|
"$SCRIPT_RUNTIME_TEMPLATES_PACKAGE.ScriptTemplateWithBindings" -> DummyScriptTemplate::class
|
||||||
|
else -> null
|
||||||
|
}?.findAnnotation<KotlinScript>()
|
||||||
|
}
|
||||||
?: throw IllegalArgumentException("${ERROR_MSG_PREFIX}Expecting KotlinScript annotation on the $baseClass")
|
?: throw IllegalArgumentException("${ERROR_MSG_PREFIX}Expecting KotlinScript annotation on the $baseClass")
|
||||||
|
|
||||||
fun scriptConfigInstance(kclass: KClass<out ScriptCompilationConfiguration>): ScriptCompilationConfiguration = try {
|
fun scriptConfigInstance(kclass: KClass<out ScriptCompilationConfiguration>): ScriptCompilationConfiguration = try {
|
||||||
|
|||||||
+1
@@ -134,6 +134,7 @@ class KJvmCompilerImpl(val hostConfiguration: ScriptingHostConfiguration) : KJvm
|
|||||||
}
|
}
|
||||||
// TODO: implement logic similar to compiler's -no-stdlib (and -no-reflect?)
|
// TODO: implement logic similar to compiler's -no-stdlib (and -no-reflect?)
|
||||||
addRoot("kotlin.stdlib", KotlinJars.stdlib)
|
addRoot("kotlin.stdlib", KotlinJars.stdlib)
|
||||||
|
KotlinJars.scriptRuntimeOrNull?.let { addRoot("kotlin.script.runtime", it) }
|
||||||
|
|
||||||
put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script") // TODO" take meaningful and valid name from somewhere
|
put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script") // TODO" take meaningful and valid name from somewhere
|
||||||
languageVersionSettings = LanguageVersionSettingsImpl(
|
languageVersionSettings = LanguageVersionSettingsImpl(
|
||||||
|
|||||||
Reference in New Issue
Block a user