Mark importing as complete in case of some unexpected behavior
For example in case when script contains some errors gradleHome might be null Then build root should be marked as updated Also notification should be updated
This commit is contained in:
+29
-24
@@ -33,7 +33,6 @@ import org.jetbrains.plugins.gradle.config.GradleSettingsListenerAdapter
|
|||||||
import org.jetbrains.plugins.gradle.service.GradleInstallationManager
|
import org.jetbrains.plugins.gradle.service.GradleInstallationManager
|
||||||
import org.jetbrains.plugins.gradle.settings.*
|
import org.jetbrains.plugins.gradle.settings.*
|
||||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||||
import java.io.File
|
|
||||||
import java.nio.file.FileSystems
|
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
|
||||||
@@ -140,45 +139,51 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
fun update(sync: KotlinDslGradleBuildSync) {
|
fun update(sync: KotlinDslGradleBuildSync) {
|
||||||
val oldRoot = actualizeBuildRoot(sync.workingDir, sync.gradleVersion) ?: return
|
val oldRoot = actualizeBuildRoot(sync.workingDir, sync.gradleVersion) ?: return
|
||||||
|
|
||||||
// fast path for linked gradle builds without .gradle.kts support
|
try {
|
||||||
if (sync.models.isEmpty()) {
|
val newRoot = updateRoot(oldRoot, sync)
|
||||||
if (oldRoot is Imported && oldRoot.data.models.isEmpty()) return
|
if (newRoot == null) {
|
||||||
}
|
markImportingInProgress(sync.workingDir, false)
|
||||||
|
|
||||||
scriptingDebugLog { "save gradle project info after import: $sync" }
|
|
||||||
|
|
||||||
if (oldRoot is Legacy) {
|
|
||||||
oldRoot.importing.set(updated)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
oldRoot.importing.set(updatingCaches)
|
add(newRoot)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
markImportingInProgress(sync.workingDir, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateRoot(oldRoot: GradleBuildRoot, sync: KotlinDslGradleBuildSync): Imported? {
|
||||||
|
// fast path for linked gradle builds without .gradle.kts support
|
||||||
|
if (sync.models.isEmpty()) {
|
||||||
|
if (oldRoot is Imported && oldRoot.data.models.isEmpty()) return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldRoot is Legacy) return null
|
||||||
|
|
||||||
|
scriptingDebugLog { "gradle project info after import: $sync" }
|
||||||
|
|
||||||
try {
|
|
||||||
// TODO: can gradleHome be null, what to do in this case
|
// TODO: can gradleHome be null, what to do in this case
|
||||||
val gradleHome = sync.gradleHome
|
val gradleHome = sync.gradleHome
|
||||||
if (gradleHome == null) {
|
if (gradleHome == null) {
|
||||||
scriptingInfoLog("Cannot find valid gradle home for ${sync.gradleHome} with version = ${sync.gradleVersion}, script models cannot be saved")
|
scriptingInfoLog("Cannot find valid gradle home for ${sync.gradleHome} with version = ${sync.gradleVersion}, script models cannot be saved")
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldRoot.importing.set(updatingCaches)
|
||||||
|
|
||||||
scriptingDebugLog { "save script models after import: ${sync.models}" }
|
scriptingDebugLog { "save script models after import: ${sync.models}" }
|
||||||
|
|
||||||
val newData = GradleBuildRootData(
|
val newData = GradleBuildRootData(sync.ts, sync.projectRoots, gradleHome, sync.javaHome, sync.models)
|
||||||
sync.ts, sync.projectRoots, gradleHome, sync.javaHome, sync.models
|
|
||||||
)
|
|
||||||
val mergedData = if (sync.failed && oldRoot is Imported) merge(oldRoot.data, newData) else newData
|
val mergedData = if (sync.failed && oldRoot is Imported) merge(oldRoot.data, newData) else newData
|
||||||
|
|
||||||
val lastModifiedFilesReset = LastModifiedFiles()
|
val newRoot = tryCreateImportedRoot(sync.workingDir, LastModifiedFiles()) { mergedData } ?: return null
|
||||||
val newRoot = tryCreateImportedRoot(sync.workingDir, lastModifiedFilesReset) { mergedData } ?: return
|
val buildRootDir = newRoot.dir ?: return null
|
||||||
GradleBuildRootDataSerializer.write(newRoot.dir ?: return, mergedData)
|
|
||||||
|
GradleBuildRootDataSerializer.write(buildRootDir, mergedData)
|
||||||
newRoot.saveLastModifiedFiles()
|
newRoot.saveLastModifiedFiles()
|
||||||
|
|
||||||
add(newRoot)
|
return newRoot
|
||||||
} catch (e: Throwable) {
|
|
||||||
markImportingInProgress(sync.workingDir, false)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun merge(old: GradleBuildRootData, new: GradleBuildRootData): GradleBuildRootData {
|
private fun merge(old: GradleBuildRootData, new: GradleBuildRootData): GradleBuildRootData {
|
||||||
|
|||||||
Reference in New Issue
Block a user