Add possibility to get location of the script.main.kts file
#KT-48414 fixed
This commit is contained in:
committed by
Ilya Chernikov
parent
7ddf83f32d
commit
ca2f37f6eb
@@ -7,6 +7,7 @@
|
||||
|
||||
package kotlin.script.experimental.api
|
||||
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||
@@ -106,6 +107,17 @@ val ScriptCompilationConfigurationKeys.implicitReceivers by PropertiesCollection
|
||||
*/
|
||||
val ScriptCompilationConfigurationKeys.providedProperties by PropertiesCollection.key<Map<String, KotlinType>>() // external variables
|
||||
|
||||
/**
|
||||
* Variable name that holds a {@link File} instance pointing to the location of the script file
|
||||
*/
|
||||
val ScriptCompilationConfigurationKeys.scriptFileLocationVariable by PropertiesCollection.key<String>()
|
||||
|
||||
/**
|
||||
* File pointing to the location of the script file. Note that in some cases it might not be possible
|
||||
* to determine script file location properly - in this case the file is an empty file
|
||||
*/
|
||||
val ScriptCompilationConfigurationKeys.scriptFileLocation by PropertiesCollection.key<File>()
|
||||
|
||||
/**
|
||||
* The list of import expressions that will be implicitly applied to the script body, the syntax is the same as for the "import" statement
|
||||
*/
|
||||
|
||||
+7
-5
@@ -41,12 +41,14 @@ fun configureProvidedPropertiesFromJsr223Context(context: ScriptEvaluationConfig
|
||||
val engineBindings = jsr223context.getBindings(ScriptContext.ENGINE_SCOPE)
|
||||
val globalBindings = jsr223context.getBindings(ScriptContext.GLOBAL_SCOPE)
|
||||
for (prop in knownProperties) {
|
||||
val v = when {
|
||||
engineBindings?.containsKey(prop.key) == true -> engineBindings[prop.key]
|
||||
globalBindings?.containsKey(prop.key) == true -> globalBindings[prop.key]
|
||||
else -> return ResultWithDiagnostics.Failure("Property ${prop.key} is not found in the bindings".asErrorDiagnostics())
|
||||
if (prop.key !in updatedProperties) {
|
||||
val v = when {
|
||||
engineBindings?.containsKey(prop.key) == true -> engineBindings[prop.key]
|
||||
globalBindings?.containsKey(prop.key) == true -> globalBindings[prop.key]
|
||||
else -> return ResultWithDiagnostics.Failure("Property ${prop.key} is not found in the bindings".asErrorDiagnostics())
|
||||
}
|
||||
updatedProperties[prop.key] = v
|
||||
}
|
||||
updatedProperties[prop.key] = v
|
||||
}
|
||||
ScriptEvaluationConfiguration(context.evaluationConfiguration) {
|
||||
providedProperties(updatedProperties)
|
||||
|
||||
Reference in New Issue
Block a user