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.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
|
||||||
|
|
||||||
|
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
|
// fast path for linked gradle builds without .gradle.kts support
|
||||||
if (sync.models.isEmpty()) {
|
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) {
|
scriptingDebugLog { "gradle project info after import: $sync" }
|
||||||
oldRoot.importing.set(updated)
|
|
||||||
return
|
// 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)
|
oldRoot.importing.set(updatingCaches)
|
||||||
|
|
||||||
try {
|
scriptingDebugLog { "save script models after import: ${sync.models}" }
|
||||||
// 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}" }
|
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(
|
val newRoot = tryCreateImportedRoot(sync.workingDir, LastModifiedFiles()) { mergedData } ?: return null
|
||||||
sync.ts, sync.projectRoots, gradleHome, sync.javaHome, sync.models
|
val buildRootDir = newRoot.dir ?: return null
|
||||||
)
|
|
||||||
val mergedData = if (sync.failed && oldRoot is Imported) merge(oldRoot.data, newData) else newData
|
|
||||||
|
|
||||||
val lastModifiedFilesReset = LastModifiedFiles()
|
GradleBuildRootDataSerializer.write(buildRootDir, mergedData)
|
||||||
val newRoot = tryCreateImportedRoot(sync.workingDir, lastModifiedFilesReset) { mergedData } ?: return
|
newRoot.saveLastModifiedFiles()
|
||||||
GradleBuildRootDataSerializer.write(newRoot.dir ?: return, mergedData)
|
|
||||||
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