Switch to File instead of String for classpaths in script dependencies
This commit is contained in:
committed by
Pavel V. Talanov
parent
5e3ba36cc1
commit
64bb47ed37
+4
-4
@@ -44,7 +44,7 @@ data class KotlinConfigurableScriptDefinition(val config: KotlinScriptConfig, va
|
||||
|
||||
override fun getScriptName(script: KtScript): Name = ScriptNameUtil.fileNameWithExtensionStripped(script, KotlinParserDefinition.STD_SCRIPT_EXT)
|
||||
|
||||
private val evaluatedClasspath by lazy { config.classpath.evalWithVars(environmentVars).distinct() }
|
||||
private val evaluatedClasspath by lazy { config.classpath.evalWithVars(environmentVars).map { File(it) }.distinctBy { it.canonicalPath } }
|
||||
|
||||
override fun <TF> getDependenciesFor(file: TF, project: Project): KotlinScriptExternalDependencies? =
|
||||
if (!isScript(file)) null
|
||||
@@ -53,13 +53,13 @@ data class KotlinConfigurableScriptDefinition(val config: KotlinScriptConfig, va
|
||||
when {
|
||||
extDeps != null ->
|
||||
object : KotlinScriptExternalDependencies {
|
||||
override val classpath = evaluatedClasspath + extDeps.classpath.evalWithVars(environmentVars).distinct()
|
||||
override val classpath: Iterable<File> = evaluatedClasspath + extDeps.classpath
|
||||
override val imports = extDeps.imports
|
||||
override val sources = extDeps.sources.evalWithVars(environmentVars).distinct()
|
||||
override val sources: Iterable<File> = extDeps.sources
|
||||
}
|
||||
!evaluatedClasspath.isEmpty() ->
|
||||
object : KotlinScriptExternalDependencies {
|
||||
override val classpath = evaluatedClasspath
|
||||
override val classpath: Iterable<File> = evaluatedClasspath
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -58,15 +58,15 @@ interface KotlinScriptDefinition {
|
||||
}
|
||||
|
||||
interface KotlinScriptExternalDependencies {
|
||||
val classpath: Iterable<String> get() = emptyList()
|
||||
val classpath: Iterable<File> get() = emptyList()
|
||||
val imports: Iterable<String> get() = emptyList()
|
||||
val sources: Iterable<String> get() = emptyList()
|
||||
val sources: Iterable<File> get() = emptyList()
|
||||
}
|
||||
|
||||
class KotlinScriptExternalDependenciesUnion(val dependencies: Iterable<KotlinScriptExternalDependencies>) : KotlinScriptExternalDependencies {
|
||||
override val classpath: Iterable<String> get() = dependencies.flatMap { it.classpath }
|
||||
override val classpath: Iterable<File> get() = dependencies.flatMap { it.classpath }
|
||||
override val imports: Iterable<String> get() = dependencies.flatMap { it.imports }
|
||||
override val sources: Iterable<String> get() = dependencies.flatMap { it.sources }
|
||||
override val sources: Iterable<File> get() = dependencies.flatMap { it.sources }
|
||||
}
|
||||
|
||||
data class ScriptParameter(val name: Name, val type: KotlinType)
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.script
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.io.File
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.concurrent.read
|
||||
import kotlin.concurrent.write
|
||||
@@ -90,11 +91,11 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
||||
}
|
||||
}
|
||||
|
||||
fun getKnownCombinedClasspath(): List<String> = cacheLock.read {
|
||||
fun getKnownCombinedClasspath(): List<File> = cacheLock.read {
|
||||
cache.values.flatMap { it.classpath }
|
||||
}.distinct()
|
||||
|
||||
fun <TF> getCombinedClasspathFor(files: Iterable<TF>): List<String> =
|
||||
fun <TF> getCombinedClasspathFor(files: Iterable<TF>): List<File> =
|
||||
getExternalImports(files)
|
||||
.flatMap { it.classpath }
|
||||
.distinct()
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ import java.util.*
|
||||
class KotlinScriptExternalDependenciesConfig : KotlinScriptExternalDependencies {
|
||||
@Tag("classpath")
|
||||
@AbstractCollection(surroundWithTag = false, elementTag = "path", elementValueAttribute = "")
|
||||
override var classpath: MutableList<String> = ArrayList()
|
||||
override var classpath: Iterable<File> = ArrayList()
|
||||
|
||||
@Tag("imports")
|
||||
@AbstractCollection(surroundWithTag = false, elementTag = "name", elementValueAttribute = "")
|
||||
@@ -38,7 +38,7 @@ class KotlinScriptExternalDependenciesConfig : KotlinScriptExternalDependencies
|
||||
|
||||
@Tag("sources")
|
||||
@AbstractCollection(surroundWithTag = false, elementTag = "path", elementValueAttribute = "")
|
||||
override var sources: MutableList<String> = ArrayList()
|
||||
override var sources: Iterable<File> = ArrayList()
|
||||
}
|
||||
|
||||
fun loadScriptExternalImportConfigs(configFile: File): List<KotlinScriptExternalDependenciesConfig> =
|
||||
|
||||
@@ -75,7 +75,7 @@ data class KotlinScriptDefinitionFromTemplate(val template: KClass<out Any>, val
|
||||
is PsiFile -> getAnnotationEntriesFromPsiFile(file)
|
||||
is VirtualFile -> getAnnotationEntriesFromVirtualFile(file, project)
|
||||
is File -> {
|
||||
val virtualFile = (StandardFileSystems.local().findFileByPath(file.absolutePath)
|
||||
val virtualFile = (StandardFileSystems.local().findFileByPath(file.canonicalPath)
|
||||
?: throw java.lang.IllegalArgumentException("Unable to find file ${file.canonicalPath}"))
|
||||
getAnnotationEntriesFromVirtualFile(virtualFile, project)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user