[plugins] IJPL-249171 Save plugin update sources of dependencies on installation from disk IJ-CR-216454

(cherry picked from commit aaf05a1333cf5a6c084f3ab07109e2b4705fa997)

GitOrigin-RevId: 2fa3b624da534f544a428f3610ec0d0225a3c305
This commit is contained in:
Elena Shaverdova
2026-08-04 22:25:59 +00:00
committed by intellij-monorepo-bot
parent 09e65a1c2a
commit a0e36e959e
4 changed files with 38 additions and 12 deletions
@@ -11,11 +11,13 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.updateSettings.impl.PluginUpdateSourceId;
import com.intellij.openapi.vfs.StandardFileSystems;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.concurrency.annotations.RequiresEdt;
@@ -28,6 +30,7 @@ import java.nio.file.Path;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@ApiStatus.Internal
@@ -79,6 +82,8 @@ public class InstallFromDiskAction extends DumbAwareAction {
if (myTableModel != null) {
installPluginFromDisk(file, project, myTableModel, myPluginEnabler, myParentComponent, callbackData -> {
onPluginInstalledFromDisk(callbackData, project);
}, (pluginId, updateSourceId) -> {
onPluginWithUpdateSourceInstalledFromDisk(pluginId, updateSourceId);
});
return;
}
@@ -101,6 +106,8 @@ public class InstallFromDiskAction extends DumbAwareAction {
try {
installPluginFromDisk(chosenFile.toNioPath(), project, tableModel, myPluginEnabler, myParentComponent, callbackData -> {
onPluginInstalledFromDisk(callbackData, project);
}, (pluginId, updateSourceId) -> {
onPluginWithUpdateSourceInstalledFromDisk(pluginId, updateSourceId);
});
}
finally {
@@ -113,8 +120,9 @@ public class InstallFromDiskAction extends DumbAwareAction {
@NotNull InstalledPluginsTableModel tableModel,
@NotNull PluginEnabler pluginEnabler,
@Nullable JComponent parentComponent,
@NotNull Consumer<? super PluginInstallCallbackData> callback) {
doInstall(fileToSelect, project, tableModel, pluginEnabler, parentComponent, callback);
@NotNull Consumer<? super PluginInstallCallbackData> callback,
@NotNull BiConsumer<PluginId, PluginUpdateSourceId> pluginUpdateSourceCallback) {
doInstall(fileToSelect, project, tableModel, pluginEnabler, parentComponent, callback, pluginUpdateSourceCallback);
}
private static void doInstall(@Nullable VirtualFile fileToSelect,
@@ -122,7 +130,8 @@ public class InstallFromDiskAction extends DumbAwareAction {
@NotNull InstalledPluginsTableModel tableModel,
@NotNull PluginEnabler pluginEnabler,
@Nullable JComponent parentComponent,
@NotNull Consumer<? super PluginInstallCallbackData> callback) {
@NotNull Consumer<? super PluginInstallCallbackData> callback,
@NotNull BiConsumer<PluginId, PluginUpdateSourceId> pluginUpdateSourceCallback) {
if (!PluginManagementPolicy.getInstance().isInstallFromDiskAllowed()) {
var message = IdeBundle.message("action.InstallFromDiskAction.not.allowed.description");
Messages.showErrorDialog(project, message, IdeBundle.message("action.InstallFromDiskAction.text"));
@@ -131,7 +140,8 @@ public class InstallFromDiskAction extends DumbAwareAction {
var chosenFile = chooseFile(fileToSelect, project, parentComponent);
if (chosenFile != null) {
installPluginFromDisk(chosenFile.toNioPath(), project, tableModel, pluginEnabler, parentComponent, callback);
installPluginFromDisk(chosenFile.toNioPath(), project, tableModel, pluginEnabler, parentComponent,
callback, pluginUpdateSourceCallback);
}
}
@@ -142,12 +152,13 @@ public class InstallFromDiskAction extends DumbAwareAction {
@RequiresEdt
private static void installPluginFromDisk(Path file,
@Nullable Project project,
@NotNull InstalledPluginsTableModel tableModel,
@NotNull PluginEnabler pluginEnabler,
@Nullable JComponent parentComponent,
@NotNull Consumer<? super PluginInstallCallbackData> callback) {
PluginInstaller.installFromDisk(tableModel, pluginEnabler, file, project, parentComponent, callback);
@Nullable Project project,
@NotNull InstalledPluginsTableModel tableModel,
@NotNull PluginEnabler pluginEnabler,
@Nullable JComponent parentComponent,
@NotNull Consumer<? super PluginInstallCallbackData> callback,
@NotNull BiConsumer<PluginId, PluginUpdateSourceId> pluginUpdateSourceCallback) {
PluginInstaller.installFromDisk(tableModel, pluginEnabler, file, project, parentComponent, callback, pluginUpdateSourceCallback);
}
@RequiresEdt
@@ -155,6 +166,9 @@ public class InstallFromDiskAction extends DumbAwareAction {
PluginInstaller.installPluginFromCallbackData(callbackData);
}
protected void onPluginWithUpdateSourceInstalledFromDisk(@NotNull PluginId pluginId, @NotNull PluginUpdateSourceId updateSourceId) {
}
@RequiresEdt
private static @Nullable VirtualFile chooseFile(@Nullable VirtualFile fileToSelect,
@Nullable Project project,
@@ -27,6 +27,7 @@ import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ex.MessagesEx
import com.intellij.openapi.updateSettings.impl.PluginUpdateSourceId
import com.intellij.openapi.util.Pair
import com.intellij.openapi.util.ThrowableComputable
import com.intellij.openapi.util.io.NioFiles
@@ -47,6 +48,7 @@ import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.function.BiConsumer
import java.util.function.Consumer
import javax.swing.JComponent
@@ -274,6 +276,7 @@ object PluginInstaller {
project: Project?,
parent: JComponent?,
callback: Consumer<in PluginInstallCallbackData>,
pluginUpdateSourceCallback: BiConsumer<PluginId, PluginUpdateSourceId>,
) {
try {
val pluginDescriptor = ProgressManager.getInstance().runProcessWithProgressSynchronously(
@@ -420,6 +423,9 @@ object PluginInstaller {
callback.accept(callbackData)
}
}
for ((pluginId, pluginUpdateSourceId) in operation.dependentPluginUpdateSourceIds) {
pluginUpdateSourceCallback.accept(pluginId, pluginUpdateSourceId)
}
if (file.toString().endsWith(".zip") && keepArchive()) {
val tempFile = MarketplacePluginDownloadService.getPluginTempFile()
@@ -52,6 +52,8 @@ import com.intellij.openapi.ui.popup.JBPopup
import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.updateSettings.impl.PluginAutoUpdateListener
import com.intellij.openapi.updateSettings.impl.PluginUpdateSourceId
import com.intellij.openapi.updateSettings.impl.PluginUpdateSourceService
import com.intellij.openapi.updateSettings.impl.UpdateOptions
import com.intellij.openapi.updateSettings.impl.UpdateSettings
import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.FUSEventSource
@@ -651,6 +653,10 @@ class PluginManagerConfigurablePanel @RequiresEdt constructor(searchQuery: Strin
}
this@PluginManagerConfigurablePanel.onPluginInstalledFromDisk(callbackData)
}
override fun onPluginWithUpdateSourceInstalledFromDisk(pluginId: PluginId, updateSourceId: PluginUpdateSourceId) {
PluginUpdateSourceService.getInstance().setPluginUpdateSourceId(pluginId, updateSourceId)
}
}
private inner class ResetConfigurableAction : DumbAwareAction(IdeBundle.message("plugin.manager.refresh")) {
@@ -55,9 +55,9 @@ internal class BackendPluginInstallerApi : PluginInstallerApi {
return channelFlow {
withContext(Dispatchers.EDT) {
val project = projectId?.findProjectOrNull()
InstallFromDiskAction.installPluginFromDisk(null, project, InstalledPluginsTableModel(project), PluginEnabler.HEADLESS, null) {
InstallFromDiskAction.installPluginFromDisk(null, project, InstalledPluginsTableModel(project), PluginEnabler.HEADLESS, null, {
trySend(PluginInstalledFromDiskResult(PluginDescriptorConverter.toPluginDto(it.pluginDescriptor), it.restartNeeded))
}
}, { _, _ -> })
}
}
}