diff --git a/compiler/frontend/src/org/jetbrains/kotlin/script/scriptTemplate.kt b/compiler/frontend/src/org/jetbrains/kotlin/script/scriptTemplate.kt index e3ea0d6bdd3..cf3e1d94cc8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/script/scriptTemplate.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/script/scriptTemplate.kt @@ -37,7 +37,6 @@ annotation class ScriptFilePattern(val pattern: String) interface GetScriptDependencies { operator fun invoke(annotations: Iterable, context: Any?): KotlinScriptExternalDependencies? = null - operator fun invoke(context: Any?): KotlinScriptExternalDependencies? = null } @Target(AnnotationTarget.CLASS) @@ -62,18 +61,14 @@ data class KotlinScriptDefinitionFromTemplate(val template: KClass, val // TODO: implement other strategy - e.g. try to extract something from match with ScriptFilePattern override fun getScriptName(script: KtScript): Name = ScriptNameUtil.fileNameWithExtensionStripped(script, KotlinParserDefinition.STD_SCRIPT_EXT) - private val dependenciesExtractors by lazy { + private val dependenciesResolvers by lazy { template.annotations.mapNotNull { it as? ScriptDependencyResolver }.map { it.extractor.constructors.first().call() } } - private val dependencies: List by lazy { - dependenciesExtractors.mapNotNull { it(context) } - } - override fun getDependenciesFor(file: TF, project: Project): KotlinScriptExternalDependencies? { val fileAnnotations = getAnnotationEntries(file, project) - val fileDeps = dependenciesExtractors.mapNotNull { it(fileAnnotations, context) } - return KotlinScriptExternalDependenciesUnion(dependencies + fileDeps) + val fileDeps = dependenciesResolvers.mapNotNull { it(fileAnnotations, context) } + return KotlinScriptExternalDependenciesUnion(fileDeps) } private fun getAnnotationEntries(file: TF, project: Project): Iterable = when (file) { diff --git a/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTest2.kt b/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTest2.kt index f482916f1c9..a9c5e265a22 100644 --- a/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTest2.kt +++ b/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTest2.kt @@ -119,7 +119,6 @@ class GetTestKotlinScriptDependencies : GetScriptDependencies { private val kotlinPaths by lazy { PathUtil.getKotlinPathsForCompiler() } override fun invoke(annotations: Iterable, context: Any?): KotlinScriptExternalDependencies? { - if (annotations.none()) return null val anns = annotations.map { parseAnnotation(it) }.filter { it.name == depends::class.simpleName } val cp = anns.flatMap { it.value.mapNotNull { @@ -130,7 +129,7 @@ class GetTestKotlinScriptDependencies : GetScriptDependencies { } } return object : KotlinScriptExternalDependencies { - override val classpath = cp + override val classpath = classpathFromClassloader() + cp } } @@ -139,12 +138,6 @@ class GetTestKotlinScriptDependencies : GetScriptDependencies { ?.mapNotNull { it.toFile()?.canonicalPath } ?.filter { it.contains("out/test") } ?: emptyList() - - override fun invoke(context: Any?): KotlinScriptExternalDependencies? { - return object : KotlinScriptExternalDependencies { - override val classpath = classpathFromClassloader() - } - } } @ScriptFilePattern(".*\\.kts")