mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[dynamic plugins] DisabledPluginsState should not be updated on project closing #IDEA-252873 fixed
GitOrigin-RevId: 13f682c3add6615eb227d5258877120b053a027a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c18825bf04
commit
f2b215cfbe
@@ -195,6 +195,23 @@ public final class DisabledPluginsState {
|
||||
trySaveDisabledPlugins(disabled);
|
||||
}
|
||||
|
||||
static boolean updateDisabledPluginsState(@NotNull List<? extends IdeaPluginDescriptor> pluginsToEnable,
|
||||
@NotNull List<? extends IdeaPluginDescriptor> pluginsToDisable) {
|
||||
Set<PluginId> disabledIds = getDisabledIds();
|
||||
|
||||
for (IdeaPluginDescriptor descriptor : pluginsToEnable) {
|
||||
descriptor.setEnabled(true);
|
||||
disabledIds.remove(descriptor.getPluginId());
|
||||
}
|
||||
|
||||
for (IdeaPluginDescriptor descriptor : pluginsToDisable) {
|
||||
descriptor.setEnabled(false);
|
||||
disabledIds.add(descriptor.getPluginId());
|
||||
}
|
||||
|
||||
return trySaveDisabledPlugins(disabledIds);
|
||||
}
|
||||
|
||||
static boolean trySaveDisabledPlugins(@NotNull Collection<PluginId> disabledPlugins) {
|
||||
try {
|
||||
saveDisabledPlugins(disabledPlugins, false);
|
||||
|
||||
@@ -83,15 +83,15 @@ public class InstalledPluginsTableModel {
|
||||
protected final void setEnabled(@NotNull IdeaPluginDescriptor ideaPluginDescriptor) {
|
||||
PluginId pluginId = ideaPluginDescriptor.getPluginId();
|
||||
|
||||
final boolean descriptorEnabled = ideaPluginDescriptor.isEnabled();
|
||||
boolean isEnabled = !PluginManagerCore.isDisabled(pluginId);
|
||||
PluginEnabledState enabled;
|
||||
if (descriptorEnabled || PluginManagerCore.isDisabled(pluginId)) {
|
||||
if (ideaPluginDescriptor.isEnabled() || !isEnabled) {
|
||||
ProjectPluginTracker pluginTracker = getPluginTracker();
|
||||
enabled = (pluginTracker != null && pluginTracker.isEnabled(pluginId)) ?
|
||||
PluginEnabledState.ENABLED_FOR_PROJECT :
|
||||
(pluginTracker != null && pluginTracker.isDisabled(pluginId)) ?
|
||||
PluginEnabledState.DISABLED_FOR_PROJECT :
|
||||
descriptorEnabled ?
|
||||
isEnabled ?
|
||||
PluginEnabledState.ENABLED :
|
||||
PluginEnabledState.DISABLED;
|
||||
}
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
package com.intellij.ide.plugins;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.PluginId;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.openapi.util.text.StringUtil.join;
|
||||
import static java.util.Collections.emptyList;
|
||||
@@ -31,7 +28,8 @@ public final class PluginEnabler {
|
||||
project,
|
||||
enable ? plugins : emptyList(),
|
||||
enable ? emptyList() : plugins,
|
||||
null
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,7 +39,8 @@ public final class PluginEnabler {
|
||||
public static boolean updatePluginEnabledState(@Nullable Project project,
|
||||
@NotNull List<? extends IdeaPluginDescriptor> pluginsToEnable,
|
||||
@NotNull List<? extends IdeaPluginDescriptor> pluginsToDisable,
|
||||
@Nullable JComponent parentComponent) {
|
||||
@Nullable JComponent parentComponent,
|
||||
boolean updateDisabledPluginsState) {
|
||||
if (pluginsToEnable.isEmpty() &&
|
||||
pluginsToDisable.isEmpty()) {
|
||||
return true;
|
||||
@@ -49,48 +48,14 @@ public final class PluginEnabler {
|
||||
LOG.info(getLogMessage(pluginsToEnable, true));
|
||||
LOG.info(getLogMessage(pluginsToDisable, false));
|
||||
|
||||
ProjectPluginTracker pluginTracker = project != null ?
|
||||
ProjectPluginTracker.getInstance(project) :
|
||||
null;
|
||||
boolean requiresRestart =
|
||||
updateDisabledPluginsState && !DisabledPluginsState.updateDisabledPluginsState(pluginsToEnable, pluginsToDisable) ||
|
||||
!DynamicPlugins.loadUnloadPlugins(pluginsToEnable, pluginsToDisable, project, parentComponent);
|
||||
|
||||
Set<PluginId> disabledIds = DisabledPluginsState.getDisabledIds();
|
||||
|
||||
for (IdeaPluginDescriptor descriptor : pluginsToEnable) {
|
||||
PluginId pluginId = descriptor.getPluginId();
|
||||
if (pluginTracker == null ||
|
||||
!pluginTracker.isEnabled(pluginId)) {
|
||||
descriptor.setEnabled(true);
|
||||
disabledIds.remove(pluginId);
|
||||
}
|
||||
}
|
||||
|
||||
for (IdeaPluginDescriptor descriptor : pluginsToDisable) {
|
||||
PluginId pluginId = descriptor.getPluginId();
|
||||
if (pluginTracker == null ||
|
||||
!pluginTracker.isDisabled(pluginId)) {
|
||||
descriptor.setEnabled(false);
|
||||
disabledIds.add(pluginId);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DisabledPluginsState.saveDisabledPlugins(disabledIds, false);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
boolean applied = DynamicPlugins.loadUnloadPlugins(
|
||||
pluginsToEnable,
|
||||
pluginsToDisable,
|
||||
project,
|
||||
parentComponent
|
||||
);
|
||||
|
||||
if (!applied) {
|
||||
if (requiresRestart) {
|
||||
InstalledPluginsState.getInstance().setRestartRequired(true);
|
||||
}
|
||||
return applied;
|
||||
return !requiresRestart;
|
||||
}
|
||||
|
||||
private static @NotNull String getLogMessage(@NotNull List<? extends IdeaPluginDescriptor> pluginsToEnable,
|
||||
|
||||
@@ -45,7 +45,8 @@ internal class ProjectPluginTracker(project: Project) : PersistentStateComponent
|
||||
project,
|
||||
setToAddTo(enable).findPluginById(),
|
||||
setToRemoveFrom(enable).findPluginById(),
|
||||
null
|
||||
null,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.updateSettings.impl.UpdateSettings;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -39,6 +38,7 @@ import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -180,13 +180,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM
|
||||
myDynamicPluginsToInstall.clear();
|
||||
myPluginsToRemoveOnCancel.clear();
|
||||
|
||||
Pair<List<IdeaPluginDescriptor>, List<IdeaPluginDescriptor>> pair = collectPluginsToEnableDisable();
|
||||
boolean enableDisableAppliedWithoutRestart = PluginEnabler.updatePluginEnabledState(
|
||||
getProject(),
|
||||
pair.getFirst(),
|
||||
pair.getSecond(),
|
||||
parent
|
||||
);
|
||||
boolean enableDisableAppliedWithoutRestart = applyEnableDisablePlugins(parent);
|
||||
myDynamicPluginsToUninstall.clear();
|
||||
myDiff.clear();
|
||||
|
||||
@@ -214,9 +208,32 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM
|
||||
myPluginsToRemoveOnCancel.clear();
|
||||
}
|
||||
|
||||
private @NotNull Pair<@NotNull List<IdeaPluginDescriptor>, @NotNull List<IdeaPluginDescriptor>> collectPluginsToEnableDisable() {
|
||||
List<IdeaPluginDescriptor> pluginsToEnable = new ArrayList<>();
|
||||
List<IdeaPluginDescriptor> pluginsToDisable = new ArrayList<>();
|
||||
private final class UpdatePluginStateAction implements BiPredicate<@Nullable JComponent, @NotNull Boolean> {
|
||||
|
||||
private final ArrayList<IdeaPluginDescriptor> myPluginsToEnable = new ArrayList<>();
|
||||
private final ArrayList<IdeaPluginDescriptor> myPluginsToDisable = new ArrayList<>();
|
||||
|
||||
public void register(@NotNull IdeaPluginDescriptor descriptor,
|
||||
boolean enable) {
|
||||
(enable ? myPluginsToEnable : myPluginsToDisable).add(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(@Nullable JComponent parentComponent,
|
||||
@NotNull Boolean updatePluginEnabledState) {
|
||||
return PluginEnabler.updatePluginEnabledState(
|
||||
getProject(),
|
||||
myPluginsToEnable,
|
||||
myPluginsToDisable,
|
||||
parentComponent,
|
||||
updatePluginEnabledState
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean applyEnableDisablePlugins(@Nullable JComponent parent) {
|
||||
UpdatePluginStateAction applyPerProjectAction = new UpdatePluginStateAction();
|
||||
UpdatePluginStateAction applyGloballyAction = new UpdatePluginStateAction();
|
||||
|
||||
ProjectPluginTracker pluginTracker = getPluginTracker();
|
||||
for (Map.Entry<IdeaPluginDescriptor, PluginEnabledState> entry : myDiff.entrySet()) {
|
||||
@@ -240,16 +257,17 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM
|
||||
|
||||
boolean shouldEnable = newState.isEnabled();
|
||||
boolean isEnabled = entry.getValue().isEnabled();
|
||||
if (shouldEnable && !isEnabled) {
|
||||
pluginsToEnable.add(descriptor);
|
||||
}
|
||||
else if (!shouldEnable &&
|
||||
(isEnabled || myErrorPluginsToDisable.contains(pluginId))) {
|
||||
pluginsToDisable.add(descriptor);
|
||||
if (shouldEnable != isEnabled ||
|
||||
!shouldEnable && myErrorPluginsToDisable.contains(pluginId)) {
|
||||
UpdatePluginStateAction action = newState.isPerProject() ?
|
||||
applyPerProjectAction :
|
||||
applyGloballyAction;
|
||||
action.register(descriptor, shouldEnable);
|
||||
}
|
||||
}
|
||||
|
||||
return Pair.create(pluginsToEnable, pluginsToDisable);
|
||||
return applyPerProjectAction.test(parent, Boolean.FALSE) &&
|
||||
applyGloballyAction.test(parent, Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void pluginInstalledFromDisk(@NotNull PluginInstallCallbackData callbackData) {
|
||||
|
||||
Reference in New Issue
Block a user