GradleBuildRootsManager: check gradle version change in gradle-wrapper.properties
This commit is contained in:
+13
-7
@@ -28,10 +28,12 @@ abstract class GradleBuildRootsLocator {
|
|||||||
private val VirtualFile.localPath
|
private val VirtualFile.localPath
|
||||||
get() = path
|
get() = path
|
||||||
|
|
||||||
|
private val gradleWrapperEnding = "/gradle/wrapper/gradle-wrapper.properties"
|
||||||
|
|
||||||
fun maybeAffectedGradleProjectFile(filePath: String): Boolean =
|
fun maybeAffectedGradleProjectFile(filePath: String): Boolean =
|
||||||
filePath.endsWith("/gradle.properties") ||
|
filePath.endsWith("/gradle.properties") ||
|
||||||
filePath.endsWith("/gradle.local") ||
|
filePath.endsWith("/gradle.local") ||
|
||||||
filePath.endsWith("/gradle-wrapper.properties") ||
|
filePath.endsWith(gradleWrapperEnding) ||
|
||||||
filePath.endsWith(".gradle.kts")
|
filePath.endsWith(".gradle.kts")
|
||||||
|
|
||||||
fun isAffectedGradleProjectFile(filePath: String): Boolean =
|
fun isAffectedGradleProjectFile(filePath: String): Boolean =
|
||||||
@@ -43,14 +45,18 @@ abstract class GradleBuildRootsLocator {
|
|||||||
filePath.endsWith("/gradle.local")
|
filePath.endsWith("/gradle.local")
|
||||||
) {
|
) {
|
||||||
return roots.getBuildByProjectDir(filePath.substringBeforeLast("/"))
|
return roots.getBuildByProjectDir(filePath.substringBeforeLast("/"))
|
||||||
} else if (filePath.endsWith("/gradle-wrapper.properties")) {
|
|
||||||
val gradleWrapperDirIndex = filePath.lastIndexOfOrNull('/') ?: return null
|
|
||||||
val gradleDirIndex = filePath.lastIndexOfOrNull('/', gradleWrapperDirIndex - 1) ?: return null
|
|
||||||
val buildDirIndex = filePath.lastIndexOfOrNull('/', gradleDirIndex - 1) ?: return null
|
|
||||||
return roots.getBuildByRootDir(filePath.substring(0, buildDirIndex))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return findScriptBuildRoot(filePath, searchNearestLegacy = false)?.root as? GradleBuildRoot
|
return findGradleWrapperPropertiesBuildDir(filePath)?.let { roots.getBuildByRootDir(it) }
|
||||||
|
?: findScriptBuildRoot(filePath, searchNearestLegacy = false)?.root
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findGradleWrapperPropertiesBuildDir(filePath: String): String? {
|
||||||
|
if (filePath.endsWith(gradleWrapperEnding)) {
|
||||||
|
return filePath.substring(0, filePath.length - gradleWrapperEnding.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EnumEntryName")
|
@Suppress("EnumEntryName")
|
||||||
|
|||||||
+28
-10
@@ -36,6 +36,7 @@ import java.nio.file.FileSystems
|
|||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.nio.file.attribute.BasicFileAttributes
|
import java.nio.file.attribute.BasicFileAttributes
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +111,7 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
|
|
||||||
fun fileChanged(filePath: String, ts: Long = System.currentTimeMillis()) {
|
fun fileChanged(filePath: String, ts: Long = System.currentTimeMillis()) {
|
||||||
findAffectedFileRoot(filePath)?.fileChanged(filePath, ts)
|
findAffectedFileRoot(filePath)?.fileChanged(filePath, ts)
|
||||||
scheduleLastModifiedFilesSave()
|
scheduleModifiedFilesCheck(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun markImportingInProgress(workingDir: String, inProgress: Boolean = true) {
|
fun markImportingInProgress(workingDir: String, inProgress: Boolean = true) {
|
||||||
@@ -156,22 +157,39 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
return GradleBuildRootData(new.importTs, roots, new.templateClasspath, models.values)
|
return GradleBuildRootData(new.importTs, roots, new.templateClasspath, models.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val lastModifiedFilesSaveScheduled = AtomicBoolean()
|
private val modifiedFilesCheckScheduled = AtomicBoolean()
|
||||||
|
private val modifiedFiles = ConcurrentLinkedQueue<String>()
|
||||||
|
|
||||||
fun scheduleLastModifiedFilesSave() {
|
fun scheduleModifiedFilesCheck(filePath: String) {
|
||||||
if (lastModifiedFilesSaveScheduled.compareAndSet(false, true)) {
|
modifiedFiles.add(filePath)
|
||||||
|
if (modifiedFilesCheckScheduled.compareAndSet(false, true)) {
|
||||||
BackgroundTaskUtil.executeOnPooledThread(project) {
|
BackgroundTaskUtil.executeOnPooledThread(project) {
|
||||||
if (lastModifiedFilesSaveScheduled.compareAndSet(true, false)) {
|
if (modifiedFilesCheckScheduled.compareAndSet(true, false)) {
|
||||||
updateNotifications(restartAnalyzer = false) { true }
|
checkModifiedFiles()
|
||||||
|
|
||||||
roots.list.forEach {
|
|
||||||
it.saveLastModifiedFiles()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkModifiedFiles() {
|
||||||
|
updateNotifications(restartAnalyzer = false) { true }
|
||||||
|
|
||||||
|
roots.list.forEach {
|
||||||
|
it.saveLastModifiedFiles()
|
||||||
|
}
|
||||||
|
|
||||||
|
// process modifiedFiles queue
|
||||||
|
while (true) {
|
||||||
|
val file = modifiedFiles.poll() ?: break
|
||||||
|
|
||||||
|
// detect gradle version change
|
||||||
|
val buildDir = findGradleWrapperPropertiesBuildDir(file)
|
||||||
|
if (buildDir != null) {
|
||||||
|
actualizeBuildRoot(buildDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun updateStandaloneScripts(update: StandaloneScriptsUpdater.() -> Unit) {
|
fun updateStandaloneScripts(update: StandaloneScriptsUpdater.() -> Unit) {
|
||||||
val changes = StandaloneScriptsUpdater.collectChanges(delegate = roots, update)
|
val changes = StandaloneScriptsUpdater.collectChanges(delegate = roots, update)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user