Change a parameter "context" in script templates to environment: Map<String, Any?>?
This commit is contained in:
committed by
Pavel V. Talanov
parent
bf683a63fb
commit
f30b402640
@@ -41,7 +41,7 @@ import kotlin.reflect.memberProperties
|
|||||||
annotation class ScriptFilePattern(val pattern: String)
|
annotation class ScriptFilePattern(val pattern: String)
|
||||||
|
|
||||||
interface ScriptDependenciesResolver {
|
interface ScriptDependenciesResolver {
|
||||||
fun resolve(scriptFile: File?, annotations: Iterable<Annotation>, context: Any?): KotlinScriptExternalDependencies? = null
|
fun resolve(scriptFile: File?, annotations: Iterable<Annotation>, environment: Map<String, Any?>?): KotlinScriptExternalDependencies? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@@ -49,7 +49,7 @@ interface ScriptDependenciesResolver {
|
|||||||
annotation class ScriptDependenciesResolverClass(val resolver: KClass<out ScriptDependenciesResolver>,
|
annotation class ScriptDependenciesResolverClass(val resolver: KClass<out ScriptDependenciesResolver>,
|
||||||
vararg val supportedAnnotationClasses: KClass<out Any>)
|
vararg val supportedAnnotationClasses: KClass<out Any>)
|
||||||
|
|
||||||
data class KotlinScriptDefinitionFromTemplate(val template: KClass<out Any>, val context: Any?) : KotlinScriptDefinition {
|
data class KotlinScriptDefinitionFromTemplate(val template: KClass<out Any>, val environment: Map<String, Any?>?) : KotlinScriptDefinition {
|
||||||
override val name = template.simpleName!!
|
override val name = template.simpleName!!
|
||||||
|
|
||||||
override fun getScriptParameters(scriptDescriptor: ScriptDescriptor): List<ScriptParameter> =
|
override fun getScriptParameters(scriptDescriptor: ScriptDescriptor): List<ScriptParameter> =
|
||||||
@@ -111,7 +111,7 @@ data class KotlinScriptDefinitionFromTemplate(val template: KClass<out Any>, val
|
|||||||
val annFQN = ann.first.qualifiedName
|
val annFQN = ann.first.qualifiedName
|
||||||
if (resolver.first.supportedAnnotationClasses.asIterable2().any { it.qualifiedName == annFQN }) ann.second else null
|
if (resolver.first.supportedAnnotationClasses.asIterable2().any { it.qualifiedName == annFQN }) ann.second else null
|
||||||
}
|
}
|
||||||
resolver.second.resolve(getFile(file), supportedAnnotations, context)
|
resolver.second.resolve(getFile(file), supportedAnnotations, environment)
|
||||||
}
|
}
|
||||||
return KotlinScriptExternalDependenciesUnion(fileDeps)
|
return KotlinScriptExternalDependenciesUnion(fileDeps)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -34,7 +34,7 @@ interface ScriptTemplateProvider {
|
|||||||
|
|
||||||
val dependenciesClasspath: Iterable<String>
|
val dependenciesClasspath: Iterable<String>
|
||||||
|
|
||||||
val context: Any?
|
val environment: Map<String, Any?>?
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val EP_NAME = ExtensionPointName.create<ScriptTemplateProvider>("org.jetbrains.kotlin.scriptTemplateProvider")
|
val EP_NAME = ExtensionPointName.create<ScriptTemplateProvider>("org.jetbrains.kotlin.scriptTemplateProvider")
|
||||||
@@ -56,7 +56,7 @@ fun makeScriptDefsFromTemplateProviders(providers: Iterable<ScriptTemplateProvid
|
|||||||
val loader = URLClassLoader(it.dependenciesClasspath.map { File(it).toURI().toURL() }.toTypedArray(), ScriptTemplateProvider::class.java.classLoader)
|
val loader = URLClassLoader(it.dependenciesClasspath.map { File(it).toURI().toURL() }.toTypedArray(), ScriptTemplateProvider::class.java.classLoader)
|
||||||
val cl = loader.loadClass(it.templateClassName)
|
val cl = loader.loadClass(it.templateClassName)
|
||||||
idToVersion.put(it.id, it.version)
|
idToVersion.put(it.id, it.version)
|
||||||
KotlinScriptDefinitionFromTemplate(cl.kotlin, it.context)
|
KotlinScriptDefinitionFromTemplate(cl.kotlin, it.environment)
|
||||||
}
|
}
|
||||||
catch (ex: Exception) {
|
catch (ex: Exception) {
|
||||||
errorsHandler(it, ex)
|
errorsHandler(it, ex)
|
||||||
|
|||||||
@@ -69,10 +69,10 @@ class ScriptTest2 {
|
|||||||
private fun compileScript(
|
private fun compileScript(
|
||||||
scriptPath: String,
|
scriptPath: String,
|
||||||
scriptBase: KClass<out Any>,
|
scriptBase: KClass<out Any>,
|
||||||
context: Any? = null,
|
environment: Map<String, Any?>? = null,
|
||||||
runIsolated: Boolean = true,
|
runIsolated: Boolean = true,
|
||||||
suppressOutput: Boolean = false): Class<*>? =
|
suppressOutput: Boolean = false): Class<*>? =
|
||||||
compileScriptImpl("compiler/testData/script/" + scriptPath, KotlinScriptDefinitionFromTemplate(scriptBase, context), runIsolated, suppressOutput)
|
compileScriptImpl("compiler/testData/script/" + scriptPath, KotlinScriptDefinitionFromTemplate(scriptBase, environment), runIsolated, suppressOutput)
|
||||||
|
|
||||||
private fun compileScriptImpl(
|
private fun compileScriptImpl(
|
||||||
scriptPath: String,
|
scriptPath: String,
|
||||||
@@ -120,7 +120,7 @@ class TestKotlinScriptDependenciesResolver : ScriptDependenciesResolver {
|
|||||||
|
|
||||||
private val kotlinPaths by lazy { PathUtil.getKotlinPathsForCompiler() }
|
private val kotlinPaths by lazy { PathUtil.getKotlinPathsForCompiler() }
|
||||||
|
|
||||||
override fun resolve(scriptFile: File?, annotations: Iterable<Annotation>, context: Any?): KotlinScriptExternalDependencies? {
|
override fun resolve(scriptFile: File?, annotations: Iterable<Annotation>, environment: Map<String, Any?>?): KotlinScriptExternalDependencies? {
|
||||||
val cp = annotations.flatMap {
|
val cp = annotations.flatMap {
|
||||||
when (it) {
|
when (it) {
|
||||||
is depends -> listOf(if (it.path == "@{runtime}") kotlinPaths.runtimePath else File(it.path))
|
is depends -> listOf(if (it.path == "@{runtime}") kotlinPaths.runtimePath else File(it.path))
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ class GradleScriptTemplateProvider(project: Project, gim: GradleInstallationMana
|
|||||||
gradleLibsPath?.listFiles { file -> file.extension == "jar" && depLibsPrefixes.any { file.name.startsWith(it) } }
|
gradleLibsPath?.listFiles { file -> file.extension == "jar" && depLibsPrefixes.any { file.name.startsWith(it) } }
|
||||||
?.map { it.canonicalPath }
|
?.map { it.canonicalPath }
|
||||||
?: emptyList()
|
?: emptyList()
|
||||||
override val context: Any? = gradleHome
|
override val environment: Map<String, Any?>? = kotlin.collections.mapOf("gradleHome" to gradleHome)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val depLibsPrefixes = listOf("gradle-script-kotlin", "gradle-core")
|
private val depLibsPrefixes = listOf("gradle-script-kotlin", "gradle-core")
|
||||||
|
|||||||
Reference in New Issue
Block a user