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:
+32
-27
@@ -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
|
||||
|
||||
try {
|
||||
val newRoot = updateRoot(oldRoot, sync)
|
||||
if (newRoot == null) {
|
||||
markImportingInProgress(sync.workingDir, false)
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
if (oldRoot is Imported && oldRoot.data.models.isEmpty()) return null
|
||||
}
|
||||
|
||||
scriptingDebugLog { "save gradle project info after import: $sync" }
|
||||
if (oldRoot is Legacy) return null
|
||||
|
||||
if (oldRoot is Legacy) {
|
||||
oldRoot.importing.set(updated)
|
||||
return
|
||||
scriptingDebugLog { "gradle project info after import: $sync" }
|
||||
|
||||
// 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 null
|
||||
}
|
||||
|
||||
oldRoot.importing.set(updatingCaches)
|
||||
|
||||
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
|
||||
}
|
||||
scriptingDebugLog { "save script models after import: ${sync.models}" }
|
||||
|
||||
scriptingDebugLog { "save script models after import: ${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 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 newRoot = tryCreateImportedRoot(sync.workingDir, LastModifiedFiles()) { mergedData } ?: return null
|
||||
val buildRootDir = newRoot.dir ?: return null
|
||||
|
||||
val lastModifiedFilesReset = LastModifiedFiles()
|
||||
val newRoot = tryCreateImportedRoot(sync.workingDir, lastModifiedFilesReset) { mergedData } ?: return
|
||||
GradleBuildRootDataSerializer.write(newRoot.dir ?: return, mergedData)
|
||||
newRoot.saveLastModifiedFiles()
|
||||
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