use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.
the class ActionManagerImpl method error.
@NotNull
@Contract(pure = true)
private static RuntimeException error(@NotNull ActionStub stub, @NotNull Throwable original, @NotNull String template, @NotNull String className) {
PluginId pluginId = stub.getPluginId();
String text = MessageFormat.format(template, className);
if (pluginId == null) {
return new IllegalStateException(text);
}
return new PluginException(text, original, pluginId);
}
use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.
the class PluginInstaller method prepareToInstall.
private static boolean prepareToInstall(PluginNode pluginNode, List<PluginId> pluginIds, List<IdeaPluginDescriptor> allPlugins, Set<PluginNode> installedDependant, PluginManagerMain.PluginEnabler pluginEnabler, @NotNull ProgressIndicator indicator) throws IOException {
installedDependant.add(pluginNode);
// check for dependent plugins at first.
if (pluginNode.getDepends() != null && pluginNode.getDepends().size() > 0) {
// prepare plugins list for install
final PluginId[] optionalDependentPluginIds = pluginNode.getOptionalDependentPluginIds();
final List<PluginNode> depends = new ArrayList<>();
final List<PluginNode> optionalDeps = new ArrayList<>();
for (int i = 0; i < pluginNode.getDepends().size(); i++) {
PluginId depPluginId = pluginNode.getDepends().get(i);
if (PluginManager.isPluginInstalled(depPluginId) || PluginManagerCore.isModuleDependency(depPluginId) || InstalledPluginsState.getInstance().wasInstalled(depPluginId) || (pluginIds != null && pluginIds.contains(depPluginId))) {
// ignore installed or installing plugins
continue;
}
IdeaPluginDescriptor depPluginDescriptor = findPluginInRepo(depPluginId, allPlugins);
PluginNode depPlugin;
if (depPluginDescriptor instanceof PluginNode) {
depPlugin = (PluginNode) depPluginDescriptor;
} else {
depPlugin = new PluginNode(depPluginId, depPluginId.getIdString(), "-1");
}
if (depPluginDescriptor != null) {
if (ArrayUtil.indexOf(optionalDependentPluginIds, depPluginId) != -1) {
optionalDeps.add(depPlugin);
} else {
depends.add(depPlugin);
}
}
}
if (depends.size() > 0) {
// has something to install prior installing the plugin
final boolean[] proceed = new boolean[1];
try {
GuiUtils.runOrInvokeAndWait(() -> {
String title = IdeBundle.message("plugin.manager.dependencies.detected.title");
String deps = StringUtil.join(depends, node -> node.getName(), ", ");
String message = IdeBundle.message("plugin.manager.dependencies.detected.message", depends.size(), deps);
proceed[0] = Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES;
});
} catch (Exception e) {
return false;
}
if (!proceed[0] || !prepareToInstall(depends, allPlugins, installedDependant, pluginEnabler, indicator)) {
return false;
}
}
if (optionalDeps.size() > 0) {
final boolean[] proceed = new boolean[1];
try {
GuiUtils.runOrInvokeAndWait(() -> {
String title = IdeBundle.message("plugin.manager.dependencies.detected.title");
String deps = StringUtil.join(optionalDeps, node -> node.getName(), ", ");
String message = IdeBundle.message("plugin.manager.optional.dependencies.detected.message", optionalDeps.size(), deps);
proceed[0] = Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES;
});
} catch (Exception e) {
return false;
}
if (proceed[0] && !prepareToInstall(optionalDeps, allPlugins, installedDependant, pluginEnabler, indicator)) {
return false;
}
}
}
Ref<IdeaPluginDescriptor> toDisable = Ref.create(null);
Optional<PluginReplacement> replacement = StreamEx.of(PluginReplacement.EP_NAME.getExtensions()).findFirst(r -> r.getNewPluginId().equals(pluginNode.getPluginId().getIdString()));
if (replacement.isPresent()) {
PluginReplacement pluginReplacement = replacement.get();
IdeaPluginDescriptor oldPlugin = PluginManager.getPlugin(pluginReplacement.getOldPluginDescriptor().getPluginId());
if (oldPlugin == null) {
LOG.warn("Plugin with id '" + pluginReplacement.getOldPluginDescriptor().getPluginId() + "' not found");
} else if (!pluginEnabler.isDisabled(oldPlugin.getPluginId())) {
ApplicationManager.getApplication().invokeAndWait(() -> {
String title = IdeBundle.message("plugin.manager.obsolete.plugins.detected.title");
String message = pluginReplacement.getReplacementMessage(oldPlugin, pluginNode);
if (Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES) {
toDisable.set(oldPlugin);
}
});
}
}
PluginDownloader downloader = PluginDownloader.createDownloader(pluginNode, pluginNode.getRepositoryName(), null);
if (downloader.prepareToInstall(indicator)) {
synchronized (ourLock) {
downloader.install();
}
pluginNode.setStatus(PluginNode.STATUS_DOWNLOADED);
if (!toDisable.isNull()) {
pluginEnabler.disablePlugins(Collections.singleton(toDisable.get()));
}
} else {
return false;
}
return true;
}
use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.
the class PluginManagerMain method loadPluginsFromHostInBackground.
/**
* Start a new thread which downloads new list of plugins from the site in
* the background and updates a list of plugins in the table.
*/
protected void loadPluginsFromHostInBackground() {
setDownloadStatus(true);
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final List<IdeaPluginDescriptor> list = ContainerUtil.newArrayList();
final Map<String, String> errors = ContainerUtil.newLinkedHashMap();
ProgressIndicator indicator = new EmptyProgressIndicator();
List<String> hosts = RepositoryHelper.getPluginHosts();
Set<PluginId> unique = ContainerUtil.newHashSet();
for (String host : hosts) {
try {
if (host == null || acceptHost(host)) {
List<IdeaPluginDescriptor> plugins = RepositoryHelper.loadPlugins(host, indicator);
for (IdeaPluginDescriptor plugin : plugins) {
if (unique.add(plugin.getPluginId())) {
list.add(plugin);
}
}
}
} catch (FileNotFoundException e) {
LOG.info(host, e);
} catch (IOException e) {
LOG.info(host, e);
if (host != ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl()) {
errors.put(host, String.format("'%s' for '%s'", e.getMessage(), host));
}
}
}
UIUtil.invokeLaterIfNeeded(() -> {
setDownloadStatus(false);
if (!list.isEmpty()) {
InstalledPluginsState state = InstalledPluginsState.getInstance();
for (IdeaPluginDescriptor descriptor : list) {
state.onDescriptorDownload(descriptor);
}
modifyPluginsList(list);
propagateUpdates(list);
}
if (!errors.isEmpty()) {
String message = IdeBundle.message("error.list.of.plugins.was.not.loaded", StringUtil.join(errors.keySet(), ", "), StringUtil.join(errors.values(), ",\n"));
String title = IdeBundle.message("title.plugins");
String ok = CommonBundle.message("button.retry"), cancel = CommonBundle.getCancelButtonText();
if (Messages.showOkCancelDialog(message, title, ok, cancel, Messages.getErrorIcon()) == Messages.OK) {
loadPluginsFromHostInBackground();
}
}
});
});
}
use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.
the class PluginManagerMain method suggestToEnableInstalledDependantPlugins.
public static boolean suggestToEnableInstalledDependantPlugins(PluginEnabler pluginEnabler, List<PluginNode> list) {
final Set<IdeaPluginDescriptor> disabled = new HashSet<>();
final Set<IdeaPluginDescriptor> disabledDependants = new HashSet<>();
for (PluginNode node : list) {
final PluginId pluginId = node.getPluginId();
if (pluginEnabler.isDisabled(pluginId)) {
disabled.add(node);
}
final List<PluginId> depends = node.getDepends();
if (depends != null) {
final Set<PluginId> optionalDeps = new HashSet<>(Arrays.asList(node.getOptionalDependentPluginIds()));
for (PluginId dependantId : depends) {
if (optionalDeps.contains(dependantId))
continue;
final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(dependantId);
if (pluginDescriptor != null && pluginEnabler.isDisabled(dependantId)) {
disabledDependants.add(pluginDescriptor);
}
}
}
}
if (!disabled.isEmpty() || !disabledDependants.isEmpty()) {
String message = "";
if (disabled.size() == 1) {
message += "Updated plugin '" + disabled.iterator().next().getName() + "' is disabled.";
} else if (!disabled.isEmpty()) {
message += "Updated plugins " + StringUtil.join(disabled, pluginDescriptor -> pluginDescriptor.getName(), ", ") + " are disabled.";
}
if (!disabledDependants.isEmpty()) {
message += "<br>";
message += "Updated plugin" + (list.size() > 1 ? "s depend " : " depends ") + "on disabled";
if (disabledDependants.size() == 1) {
message += " plugin '" + disabledDependants.iterator().next().getName() + "'.";
} else {
message += " plugins " + StringUtil.join(disabledDependants, pluginDescriptor -> pluginDescriptor.getName(), ", ") + ".";
}
}
message += " Disabled plugins " + (disabled.isEmpty() ? "and plugins which depend on disabled " : "") + "won't be activated after restart.";
int result;
if (!disabled.isEmpty() && !disabledDependants.isEmpty()) {
result = Messages.showYesNoCancelDialog(XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), "Enable all", "Enable updated plugin" + (disabled.size() > 1 ? "s" : ""), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
if (result == Messages.CANCEL)
return false;
} else {
message += "<br>Would you like to enable ";
if (!disabled.isEmpty()) {
message += "updated plugin" + (disabled.size() > 1 ? "s" : "");
} else {
//noinspection SpellCheckingInspection
message += "plugin dependenc" + (disabledDependants.size() > 1 ? "ies" : "y");
}
message += "?";
result = Messages.showYesNoDialog(XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), Messages.getQuestionIcon());
if (result == Messages.NO)
return false;
}
if (result == Messages.YES) {
disabled.addAll(disabledDependants);
pluginEnabler.enablePlugins(disabled);
} else if (result == Messages.NO && !disabled.isEmpty()) {
pluginEnabler.enablePlugins(disabled);
}
return true;
}
return false;
}
use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.
the class InstalledPluginsManagerMain method checkInstalledPluginDependencies.
private static void checkInstalledPluginDependencies(@NotNull InstalledPluginsTableModel model, @NotNull IdeaPluginDescriptorImpl pluginDescriptor, @Nullable Component parent) {
final Set<PluginId> notInstalled = new HashSet<>();
final Set<PluginId> disabledIds = new HashSet<>();
final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds();
final PluginId[] optionalDependentPluginIds = pluginDescriptor.getOptionalDependentPluginIds();
for (PluginId id : dependentPluginIds) {
if (ArrayUtilRt.find(optionalDependentPluginIds, id) > -1)
continue;
final boolean disabled = model.isDisabled(id);
final boolean enabled = model.isEnabled(id);
if (!enabled && !disabled && !PluginManagerCore.isModuleDependency(id)) {
notInstalled.add(id);
} else if (disabled) {
disabledIds.add(id);
}
}
if (!notInstalled.isEmpty()) {
String deps = StringUtil.join(notInstalled, id -> id.toString(), ", ");
String message = "Plugin " + pluginDescriptor.getName() + " depends on unknown plugin" + (notInstalled.size() > 1 ? "s " : " ") + deps;
MessagesEx.showWarningDialog(parent, message, CommonBundle.getWarningTitle());
}
if (!disabledIds.isEmpty()) {
final Set<IdeaPluginDescriptor> dependencies = new HashSet<>();
for (IdeaPluginDescriptor ideaPluginDescriptor : model.getAllPlugins()) {
if (disabledIds.contains(ideaPluginDescriptor.getPluginId())) {
dependencies.add(ideaPluginDescriptor);
}
}
String part = "disabled plugin" + (dependencies.size() > 1 ? "s " : " ");
String deps = StringUtil.join(dependencies, descriptor -> descriptor.getName(), ", ");
String message = "Plugin " + pluginDescriptor.getName() + " depends on " + part + deps + ". Enable " + part.trim() + "?";
if (MessagesEx.showOkCancelDialog(parent, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.OK) {
model.enableRows(dependencies.toArray(new IdeaPluginDescriptor[dependencies.size()]), Boolean.TRUE);
}
}
}
Aggregations