diff --git a/java/compiler/impl/src/com/intellij/compiler/ExternalCompilerConfigurationStorage.kt b/java/compiler/impl/src/com/intellij/compiler/ExternalCompilerConfigurationStorage.kt index 11f7d50b6bcc..2cfa1f25361c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ExternalCompilerConfigurationStorage.kt +++ b/java/compiler/impl/src/com/intellij/compiler/ExternalCompilerConfigurationStorage.kt @@ -1,4 +1,6 @@ // Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +@file:Suppress("ReplacePutWithAssignment", "ReplaceGetOrSet") + package com.intellij.compiler import com.intellij.openapi.components.PersistentStateComponent @@ -22,8 +24,9 @@ internal class ExternalCompilerConfigurationStorage(private val project: Project companion object { @JvmStatic - fun getInstance(project: Project): ExternalCompilerConfigurationStorage = - project.getService(ExternalCompilerConfigurationStorage::class.java) + fun getInstance(project: Project): ExternalCompilerConfigurationStorage { + return project.getService(ExternalCompilerConfigurationStorage::class.java) + } } override fun getState(): Element { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfiguration.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfiguration.java index b9c7eddf94af..8e5fed0c29f6 100755 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfiguration.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfiguration.java @@ -13,13 +13,14 @@ import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions; import java.util.HashMap; import java.util.Map; +@SuppressWarnings("LightServiceMigrationCode") @State(name = "JavacSettings", storages = @Storage("compiler.xml")) -public class JavacConfiguration implements PersistentStateComponent { +public final class JavacConfiguration implements PersistentStateComponent { private final JpsJavaCompilerOptions mySettings = new JpsJavaCompilerOptions(); - private final Project myProject; + private final Project project; - public JavacConfiguration(Project project) { - myProject = project; + public JavacConfiguration(@NotNull Project project) { + this.project = project; } @Override @@ -27,7 +28,7 @@ public class JavacConfiguration implements PersistentStateComponent(state.ADDITIONAL_OPTIONS_OVERRIDE); // copyBean copies by reference, we need a map clone here - final PathMacroManager macros = PathMacroManager.getInstance(myProject); + final PathMacroManager macros = PathMacroManager.getInstance(project); state.ADDITIONAL_OPTIONS_STRING = macros.collapsePathsRecursively(state.ADDITIONAL_OPTIONS_STRING); for (Map.Entry entry : state.ADDITIONAL_OPTIONS_OVERRIDE.entrySet()) { entry.setValue(macros.collapsePathsRecursively(entry.getValue())); diff --git a/platform/configuration-store-impl/src/ComponentInfo.kt b/platform/configuration-store-impl/src/ComponentInfo.kt index 4ed9638b2363..77f3813c148c 100644 --- a/platform/configuration-store-impl/src/ComponentInfo.kt +++ b/platform/configuration-store-impl/src/ComponentInfo.kt @@ -133,10 +133,11 @@ internal fun getEffectiveRoamingType(roamingType: RoamingType, collapsedPath: St } } -internal fun isSpecialOrNonRoamableStorage(collapsedPath: String): Boolean = - collapsedPath == StoragePathMacros.WORKSPACE_FILE || - collapsedPath == StoragePathMacros.NON_ROAMABLE_FILE || - isSpecialStorage(collapsedPath) +internal fun isSpecialOrNonRoamableStorage(collapsedPath: String): Boolean { + return collapsedPath == StoragePathMacros.WORKSPACE_FILE || + collapsedPath == StoragePathMacros.NON_ROAMABLE_FILE || + isSpecialStorage(collapsedPath) +} internal fun isSpecialStorage(collapsedPath: String): Boolean { return collapsedPath == StoragePathMacros.CACHE_FILE || collapsedPath == StoragePathMacros.PRODUCT_WORKSPACE_FILE diff --git a/platform/configuration-store-impl/src/ProjectStoreBridge.kt b/platform/configuration-store-impl/src/ProjectStoreBridge.kt index 9330685460d9..016ef90329e9 100644 --- a/platform/configuration-store-impl/src/ProjectStoreBridge.kt +++ b/platform/configuration-store-impl/src/ProjectStoreBridge.kt @@ -21,7 +21,6 @@ import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.util.Pair import com.intellij.openapi.util.SystemInfoRt -import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.VirtualFileManager @@ -86,7 +85,7 @@ class ProjectWithModuleStoreImpl(project: Project) : ProjectStoreImpl(project), saveSessions: MutableList, saveResult: SaveResult, forceSavingAllSettings: Boolean, - projectSessionManager: ProjectSaveSessionProducerManager + projectSessionManager: ProjectSaveSessionProducerManager, ) { projectSessionManager as ProjectWithModulesSaveSessionProducerManager val workspaceModel = project.serviceAsync() @@ -376,16 +375,14 @@ private class ProjectWithModulesSaveSessionProducerManager(project: Project, isU fun commitComponents(moduleStore: ComponentStoreImpl, moduleSaveSessionManager: SaveSessionProducerManager) { fun commitToStorage(storageSpec: Storage, componentToElement: Map) { val storage = moduleStore.storageManager.getStateStorage(storageSpec) - val producer = moduleSaveSessionManager.getProducer(storage) - if (producer != null) { - for ((componentName, componentTag) in componentToElement) { - producer.setState( - component = null, - componentName = componentName, - pluginId = PluginManagerCore.CORE_ID, - state = if (componentTag === NULL_ELEMENT) null else componentTag, - ) - } + val producer = moduleSaveSessionManager.getProducer(storage) ?: return + for ((componentName, componentTag) in componentToElement) { + producer.setState( + component = null, + componentName = componentName, + pluginId = PluginManagerCore.CORE_ID, + state = if (componentTag === NULL_ELEMENT) null else componentTag, + ) } } @@ -415,40 +412,40 @@ internal class StorageJpsConfigurationReader(private val project: Project, priva if (ProjectUtil.isRemotePath(FileUtilRt.toSystemDependentName(filePath)) && !TrustedProjects.isProjectTrusted(project)) { throw IOException(ConfigurationStoreBundle.message("error.message.details.configuration.files.from.remote.locations.in.safe.mode")) } - if (componentName.isEmpty()) { - //this is currently used for loading Eclipse project configuration from the.classpath file - val file = VirtualFileManager.getInstance().findFileByUrl(fileUrl) - val component = file?.inputStream?.use { JDOMUtil.load(it) } - return@addMeasuredTime component - } - if (isExternalMiscFile(filePath)) { - // this is a workaround to make a working scenario when the whole .idea is moved to external configuration dir - // see com.intellij.workspaceModel.ide.impl.jps.serialization.JpsProjectEntitiesLoader.isExternalStorageEnabled - val component = getCachingReader().loadComponent(fileUrl, componentName, customModuleFilePath) - return@addMeasuredTime component - } - if (filePath.endsWith(".iml") || isExternalModuleFile(filePath)) { - //todo fetch data from ModuleStore (IJPL-15992) - val component = getCachingReader().loadComponent(fileUrl, componentName, customModuleFilePath) - return@addMeasuredTime component - } - else { - val storage = getProjectStateStorage(filePath, project.stateStore, project) - val stateMap = storage.getStorageData() - val component = if (storage is DirectoryBasedStorage) { - val elementContent = stateMap.getElement(PathUtilRt.getFileName(filePath)) - if (elementContent == null) { - null + + when { + componentName.isEmpty() -> { + // this is currently used for loading Eclipse project configuration from the.classpath file + val file = VirtualFileManager.getInstance().findFileByUrl(fileUrl) + file?.inputStream?.use { JDOMUtil.load(it) } + } + isExternalMiscFile(filePath) -> { + // this is a workaround to make a working scenario when the whole .idea is moved to external configuration dir + // see com.intellij.workspaceModel.ide.impl.jps.serialization.JpsProjectEntitiesLoader.isExternalStorageEnabled + getCachingReader().loadComponent(fileUrl, componentName, customModuleFilePath) + } + filePath.endsWith(".iml") || isExternalModuleFile(filePath) -> { + //todo fetch data from ModuleStore (IJPL-15992) + getCachingReader().loadComponent(fileUrl, componentName, customModuleFilePath) + } + else -> { + val storage = getProjectStateStorage(filePath, project.stateStore, project) + val stateMap = storage.getStorageData() + val component = if (storage is DirectoryBasedStorage) { + val elementContent = stateMap.getElement(PathUtilRt.getFileName(filePath)) + if (elementContent == null) { + null + } + else { + Element(ComponentStorageUtil.COMPONENT).setAttribute(ComponentStorageUtil.NAME, componentName).addContent(elementContent) + } } else { - Element(ComponentStorageUtil.COMPONENT).setAttribute(ComponentStorageUtil.NAME, componentName).addContent(elementContent) + stateMap.getElement(componentName) } - } - else { - stateMap.getElement(componentName) - } - return@addMeasuredTime component + component + } } } @@ -493,19 +490,18 @@ internal class StorageJpsConfigurationReader(private val project: Project, priva } internal fun getProjectStateStorage(filePath: String, store: IProjectStore, project: Project): StateStorageBase { - val storageSpec = getStorageSpec(filePath, project) @Suppress("UNCHECKED_CAST") - return store.storageManager.getStateStorage(storageSpec) as StateStorageBase + return store.storageManager.getStateStorage(getStorageSpec(filePath, project)) as StateStorageBase } private fun getStorageSpec(filePath: String, project: Project): Storage { val collapsedPath: String val splitterClass: Class - val fileName = PathUtil.getFileName(filePath) - val parentPath = PathUtil.getParentPath(filePath) - val parentFileName = PathUtil.getFileName(parentPath) - if (filePath.endsWith(".ipr") || fileName == "misc.xml" && parentFileName == Project.DIRECTORY_STORE_FOLDER) { - collapsedPath = "\$PROJECT_FILE$" + val fileName = PathUtilRt.getFileName(filePath) + val parentPath = PathUtilRt.getParentPath(filePath) + val parentFileName = PathUtilRt.getFileName(parentPath) + if (filePath.endsWith(".ipr") || (fileName == "misc.xml" && parentFileName == Project.DIRECTORY_STORE_FOLDER)) { + collapsedPath = $$"$PROJECT_FILE$" splitterClass = StateSplitterEx::class.java } else { @@ -514,13 +510,13 @@ private fun getStorageSpec(filePath: String, project: Project): Storage { splitterClass = StateSplitterEx::class.java } else { - val grandParentPath = PathUtil.getParentPath(parentPath) + val grandParentPath = PathUtilRt.getParentPath(parentPath) collapsedPath = parentFileName splitterClass = FakeDirectoryBasedStateSplitter::class.java if (PathUtil.getFileName(grandParentPath) != Project.DIRECTORY_STORE_FOLDER) { if (parentFileName == "project") { if (fileName == "libraries.xml" || fileName == "artifacts.xml") { - val inProjectStorage = FileStorageAnnotation(FileUtil.getNameWithoutExtension(fileName), false, splitterClass) + val inProjectStorage = FileStorageAnnotation(FileUtilRt.getNameWithoutExtension(fileName), false, splitterClass) val componentName = if (fileName == "libraries.xml") "libraryTable" else "ArtifactManager" StreamProviderFactory.EP_NAME.computeSafeIfAny(project) { it.getOrCreateStorageSpec(fileName, StateAnnotation(componentName, inProjectStorage)) diff --git a/platform/configuration-store-impl/src/SaveSessionProducerManager.kt b/platform/configuration-store-impl/src/SaveSessionProducerManager.kt index f452e9f1bec9..ccaa4d17373c 100644 --- a/platform/configuration-store-impl/src/SaveSessionProducerManager.kt +++ b/platform/configuration-store-impl/src/SaveSessionProducerManager.kt @@ -1,4 +1,6 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +@file:Suppress("ReplaceGetOrSet") + package com.intellij.configurationStore import com.intellij.openapi.application.ApplicationManager @@ -18,7 +20,7 @@ internal open class SaveSessionProducerManager(private val isUseVfsForWrite: Boo private val producers = Collections.synchronizedMap(LinkedHashMap()) fun getProducer(storage: StateStorage): SaveSessionProducer? { - var producer = producers[storage] + var producer = producers.get(storage) if (producer == null) { producer = storage.createSaveSessionProducer() ?: return null val prev = producers.put(storage, producer) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt index 375cce804a0c..42d81d7af4c6 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt @@ -23,8 +23,9 @@ internal class ExternalModuleStorage(private val module: Module, storageManager: override fun loadLocalData(): Element? = manager.readModuleData(module.name) - override fun createSaveSession(states: StateMap): SaveSessionProducer = - ExternalStorageSaveSessionProducer(states, storage = this, manager.moduleStorage, module.name) + override fun createSaveSession(states: StateMap): SaveSessionProducer { + return ExternalStorageSaveSessionProducer(states, storage = this, manager.moduleStorage, module.name) + } } internal open class ExternalProjectStorage( @@ -40,8 +41,9 @@ internal open class ExternalProjectStorage( override fun loadLocalData(): Element? = manager.fileStorage.read(fileSpec) - override fun createSaveSession(states: StateMap): SaveSessionProducer = - ExternalStorageSaveSessionProducer(states, storage = this, manager.fileStorage, name = fileSpec) + override fun createSaveSession(states: StateMap): SaveSessionProducer { + return ExternalStorageSaveSessionProducer(states, storage = this, manager.fileStorage, name = fileSpec) + } override fun toString(): String = "ExternalProjectStorage(fileSpec=${fileSpec})" } @@ -64,19 +66,22 @@ internal class ExternalProjectFilteringStorage( override fun hasData(element: Element): Boolean = element.children.any { elementOutputFilter.accept(it, 1) } } - override fun loadLocalData(): Element? = - JDOMUtil.merge( + override fun loadLocalData(): Element? { + return JDOMUtil.merge( super.loadLocalData(), internalStorage.getSerializedState(internalStorage.loadData(), component = null, componentName, archive = true) ) + } - override fun createSaveSession(states: StateMap): SaveSessionProducer = - ExternalStorageSaveSessionProducer(states, storage = this, manager.fileStorage, name = fileSpec, filter) + override fun createSaveSession(states: StateMap): SaveSessionProducer { + return ExternalStorageSaveSessionProducer(states, storage = this, manager.fileStorage, name = fileSpec, filter) + } } -private fun findExternalSystemStreamProviderFactory(project: Project): ExternalSystemStreamProviderFactory = - StreamProviderFactory.EP_NAME.getExtensions(project) +private fun findExternalSystemStreamProviderFactory(project: Project): ExternalSystemStreamProviderFactory { + return StreamProviderFactory.EP_NAME.getExtensions(project) .first { it is ExternalSystemStreamProviderFactory } as ExternalSystemStreamProviderFactory +} private class ExternalStorageSaveSessionProducer( states: StateMap, diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt index 94512d6bc101..5bae049f0e3a 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt @@ -15,7 +15,6 @@ import com.intellij.openapi.roots.ProjectModelElement import com.intellij.openapi.startup.StartupManager import com.intellij.util.Function import org.jdom.Element -import java.util.* import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.locks.ReentrantReadWriteLock import kotlin.concurrent.read @@ -32,7 +31,7 @@ internal class ExternalSystemStreamProviderFactory(private val project: Project) private val storages = HashMap() init { - project.messageBus.connect().subscribe(ModuleListener.TOPIC, object : ModuleListener { + project.messageBus.simpleConnect().subscribe(ModuleListener.TOPIC, object : ModuleListener { override fun moduleRemoved(project: Project, module: Module) { moduleStorage.remove(module.name) } @@ -45,7 +44,13 @@ internal class ExternalSystemStreamProviderFactory(private val project: Project) }) } - override fun customizeStorageSpecs(component: PersistentStateComponent<*>, storageManager: StateStorageManager, stateSpec: State, storages: List, operation: StateStorageOperation): List? { + override fun customizeStorageSpecs( + component: PersistentStateComponent<*>, + storageManager: StateStorageManager, + stateSpec: State, + storages: List, + operation: StateStorageOperation, + ): List? { val componentManager = storageManager.componentManager ?: return null val project = componentManager as? Project ?: (componentManager as Module).project diff --git a/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/CachingJpsFileContentReader.kt b/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/CachingJpsFileContentReader.kt index 78ac3f4965ae..74e1f0947af2 100644 --- a/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/CachingJpsFileContentReader.kt +++ b/platform/platform-impl/src/com/intellij/workspaceModel/ide/impl/jps/serialization/CachingJpsFileContentReader.kt @@ -1,4 +1,6 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +@file:Suppress("ReplaceGetOrSet") + package com.intellij.workspaceModel.ide.impl.jps.serialization import com.intellij.openapi.components.ExpandMacroToPathMap @@ -7,7 +9,6 @@ import com.intellij.openapi.components.impl.ModulePathMacroManager import com.intellij.openapi.components.impl.ProjectPathMacroManager import com.intellij.openapi.components.impl.stores.ComponentStorageUtil import com.intellij.openapi.util.JDOMUtil -import com.intellij.openapi.util.text.Strings import com.intellij.platform.workspace.jps.JpsProjectConfigLocation import com.intellij.platform.workspace.jps.bridge.impl.serialization.DefaultImlNormalizer import com.intellij.platform.workspace.jps.serialization.impl.JpsFileContentReader @@ -32,11 +33,12 @@ class CachingJpsFileContentReader(private val configLocation: JpsProjectConfigLo val content = fileContentCache.computeIfAbsent(fileUrl + customModuleFilePath) { loadComponents(fileUrl, customModuleFilePath) } - return content[componentName] + return content.get(componentName) } - override fun getExpandMacroMap(fileUrl: String): ExpandMacroToPathMap = - getMacroManager(fileUrl = fileUrl, customModuleFilePath = null).expandMacroMap + override fun getExpandMacroMap(fileUrl: String): ExpandMacroToPathMap { + return getMacroManager(fileUrl = fileUrl, customModuleFilePath = null).expandMacroMap + } private fun loadComponents(fileUrl: String, customModuleFilePath: String?): Map { val macroManager = getMacroManager(fileUrl = fileUrl, customModuleFilePath = customModuleFilePath) @@ -46,17 +48,17 @@ class CachingJpsFileContentReader(private val configLocation: JpsProjectConfigLo private fun getMacroManager(fileUrl: String, customModuleFilePath: String?): PathMacroManager { val path = JpsPathUtil.urlToPath(fileUrl) - return if (fileUrl.endsWith(".iml") || isExternalModuleFile(path)) { - ModulePathMacroManager.createInstance(configLocation::projectFilePath) { customModuleFilePath ?: path } + if (fileUrl.endsWith(".iml") || isExternalModuleFile(path)) { + return ModulePathMacroManager.createInstance(configLocation::projectFilePath) { customModuleFilePath ?: path } } else { - projectPathMacroManager + return projectPathMacroManager } } private fun loadStorageFile(xmlFile: Path, pathMacroManager: PathMacroManager): Map { val rootElement = JDOMUtil.load(xmlFile) - if (Strings.endsWith(xmlFile.toString(), ".iml")) { + if (xmlFile.toString().endsWith(".iml")) { DefaultImlNormalizer.normalize(rootElement) } return ComponentStorageUtil.loadComponents(rootElement, pathMacroManager) diff --git a/platform/projectModel-impl/src/com/intellij/configurationStore/StreamProviderFactory.kt b/platform/projectModel-impl/src/com/intellij/configurationStore/StreamProviderFactory.kt index ad6c6dbd228b..8c27904c85b0 100644 --- a/platform/projectModel-impl/src/com/intellij/configurationStore/StreamProviderFactory.kt +++ b/platform/projectModel-impl/src/com/intellij/configurationStore/StreamProviderFactory.kt @@ -9,7 +9,7 @@ import org.jetbrains.annotations.ApiStatus * Project level extension point. * * Allows setting custom storage class using providing custom storage specs. - * Or set custom stream provider for default storage (XmlElementStorage). + * Or set a custom stream provider for default storage (XmlElementStorage). */ @ApiStatus.Internal interface StreamProviderFactory { diff --git a/platform/workspace/jps/src/com/intellij/platform/workspace/jps/serialization/impl/JpsProjectEntitiesLoader.kt b/platform/workspace/jps/src/com/intellij/platform/workspace/jps/serialization/impl/JpsProjectEntitiesLoader.kt index b648d8b145c8..3f084c942897 100644 --- a/platform/workspace/jps/src/com/intellij/platform/workspace/jps/serialization/impl/JpsProjectEntitiesLoader.kt +++ b/platform/workspace/jps/src/com/intellij/platform/workspace/jps/serialization/impl/JpsProjectEntitiesLoader.kt @@ -59,23 +59,27 @@ object JpsProjectEntitiesLoader { orphanage: MutableEntityStorage, errorReporter: ErrorReporter, context: SerializationContext) { - val reader = context.fileContentReader - val serializer = ModuleListSerializerImpl.createModuleEntitiesSerializer(moduleFile.toVirtualFileUrl(context.virtualFileUrlManager), - null, source, context) - val newEntities = serializer.loadEntities(reader, errorReporter, context.virtualFileUrlManager) + val serializer = ModuleListSerializerImpl.createModuleEntitiesSerializer( + fileUrl = moduleFile.toVirtualFileUrl(context.virtualFileUrlManager), + moduleGroup = null, + source = source, + context = context, + ) + val newEntities = serializer.loadEntities(context.fileContentReader, errorReporter, context.virtualFileUrlManager) serializer.checkAndAddToBuilder(builder, orphanage, newEntities.data) newEntities.exception?.let { throw it } } - fun createProjectSerializers(configLocation: JpsProjectConfigLocation, - externalStoragePath: Path, - context: SerializationContext): JpsProjectSerializers { + fun createProjectSerializers( + configLocation: JpsProjectConfigLocation, + externalStoragePath: Path, + context: SerializationContext, + ): JpsProjectSerializers { val externalStorageRoot = externalStoragePath.toVirtualFileUrl(context.virtualFileUrlManager) val externalStorageMapping = JpsExternalStorageMappingImpl(externalStorageRoot, configLocation) return when (configLocation) { is JpsProjectConfigLocation.FileBased -> createIprProjectSerializers(configLocation, externalStorageMapping, context) is JpsProjectConfigLocation.DirectoryBased -> createDirectoryProjectSerializers(configLocation, externalStorageMapping, context) - else -> error("Unexpected state") } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt index c3059f45f5a1..607091c8e316 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/workspaceModel/WorkspaceProjectImporter.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.application.WriteIntentReadAction import com.intellij.openapi.application.edtWriteAction import com.intellij.openapi.components.Service import com.intellij.openapi.components.service +import com.intellij.openapi.components.serviceAsync import com.intellij.openapi.diagnostic.ControlFlowException import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.extensions.ExtensionPointName @@ -57,7 +58,7 @@ import java.nio.file.Path import java.util.function.Function import kotlin.coroutines.cancellation.CancellationException -internal val AFTER_IMPORT_CONFIGURATOR_EP: ExtensionPointName = ExtensionPointName.create( +internal val AFTER_IMPORT_CONFIGURATOR_EP: ExtensionPointName = ExtensionPointName( "org.jetbrains.idea.maven.importing.afterImportConfigurator") @TestOnly @@ -83,13 +84,15 @@ internal open class WorkspaceProjectImporter( val migratedToExternalStorage = migrateToExternalStorageIfNeeded() - val storageBeforeImport = WorkspaceModel.getInstance(myProject).currentSnapshot + val storageBeforeImport = myProject.serviceAsync().currentSnapshot val projectChangesInfo = tracer.spanBuilder("collectProjectChanges").use { collectProjectChanges(storageBeforeImport, projectsToImport, migratedToExternalStorage) } - if (!projectChangesInfo.hasChanges) return emptyList() + if (!projectChangesInfo.hasChanges) { + return emptyList() + } val postTasks = ArrayList() val stats = WorkspaceImportStats.start(myProject) @@ -144,24 +147,23 @@ internal open class WorkspaceProjectImporter( } private fun migrateToExternalStorageIfNeeded(): Boolean { - var migratedToExternalStorage = false val externalStorageManager = ExternalStorageConfigurationManager.getInstance(myProject) - if (!externalStorageManager.isEnabled) { - ExternalProjectsManagerImpl.getInstance(myProject).setStoreExternally(true) - migratedToExternalStorage = true - - if (!externalStorageManager.isEnabled) { - MavenLog.LOG.error( - "Can't migrate the project to external project files storage: ExternalStorageConfigurationManager.isEnabled=false") - } - else if (!myProject.isExternalStorageEnabled) { - MavenLog.LOG.warn("Can't migrate the project to external project files storage: Project.isExternalStorageEnabled=false") - } - else { - MavenLog.LOG.info("Project has been migrated to external project files storage") - } + if (externalStorageManager.isEnabled) { + return false } - return migratedToExternalStorage + + ExternalProjectsManagerImpl.getInstance(myProject).setStoreExternally(true) + + if (!externalStorageManager.isEnabled) { + MavenLog.LOG.error("Can't migrate the project to external project files storage: ExternalStorageConfigurationManager.isEnabled=false") + } + else if (!myProject.isExternalStorageEnabled) { + MavenLog.LOG.warn("Can't migrate the project to external project files storage: Project.isExternalStorageEnabled=false") + } + else { + MavenLog.LOG.info("Project has been migrated to external project files storage") + } + return true } private data class ProjectChangesInfo(val hasChanges: Boolean, val allProjectsToChanges: Map) {