Module info has to be read under readAction in scriptDefinitionsFromDependencies
#EA-220355 Fixed
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.script
|
package org.jetbrains.kotlin.idea.script
|
||||||
|
|
||||||
import com.intellij.ProjectTopics
|
import com.intellij.ProjectTopics
|
||||||
|
import com.intellij.openapi.application.runReadAction
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.roots.ModuleRootEvent
|
import com.intellij.openapi.roots.ModuleRootEvent
|
||||||
import com.intellij.openapi.roots.ModuleRootListener
|
import com.intellij.openapi.roots.ModuleRootListener
|
||||||
@@ -96,28 +97,31 @@ private fun scriptDefinitionsFromDependencies(project: Project): TemplatesWithCp
|
|||||||
return templatesFound
|
return templatesFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// processing source roots from the same project first since the resources are copied to the classes roots only on compilation
|
runReadAction {
|
||||||
project.allModules().forEach { module ->
|
if (project.isDisposed) return@runReadAction
|
||||||
OrderEnumerator.orderEntries(module).withoutDepModules().withoutLibraries().withoutSdk().sourceRoots.forEach { root ->
|
// processing source roots from the same project first since the resources are copied to the classes roots only on compilation
|
||||||
if (addTemplatesFromRoot(root)) {
|
project.allModules().forEach { module ->
|
||||||
classpath.addAll(OrderEnumerator.orderEntries(module).withoutSdk().classesRoots.mapNotNull {
|
OrderEnumerator.orderEntries(module).withoutDepModules().withoutLibraries().withoutSdk().sourceRoots.forEach { root ->
|
||||||
it.canonicalPath?.removeSuffix("!/").let(::File)
|
if (addTemplatesFromRoot(root)) {
|
||||||
})
|
classpath.addAll(OrderEnumerator.orderEntries(module).withoutSdk().classesRoots.mapNotNull {
|
||||||
|
it.canonicalPath?.removeSuffix("!/").let(::File)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
project.allModules().forEach { module ->
|
project.allModules().forEach { module ->
|
||||||
// assuming that all libraries are placed into classes roots
|
// assuming that all libraries are placed into classes roots
|
||||||
// TODO: extract exact library dependencies instead of putting all module dependencies into classpath
|
// TODO: extract exact library dependencies instead of putting all module dependencies into classpath
|
||||||
OrderEnumerator.orderEntries(module).withoutDepModules().withoutSdk().classesRoots.forEach { root ->
|
OrderEnumerator.orderEntries(module).withoutDepModules().withoutSdk().classesRoots.forEach { root ->
|
||||||
if (addTemplatesFromRoot(root)) {
|
if (addTemplatesFromRoot(root)) {
|
||||||
// minimizing the classpath needed to use the template by taking cp only from modules with new templates found
|
// minimizing the classpath needed to use the template by taking cp only from modules with new templates found
|
||||||
// on the other hand the approach may fail if some module contains a template without proper classpath, while
|
// on the other hand the approach may fail if some module contains a template without proper classpath, while
|
||||||
// the other has properly configured classpath, so assuming that the dependencies are set correctly everywhere
|
// the other has properly configured classpath, so assuming that the dependencies are set correctly everywhere
|
||||||
classpath.addAll(OrderEnumerator.orderEntries(module).withoutSdk().classesRoots.mapNotNull {
|
classpath.addAll(OrderEnumerator.orderEntries(module).withoutSdk().classesRoots.mapNotNull {
|
||||||
it.canonicalPath?.removeSuffix("!/").let(::File)
|
it.canonicalPath?.removeSuffix("!/").let(::File)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user