GradleBuildRoot: require LastModifiedFiles explicitly
This commit is contained in:
+24
-40
@@ -17,10 +17,6 @@ import org.jetbrains.kotlin.scripting.resolve.VirtualFileScriptSource
|
|||||||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings
|
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@set:TestOnly
|
|
||||||
@get:TestOnly
|
|
||||||
internal var skipLastModifiedFilesLoading = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [GradleBuildRoot] is a linked gradle build (don't confuse with gradle project and included build).
|
* [GradleBuildRoot] is a linked gradle build (don't confuse with gradle project and included build).
|
||||||
* Each [GradleBuildRoot] may have it's own Gradle version, Java home and other settings.
|
* Each [GradleBuildRoot] may have it's own Gradle version, Java home and other settings.
|
||||||
@@ -29,7 +25,7 @@ internal var skipLastModifiedFilesLoading = false
|
|||||||
*
|
*
|
||||||
* See [GradleBuildRootsManager] for more details.
|
* See [GradleBuildRootsManager] for more details.
|
||||||
*/
|
*/
|
||||||
sealed class GradleBuildRoot {
|
sealed class GradleBuildRoot(private val lastModifiedFiles: LastModifiedFiles) {
|
||||||
@Volatile
|
@Volatile
|
||||||
var importing = false
|
var importing = false
|
||||||
|
|
||||||
@@ -40,18 +36,6 @@ sealed class GradleBuildRoot {
|
|||||||
val dir: VirtualFile?
|
val dir: VirtualFile?
|
||||||
get() = LocalFileSystem.getInstance().findFileByPath(pathPrefix)
|
get() = LocalFileSystem.getInstance().findFileByPath(pathPrefix)
|
||||||
|
|
||||||
private lateinit var lastModifiedFiles: LastModifiedFiles
|
|
||||||
|
|
||||||
fun loadLastModifiedFiles() {
|
|
||||||
val loaded = if (!skipLastModifiedFilesLoading) {
|
|
||||||
val dir = dir
|
|
||||||
if (dir != null) LastModifiedFiles.read(dir)
|
|
||||||
else null
|
|
||||||
} else null
|
|
||||||
|
|
||||||
lastModifiedFiles = loaded ?: LastModifiedFiles()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveLastModifiedFiles() {
|
fun saveLastModifiedFiles() {
|
||||||
LastModifiedFiles.write(dir ?: return, lastModifiedFiles)
|
LastModifiedFiles.write(dir ?: return, lastModifiedFiles)
|
||||||
}
|
}
|
||||||
@@ -64,36 +48,29 @@ sealed class GradleBuildRoot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class WithoutScriptModels(settings: GradleProjectSettings) : GradleBuildRoot() {
|
sealed class WithoutScriptModels(
|
||||||
|
settings: GradleProjectSettings,
|
||||||
|
lastModifiedFiles: LastModifiedFiles
|
||||||
|
) : GradleBuildRoot(lastModifiedFiles) {
|
||||||
final override val pathPrefix = settings.externalProjectPath!!
|
final override val pathPrefix = settings.externalProjectPath!!
|
||||||
final override val projectRoots = settings.modules.takeIf { it.isNotEmpty() } ?: listOf(pathPrefix)
|
final override val projectRoots = settings.modules.takeIf { it.isNotEmpty() } ?: listOf(pathPrefix)
|
||||||
|
|
||||||
init {
|
|
||||||
loadLastModifiedFiles()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gradle build with old Gradle version (<6.0)
|
* Gradle build with old Gradle version (<6.0)
|
||||||
*/
|
*/
|
||||||
class Legacy(
|
class Legacy(
|
||||||
settings: GradleProjectSettings
|
settings: GradleProjectSettings,
|
||||||
) : WithoutScriptModels(settings) {
|
lastModifiedFiles: LastModifiedFiles = settings.loadLastModifiedFiles() ?: LastModifiedFiles()
|
||||||
init {
|
) : WithoutScriptModels(settings, lastModifiedFiles)
|
||||||
loadLastModifiedFiles()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linked but not yet imported Gradle build.
|
* Linked but not yet imported Gradle build.
|
||||||
*/
|
*/
|
||||||
class New(
|
class New(
|
||||||
settings: GradleProjectSettings
|
settings: GradleProjectSettings,
|
||||||
) : WithoutScriptModels(settings) {
|
lastModifiedFiles: LastModifiedFiles = settings.loadLastModifiedFiles() ?: LastModifiedFiles()
|
||||||
init {
|
) : WithoutScriptModels(settings, lastModifiedFiles)
|
||||||
loadLastModifiedFiles()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imported Gradle build.
|
* Imported Gradle build.
|
||||||
@@ -102,15 +79,12 @@ class New(
|
|||||||
class Imported(
|
class Imported(
|
||||||
override val pathPrefix: String,
|
override val pathPrefix: String,
|
||||||
val javaHome: File?,
|
val javaHome: File?,
|
||||||
val data: GradleBuildRootData
|
val data: GradleBuildRootData,
|
||||||
) : GradleBuildRoot() {
|
lastModifiedFiles: LastModifiedFiles
|
||||||
|
) : GradleBuildRoot(lastModifiedFiles) {
|
||||||
override val projectRoots: Collection<String>
|
override val projectRoots: Collection<String>
|
||||||
get() = data.projectRoots
|
get() = data.projectRoots
|
||||||
|
|
||||||
init {
|
|
||||||
loadLastModifiedFiles()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun collectConfigurations(builder: ScriptClassRootsBuilder) {
|
fun collectConfigurations(builder: ScriptClassRootsBuilder) {
|
||||||
if (javaHome != null) {
|
if (javaHome != null) {
|
||||||
builder.sdks.addSdk(javaHome)
|
builder.sdks.addSdk(javaHome)
|
||||||
@@ -140,4 +114,14 @@ class Imported(
|
|||||||
val scriptSource = VirtualFileScriptSource(file)
|
val scriptSource = VirtualFileScriptSource(file)
|
||||||
return definitions.firstOrNull { it.isScript(scriptSource) }
|
return definitions.firstOrNull { it.isScript(scriptSource) }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun GradleProjectSettings.loadLastModifiedFiles(): LastModifiedFiles? {
|
||||||
|
val externalProjectPath = externalProjectPath ?: return null
|
||||||
|
return loadLastModifiedFiles(externalProjectPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadLastModifiedFiles(rootDirPath: String): LastModifiedFiles? {
|
||||||
|
val vFile = LocalFileSystem.getInstance().findFileByPath(rootDirPath) ?: return null
|
||||||
|
return LastModifiedFiles.read(vFile)
|
||||||
}
|
}
|
||||||
+13
-8
@@ -128,14 +128,16 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
val root = actualizeBuildRoot(build.workingDir) ?: return
|
val root = actualizeBuildRoot(build.workingDir) ?: return
|
||||||
root.importing = false
|
root.importing = false
|
||||||
|
|
||||||
if (root is Legacy) return
|
if (root is Legacy) return
|
||||||
|
|
||||||
val templateClasspath = GradleScriptDefinitionsContributor.getDefinitionsTemplateClasspath(project)
|
val templateClasspath = GradleScriptDefinitionsContributor.getDefinitionsTemplateClasspath(project)
|
||||||
val newData = GradleBuildRootData(build.projectRoots, templateClasspath, build.models)
|
val newData = GradleBuildRootData(build.projectRoots, templateClasspath, build.models)
|
||||||
val mergedData = if (build.failed && root is Imported) merge(root.data, newData) else newData
|
val mergedData = if (build.failed && root is Imported) merge(root.data, newData) else newData
|
||||||
|
|
||||||
val newSupport = tryCreateImportedRoot(build.workingDir) { mergedData } ?: return
|
val lastModifiedFilesReset = LastModifiedFiles()
|
||||||
GradleBuildRootDataSerializer.write(newSupport.dir ?: return, mergedData)
|
val newSupport = tryCreateImportedRoot(build.workingDir, lastModifiedFilesReset) { mergedData } ?: return
|
||||||
|
GradleBuildRootDataSerializer.write(newSupport.dir ?: return, mergedData)
|
||||||
|
newSupport.saveLastModifiedFiles()
|
||||||
|
|
||||||
add(newSupport)
|
add(newSupport)
|
||||||
|
|
||||||
@@ -285,6 +287,7 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
|
|
||||||
private fun tryCreateImportedRoot(
|
private fun tryCreateImportedRoot(
|
||||||
externalProjectPath: String,
|
externalProjectPath: String,
|
||||||
|
lastModifiedFiles: LastModifiedFiles = loadLastModifiedFiles(externalProjectPath) ?: LastModifiedFiles(),
|
||||||
dataProvider: (buildRoot: VirtualFile) -> GradleBuildRootData?
|
dataProvider: (buildRoot: VirtualFile) -> GradleBuildRootData?
|
||||||
): Imported? {
|
): Imported? {
|
||||||
val buildRoot = VfsUtil.findFile(Paths.get(externalProjectPath), true) ?: return null
|
val buildRoot = VfsUtil.findFile(Paths.get(externalProjectPath), true) ?: return null
|
||||||
@@ -293,12 +296,14 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
.getExecutionSettings<GradleExecutionSettings>(project, externalProjectPath, GradleConstants.SYSTEM_ID)
|
.getExecutionSettings<GradleExecutionSettings>(project, externalProjectPath, GradleConstants.SYSTEM_ID)
|
||||||
.javaHome?.let { File(it) }
|
.javaHome?.let { File(it) }
|
||||||
|
|
||||||
return Imported(externalProjectPath, javaHome, data)
|
return Imported(externalProjectPath, javaHome, data, lastModifiedFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun add(newRoot: GradleBuildRoot) {
|
private fun add(newRoot: GradleBuildRoot) {
|
||||||
val old = roots.add(newRoot)
|
val old = roots.add(newRoot)
|
||||||
if (old is Imported && newRoot !is Imported) removeData(old.pathPrefix)
|
if (old is Imported && newRoot !is Imported) {
|
||||||
|
removeData(old.pathPrefix)
|
||||||
|
}
|
||||||
if (old is Imported || newRoot is Imported) {
|
if (old is Imported || newRoot is Imported) {
|
||||||
updater.invalidateAndCommit()
|
updater.invalidateAndCommit()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -6,14 +6,11 @@
|
|||||||
package org.jetbrains.kotlin.idea.scripting.gradle.roots
|
package org.jetbrains.kotlin.idea.scripting.gradle.roots
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.scripting.gradle.GradleKotlinScriptConfigurationInputs
|
import org.jetbrains.kotlin.idea.scripting.gradle.GradleKotlinScriptConfigurationInputs
|
||||||
|
import org.jetbrains.kotlin.idea.scripting.gradle.LastModifiedFiles
|
||||||
import org.jetbrains.kotlin.idea.scripting.gradle.importing.KotlinDslScriptModel
|
import org.jetbrains.kotlin.idea.scripting.gradle.importing.KotlinDslScriptModel
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
open class AbstractGradleBuildRootsLocatorTest {
|
open class AbstractGradleBuildRootsLocatorTest {
|
||||||
init {
|
|
||||||
skipLastModifiedFilesLoading = true
|
|
||||||
}
|
|
||||||
|
|
||||||
private val scripts = mutableMapOf<String, GradleScriptInfo>()
|
private val scripts = mutableMapOf<String, GradleScriptInfo>()
|
||||||
private val locator = MyRootsLocator()
|
private val locator = MyRootsLocator()
|
||||||
|
|
||||||
@@ -39,7 +36,8 @@ open class AbstractGradleBuildRootsLocatorTest {
|
|||||||
relativeProjectRoots.map { (pathPrefix + it).removeSuffix("/") },
|
relativeProjectRoots.map { (pathPrefix + it).removeSuffix("/") },
|
||||||
listOf(),
|
listOf(),
|
||||||
listOf()
|
listOf()
|
||||||
)
|
),
|
||||||
|
LastModifiedFiles()
|
||||||
)
|
)
|
||||||
|
|
||||||
add(root)
|
add(root)
|
||||||
|
|||||||
Reference in New Issue
Block a user