[plugins] IJPL-173491 auto-update: account content modules in dependency resolution

(cherry picked from commit 043f98ee9c0c4b294caa97fba7e393be0d9575a0)

# Conflicts:
#	community/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginAutoUpdateService.kt

GitOrigin-RevId: f38fa719283ec99e19ea2901a9ccea6dfb27c4b6
This commit is contained in:
Vadim Salavatov
2025-01-28 14:36:05 +01:00
committed by intellij-monorepo-bot
parent 7f0816c910
commit 45e2bc6af6
2 changed files with 11 additions and 6 deletions

View File

@@ -130,7 +130,10 @@ object PluginAutoUpdater {
val updatesToApply = mutableSetOf<PluginId>()
val rejectedUpdates = mutableMapOf<PluginId, String>()
// checks mostly duplicate what is written in com.intellij.ide.plugins.PluginInstaller.installFromDisk. FIXME, I guess
val enabledModules = currentDescriptors.getIdMap().flatMap { listOf(it.key) + it.value.pluginAliases }.toSet()
val enabledPluginsAndModulesIds: Set<String> = currentDescriptors.getIdMap().flatMap { entry ->
val desc = entry.value
listOf(desc.pluginId.idString) + desc.pluginAliases.map { it.idString } + desc.content.modules.map { it.name }
}.toSet()
for ((id, updateDesc) in updates) {
val existingDesc = currentDescriptors.getIdMap()[id] ?: currentDescriptors.getIncompleteIdMap()[id]
if (existingDesc == null) {
@@ -164,7 +167,7 @@ object PluginAutoUpdater {
// bit more formalized and a bit more flexible to be reused here (TODO).
val unmetDependencies = findUnsatisfiedDependencies(
updateDesc.pluginDependencies,
enabledModules // + currentDescriptors.getIncompleteIdMap().map { it.key } // TODO revise if incomplete is fine
enabledPluginsAndModulesIds
)
if (unmetDependencies.isNotEmpty()) {
rejectedUpdates[id] = "plugin $id of version ${updateDesc.version} has unsatisfied dependencies " +

View File

@@ -104,7 +104,9 @@ internal class PluginAutoUpdateService(private val cs: CoroutineScope) {
private suspend fun downloadUpdates(downloaders: List<PluginDownloader>): List<PluginDownloader> {
val downloadedList = mutableListOf<PluginDownloader>()
val enabledModules = PluginManagerCore.getPluginSet().moduleGraph.nodes.flatMap { listOf(it.pluginId) + it.pluginAliases }.toSet()
val enabledPluginsAndModules: Set<String> = PluginManagerCore.getPluginSet().getEnabledModules().flatMap {
listOf(it.moduleName ?: it.pluginId.idString) + it.pluginAliases.map { id -> id.idString }
}.toSet()
val downloaders = downloaders.filter { downloader ->
val existingUpdateState = updatesState[downloader.id]
if (PluginManagerCore.getPlugin(downloader.id) == null) {
@@ -117,7 +119,7 @@ internal class PluginAutoUpdateService(private val cs: CoroutineScope) {
}
val unsatisfiedDependencies = findUnsatisfiedDependencies(
updateDescriptor = downloader.toPluginNode().dependencies,
enabledModules = enabledModules,
enabledPluginsAndModulesIds = enabledPluginsAndModules,
)
if (unsatisfiedDependencies.isNotEmpty()) {
LOG.debug {
@@ -232,13 +234,13 @@ private val LOG
@ApiStatus.Internal
fun findUnsatisfiedDependencies(
updateDescriptor: Collection<IdeaPluginDependency>,
enabledModules: Collection<PluginId>,
enabledPluginsAndModulesIds: Collection<String>,
): List<IdeaPluginDependency> {
return updateDescriptor.filter { dep ->
if (dep.isOptional) {
return@filter false
}
val dependencySatisfied = enabledModules.any { it == dep.pluginId }
val dependencySatisfied = enabledPluginsAndModulesIds.any { it == dep.pluginId.idString }
!dependencySatisfied
}
}