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.settings.*
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||
import java.io.File
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
@@ -140,45 +139,51 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
||||
fun update(sync: KotlinDslGradleBuildSync) {
|
||||
val oldRoot = actualizeBuildRoot(sync.workingDir, sync.gradleVersion) ?: return
|
||||
|
||||
// fast path for linked gradle builds without .gradle.kts support
|
||||
if (sync.models.isEmpty()) {
|
||||
if (oldRoot is Imported && oldRoot.data.models.isEmpty()) return
|
||||
}
|
||||
|
||||
scriptingDebugLog { "save gradle project info after import: $sync" }
|
||||
|
||||
if (oldRoot is Legacy) {
|
||||
oldRoot.importing.set(updated)
|
||||
try {
|
||||
val newRoot = updateRoot(oldRoot, sync)
|
||||
if (newRoot == null) {
|
||||
markImportingInProgress(sync.workingDir, false)
|
||||
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
|
||||
val gradleHome = sync.gradleHome
|
||||
if (gradleHome == null) {
|
||||
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}" }
|
||||
|
||||
val newData = GradleBuildRootData(
|
||||
sync.ts, sync.projectRoots, gradleHome, sync.javaHome, sync.models
|
||||
)
|
||||
val newData = GradleBuildRootData(sync.ts, sync.projectRoots, gradleHome, sync.javaHome, sync.models)
|
||||
val mergedData = if (sync.failed && oldRoot is Imported) merge(oldRoot.data, newData) else newData
|
||||
|
||||
val lastModifiedFilesReset = LastModifiedFiles()
|
||||
val newRoot = tryCreateImportedRoot(sync.workingDir, lastModifiedFilesReset) { mergedData } ?: return
|
||||
GradleBuildRootDataSerializer.write(newRoot.dir ?: return, mergedData)
|
||||
val newRoot = tryCreateImportedRoot(sync.workingDir, LastModifiedFiles()) { mergedData } ?: return null
|
||||
val buildRootDir = newRoot.dir ?: return null
|
||||
|
||||
GradleBuildRootDataSerializer.write(buildRootDir, mergedData)
|
||||
newRoot.saveLastModifiedFiles()
|
||||
|
||||
add(newRoot)
|
||||
} catch (e: Throwable) {
|
||||
markImportingInProgress(sync.workingDir, false)
|
||||
throw e
|
||||
}
|
||||
return newRoot
|
||||
}
|
||||
|
||||
private fun merge(old: GradleBuildRootData, new: GradleBuildRootData): GradleBuildRootData {
|
||||
|
||||
Reference in New Issue
Block a user