From c67df1928123e5601d549b02558081751258eaa2 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Fri, 23 Nov 2018 16:36:01 +0100 Subject: [PATCH] Improve classpath calculation for locally-defined script templates Since at least in gradle-imported projects, the template could be found in several modules, some of them - incomplete (parent/buildscript module) the previous logic of filtering for already processed templates and roots is incorrect, and therefore removed. Also fixes the exception in our project "cannot load script definition" --- .../script/scriptsTemplatesFromDependencies.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/script/scriptsTemplatesFromDependencies.kt b/idea/src/org/jetbrains/kotlin/idea/script/scriptsTemplatesFromDependencies.kt index 7e7d2b25856..561f9c4408f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/script/scriptsTemplatesFromDependencies.kt +++ b/idea/src/org/jetbrains/kotlin/idea/script/scriptsTemplatesFromDependencies.kt @@ -60,19 +60,17 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc val processedRoots = hashSetOf() fun addTemplatesFromRoot(vfile: VirtualFile): Boolean { - var newTemplatesFound = false - if (!processedRoots.contains(vfile)) { - processedRoots.add(vfile) - val root = JarFileSystem.getInstance().getJarRootForLocalFile(vfile) ?: vfile - if (root.isValid) { - root.findFileByRelativePath(templatesPath)?.takeIf { it.isDirectory }?.children?.forEach { - if (it.isValid && !it.isDirectory && templates.add(it.name)) { - newTemplatesFound = true - } + var templatesFound = false + val root = JarFileSystem.getInstance().getJarRootForLocalFile(vfile) ?: vfile + if (root.isValid) { + root.findFileByRelativePath(templatesPath)?.takeIf { it.isDirectory }?.children?.forEach { + if (it.isValid && !it.isDirectory) { + templates.add(it.name) + templatesFound = true } } } - return newTemplatesFound + return templatesFound } // processing source roots from the same project first since the resources are copied to the classes roots only on compilation