Add previous imports to resolving interfaces to enable effective caching implementations
This commit is contained in:
committed by
Pavel V. Talanov
parent
f30b402640
commit
4f05f839a3
+1
-1
@@ -46,7 +46,7 @@ data class KotlinConfigurableScriptDefinition(val config: KotlinScriptConfig, va
|
||||
|
||||
private val evaluatedClasspath by lazy { config.classpath.evalWithVars(environmentVars).map { File(it) }.distinctBy { it.canonicalPath } }
|
||||
|
||||
override fun <TF> getDependenciesFor(file: TF, project: Project): KotlinScriptExternalDependencies? =
|
||||
override fun <TF> getDependenciesFor(file: TF, project: Project, previousDependencies: KotlinScriptExternalDependencies?): KotlinScriptExternalDependencies? =
|
||||
if (!isScript(file)) null
|
||||
else {
|
||||
val extDeps = getScriptDependenciesFromConfig(file)
|
||||
|
||||
@@ -54,7 +54,7 @@ interface KotlinScriptDefinition {
|
||||
fun getScriptName(script: KtScript): Name =
|
||||
ScriptNameUtil.fileNameWithExtensionStripped(script, KotlinParserDefinition.STD_SCRIPT_EXT)
|
||||
|
||||
fun <TF> getDependenciesFor(file: TF, project: Project): KotlinScriptExternalDependencies? = null
|
||||
fun <TF> getDependenciesFor(file: TF, project: Project, previousDependencies: KotlinScriptExternalDependencies?): KotlinScriptExternalDependencies? = null
|
||||
}
|
||||
|
||||
interface KotlinScriptExternalDependencies {
|
||||
|
||||
+3
-3
@@ -36,7 +36,7 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
||||
cache[path]
|
||||
?: if (cacheOfNulls.contains(path)) null
|
||||
else scriptDefinitionProvider.findScriptDefinition(file)
|
||||
?.let { it.getDependenciesFor(file, project) }
|
||||
?.let { it.getDependenciesFor(file, project, null) }
|
||||
.apply { cacheLock.write {
|
||||
if (this == null) {
|
||||
cacheOfNulls.add(path)
|
||||
@@ -57,7 +57,7 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
||||
if (!cache.containsKey(path) && !cacheOfNulls.contains(path) && !uncached.contains(path)) {
|
||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||
if (scriptDef != null) {
|
||||
val deps = scriptDef.getDependenciesFor(file, project)
|
||||
val deps = scriptDef.getDependenciesFor(file, project, null)
|
||||
if (deps != null) {
|
||||
cache.put(path, deps)
|
||||
}
|
||||
@@ -78,8 +78,8 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
||||
val path = getFilePath(file)
|
||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||
if (scriptDef != null) {
|
||||
val deps = scriptDef.getDependenciesFor(file, project)
|
||||
val oldDeps = cache[path]
|
||||
val deps = scriptDef.getDependenciesFor(file, project, oldDeps)
|
||||
when {
|
||||
deps != null && (oldDeps == null ||
|
||||
!deps.classpath.isSameClasspathAs(oldDeps.classpath) || !deps.sources.isSameClasspathAs(oldDeps.sources)) -> {
|
||||
|
||||
@@ -41,7 +41,11 @@ import kotlin.reflect.memberProperties
|
||||
annotation class ScriptFilePattern(val pattern: String)
|
||||
|
||||
interface ScriptDependenciesResolver {
|
||||
fun resolve(scriptFile: File?, annotations: Iterable<Annotation>, environment: Map<String, Any?>?): KotlinScriptExternalDependencies? = null
|
||||
fun resolve(scriptFile: File?,
|
||||
annotations: Iterable<Annotation>,
|
||||
environment: Map<String, Any?>?,
|
||||
previousDependencies: KotlinScriptExternalDependencies? = null
|
||||
): KotlinScriptExternalDependencies? = null
|
||||
}
|
||||
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@@ -88,7 +92,7 @@ data class KotlinScriptDefinitionFromTemplate(val template: KClass<out Any>, val
|
||||
return res
|
||||
}
|
||||
|
||||
override fun <TF> getDependenciesFor(file: TF, project: Project): KotlinScriptExternalDependencies? {
|
||||
override fun <TF> getDependenciesFor(file: TF, project: Project, previousDependencies: KotlinScriptExternalDependencies?): KotlinScriptExternalDependencies? {
|
||||
val fileAnnotations = getAnnotationEntries(file, project)
|
||||
.map { KtAnnotationWrapper(it) }
|
||||
.mapNotNull { wrappedAnn ->
|
||||
@@ -111,7 +115,7 @@ data class KotlinScriptDefinitionFromTemplate(val template: KClass<out Any>, val
|
||||
val annFQN = ann.first.qualifiedName
|
||||
if (resolver.first.supportedAnnotationClasses.asIterable2().any { it.qualifiedName == annFQN }) ann.second else null
|
||||
}
|
||||
resolver.second.resolve(getFile(file), supportedAnnotations, environment)
|
||||
resolver.second.resolve(getFile(file), supportedAnnotations, environment, previousDependencies)
|
||||
}
|
||||
return KotlinScriptExternalDependenciesUnion(fileDeps)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user