mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make UpdateSettingsProvider not experimental and per app EP
e.g. for Kotlin no need to use project, so, it is ok to have it per app
This commit is contained in:
@@ -22,7 +22,7 @@ import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.processOpenedProjects
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.newvfs.ManagingFS
|
||||
@@ -48,7 +48,7 @@ internal class SaveAndSyncHandlerImpl : BaseSaveAndSyncHandler(), Disposable {
|
||||
@Volatile
|
||||
private var refreshSessionId = -1L
|
||||
|
||||
private val saveQueue = ArrayDeque<SaveAndSyncHandler.SaveTask>()
|
||||
private val saveQueue = ArrayDeque<SaveTask>()
|
||||
|
||||
private val saveAlarm = pooledThreadSingleAlarm(delay = 300, parentDisposable = this) {
|
||||
val app = ApplicationManager.getApplication()
|
||||
@@ -147,13 +147,13 @@ internal class SaveAndSyncHandlerImpl : BaseSaveAndSyncHandler(), Disposable {
|
||||
})
|
||||
}
|
||||
|
||||
override fun scheduleSave(task: SaveAndSyncHandler.SaveTask, forceExecuteImmediately: Boolean) {
|
||||
override fun scheduleSave(task: SaveTask, forceExecuteImmediately: Boolean) {
|
||||
if (addToSaveQueue(task) || forceExecuteImmediately) {
|
||||
saveAlarm.cancelAndRequest(forceRun = forceExecuteImmediately)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addToSaveQueue(task: SaveAndSyncHandler.SaveTask): Boolean {
|
||||
private fun addToSaveQueue(task: SaveTask): Boolean {
|
||||
synchronized(saveQueue) {
|
||||
if (task.onlyProject == null) {
|
||||
saveQueue.removeAll(task::isMoreGenericThan)
|
||||
@@ -273,7 +273,7 @@ internal class SaveAndSyncHandlerImpl : BaseSaveAndSyncHandler(), Disposable {
|
||||
|
||||
override fun refreshOpenFiles() {
|
||||
val files = ArrayList<VirtualFile>()
|
||||
for (project in ProjectManager.getInstance().openProjects) {
|
||||
processOpenedProjects { project ->
|
||||
FileEditorManager.getInstance(project).selectedFiles.filterTo(files) { it is NewVirtualFile }
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ import com.intellij.openapi.diagnostic.runAndLogException
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectBundle
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.ProjectReloadState
|
||||
import com.intellij.openapi.project.processOpenedProjects
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.Ref
|
||||
@@ -55,15 +55,11 @@ internal class StoreReloadManagerImpl : StoreReloadManager, Disposable {
|
||||
}
|
||||
|
||||
val projectsToReload = THashSet<Project>()
|
||||
for (project in ProjectManager.getInstance().openProjects) {
|
||||
if (project.isDisposed) {
|
||||
continue
|
||||
}
|
||||
|
||||
processOpenedProjects { project ->
|
||||
val changedSchemes = CHANGED_SCHEMES_KEY.getAndClear(project as UserDataHolderEx)
|
||||
val changedStorages = CHANGED_FILES_KEY.getAndClear(project as UserDataHolderEx)
|
||||
if ((changedSchemes == null || changedSchemes.isEmpty) && (changedStorages == null || changedStorages.isEmpty)) {
|
||||
continue
|
||||
return@processOpenedProjects
|
||||
}
|
||||
|
||||
runBatchUpdate(project.messageBus) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 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.
|
||||
// Copyright 2000-2019 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:JvmName("ProjectUtil")
|
||||
package com.intellij.openapi.project
|
||||
|
||||
@@ -191,4 +191,14 @@ inline fun runWhenProjectOpened(project: Project? = null, crossinline handler: (
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
inline fun processOpenedProjects(processor: (Project) -> Unit) {
|
||||
for (project in ProjectManager.getInstance().openProjects) {
|
||||
if (!project.isInitialized || project.isDisposed) {
|
||||
continue
|
||||
}
|
||||
|
||||
processor(project)
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import com.intellij.openapi.components.stateStore
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.processOpenedProjects
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.annotations.CalledInAny
|
||||
@@ -157,10 +157,8 @@ suspend fun saveProjectsAndApp(forceSavingAllSettings: Boolean, onlyProject: Pro
|
||||
|
||||
@CalledInAny
|
||||
private suspend fun saveAllProjects(forceSavingAllSettings: Boolean) {
|
||||
for (project in ProjectManager.getInstance().openProjects) {
|
||||
if (!project.isDisposed) {
|
||||
saveSettings(project, forceSavingAllSettings)
|
||||
}
|
||||
processOpenedProjects { project ->
|
||||
saveSettings(project, forceSavingAllSettings)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-17
@@ -1,33 +1,22 @@
|
||||
// Copyright 2000-2018 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.
|
||||
// Copyright 2000-2019 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:JvmName("UpdateSettingsProviderHelper")
|
||||
package com.intellij.openapi.updateSettings.impl
|
||||
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.diagnostic.runAndLogException
|
||||
import com.intellij.openapi.extensions.ProjectExtensionPointName
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
|
||||
private val LOG = logger<UpdateOptions>()
|
||||
private val UPDATE_SETTINGS_PROVIDER_EP = ExtensionPointName<UpdateSettingsProvider>("com.intellij.updateSettingsProvider")
|
||||
|
||||
@ApiStatus.Experimental
|
||||
private val UPDATE_SETTINGS_PROVIDER_EP = ProjectExtensionPointName<UpdateSettingsProvider>("com.intellij.updateSettingsProvider")
|
||||
|
||||
@ApiStatus.Experimental
|
||||
interface UpdateSettingsProvider {
|
||||
fun getPluginRepositories(): List<String>
|
||||
}
|
||||
|
||||
internal fun addPluginRepositories(to: MutableList<String>) {
|
||||
for (project in ProjectManager.getInstance().openProjects) {
|
||||
if (!project.isInitialized || project.isDisposed) {
|
||||
continue
|
||||
}
|
||||
|
||||
for (provider in UPDATE_SETTINGS_PROVIDER_EP.getExtensions(project)) {
|
||||
LOG.runAndLogException {
|
||||
to.addAll(provider.getPluginRepositories())
|
||||
}
|
||||
for (provider in UPDATE_SETTINGS_PROVIDER_EP.extensionList) {
|
||||
LOG.runAndLogException {
|
||||
to.addAll(provider.getPluginRepositories())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,7 +313,7 @@
|
||||
<extensionPoint name="projectNameProvider" interface="com.intellij.openapi.project.ex.ProjectNameProvider"/>
|
||||
<extensionPoint name="streamProviderFactory" interface="com.intellij.configurationStore.StreamProviderFactory" area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint name="updateSettingsProvider" interface="com.intellij.openapi.updateSettings.impl.UpdateSettingsProvider" area="IDEA_PROJECT"/>
|
||||
<extensionPoint name="updateSettingsProvider" interface="com.intellij.openapi.updateSettings.impl.UpdateSettingsProvider"/>
|
||||
|
||||
<extensionPoint name="webHelpProvider" interface="com.intellij.openapi.help.WebHelpProvider"/>
|
||||
|
||||
|
||||
@@ -6,24 +6,32 @@ import com.intellij.configurationScript.readObject
|
||||
import com.intellij.openapi.components.BaseState
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.processOpenedProjects
|
||||
import com.intellij.openapi.updateSettings.impl.UpdateSettingsProvider
|
||||
import com.intellij.openapi.util.NotNullLazyKey
|
||||
import com.intellij.util.SmartList
|
||||
import com.intellij.util.concurrency.SynchronizedClearableLazy
|
||||
import org.yaml.snakeyaml.nodes.MappingNode
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode
|
||||
|
||||
private class MyUpdateSettingsProvider(project: Project) : UpdateSettingsProvider {
|
||||
private val data = SynchronizedClearableLazy<PluginsConfiguration?> {
|
||||
val node = project.service<ConfigurationFileManager>().getConfigurationNode()
|
||||
?: return@SynchronizedClearableLazy null
|
||||
private val dataKey = NotNullLazyKey.create<SynchronizedClearableLazy<PluginsConfiguration?>, Project>("MyUpdateSettingsProvider") { project ->
|
||||
val data = SynchronizedClearableLazy {
|
||||
val node = project.service<ConfigurationFileManager>().getConfigurationNode() ?: return@SynchronizedClearableLazy null
|
||||
readPluginsConfiguration(node)
|
||||
}
|
||||
project.service<ConfigurationFileManager>().registerClearableLazyValue(data)
|
||||
data
|
||||
}
|
||||
|
||||
init {
|
||||
project.service<ConfigurationFileManager>().registerClearableLazyValue(data)
|
||||
}
|
||||
|
||||
private class MyUpdateSettingsProvider : UpdateSettingsProvider {
|
||||
override fun getPluginRepositories(): List<String> {
|
||||
return data.value?.repositories ?: emptyList()
|
||||
val result = SmartList<String>()
|
||||
processOpenedProjects { project ->
|
||||
dataKey.getValue(project).value?.repositories?.let {
|
||||
result.addAll(it)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +46,7 @@ internal fun readPluginsConfiguration(rootNode: MappingNode): PluginsConfigurati
|
||||
val keyNode = tuple.keyNode
|
||||
if (keyNode is ScalarNode && keyNode.value == Keys.plugins) {
|
||||
val valueNode = tuple.valueNode as? MappingNode ?: continue
|
||||
return readObject(PluginsConfiguration(),
|
||||
valueNode) as PluginsConfiguration
|
||||
return readObject(PluginsConfiguration(), valueNode) as PluginsConfiguration
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user