use of com.intellij.openapi.updateSettings.impl.PluginDownloader 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.updateSettings.impl.PluginDownloader in project intellij-community by JetBrains.
the class PluginsAdvertiser method runActivity.
@Override
public void runActivity(@NotNull Project project) {
if (!UpdateSettings.getInstance().isCheckNeeded()) {
return;
}
final UnknownFeaturesCollector collectorSuggester = UnknownFeaturesCollector.getInstance(project);
final Set<UnknownFeature> unknownFeatures = collectorSuggester.getUnknownFeatures();
final KnownExtensions extensions = loadExtensions();
if (extensions != null && unknownFeatures.isEmpty()) {
return;
}
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode() || application.isHeadlessEnvironment()) {
return;
}
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> application.executeOnPooledThread(new Runnable() {
private final Set<PluginDownloader> myPlugins = new HashSet<>();
private List<IdeaPluginDescriptor> myAllPlugins;
private final Map<Plugin, IdeaPluginDescriptor> myDisabledPlugins = new HashMap<>();
private List<String> myBundledPlugin;
private final MultiMap<String, UnknownFeature> myFeatures = new MultiMap<>();
@Override
public void run() {
if (project.isDisposed()) {
return;
}
try {
myAllPlugins = RepositoryHelper.loadPluginsFromAllRepositories(null);
if (project.isDisposed()) {
return;
}
if (extensions == null) {
loadSupportedExtensions(myAllPlugins);
if (project.isDisposed())
return;
EditorNotifications.getInstance(project).updateAllNotifications();
}
final Map<String, Plugin> ids = new HashMap<>();
for (UnknownFeature feature : unknownFeatures) {
ProgressManager.checkCanceled();
final List<Plugin> pluginId = retrieve(feature);
if (pluginId != null) {
for (Plugin plugin : pluginId) {
ids.put(plugin.myPluginId, plugin);
myFeatures.putValue(plugin.myPluginId, feature);
}
}
}
final List<String> disabledPlugins = PluginManagerCore.getDisabledPlugins();
//include disabled plugins
for (String id : ids.keySet()) {
Plugin plugin = ids.get(id);
if (disabledPlugins.contains(id)) {
final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(PluginId.getId(id));
if (pluginDescriptor != null) {
myDisabledPlugins.put(plugin, pluginDescriptor);
}
}
}
myBundledPlugin = hasBundledPluginToInstall(ids.values());
for (IdeaPluginDescriptor loadedPlugin : myAllPlugins) {
final PluginId pluginId = loadedPlugin.getPluginId();
if (ids.containsKey(pluginId.getIdString()) && !disabledPlugins.contains(pluginId.getIdString()) && !PluginManagerCore.isBrokenPlugin(loadedPlugin)) {
myPlugins.add(PluginDownloader.createDownloader(loadedPlugin));
}
}
ApplicationManager.getApplication().invokeLater(this::onSuccess, ModalityState.NON_MODAL);
} catch (Exception e) {
LOG.info(e);
}
}
private void onSuccess() {
String message = null;
if (!myPlugins.isEmpty() || !myDisabledPlugins.isEmpty()) {
message = getAddressedMessagePresentation();
if (!myDisabledPlugins.isEmpty()) {
message += "<a href=\"enable\">Enable plugins...</a><br>";
} else {
message += "<a href=\"configure\">Configure plugins...</a><br>";
}
message += "<a href=\"ignore\">Ignore Unknown Features</a>";
} else if (myBundledPlugin != null && !PropertiesComponent.getInstance().isTrueValue(IGNORE_ULTIMATE_EDITION)) {
message = "Features covered by " + IDEA_ULTIMATE_EDITION + " (" + StringUtil.join(myBundledPlugin, ", ") + ") are detected.<br>" + "<a href=\"open\">" + CHECK_ULTIMATE_EDITION_TITLE + "</a><br>" + "<a href=\"ignoreUltimate\">" + ULTIMATE_EDITION_SUGGESTION + "</a>";
}
if (message != null) {
final ConfigurePluginsListener notificationListener = new ConfigurePluginsListener(unknownFeatures, project, myAllPlugins, myPlugins, myDisabledPlugins);
NOTIFICATION_GROUP.createNotification(DISPLAY_ID, message, NotificationType.INFORMATION, notificationListener).notify(project);
}
}
@NotNull
private String getAddressedMessagePresentation() {
final MultiMap<String, String> addressedFeatures = MultiMap.createSet();
final Set<String> ids = new LinkedHashSet<>();
for (PluginDownloader plugin : myPlugins) {
ids.add(plugin.getPluginId());
}
for (Plugin plugin : myDisabledPlugins.keySet()) {
ids.add(plugin.myPluginId);
}
for (String id : ids) {
for (UnknownFeature feature : myFeatures.get(id)) {
addressedFeatures.putValue(feature.getFeatureDisplayName(), feature.getImplementationName());
}
}
final String addressedFeaturesPresentation = StringUtil.join(addressedFeatures.entrySet(), entry -> entry.getKey() + "[" + StringUtil.join(entry.getValue(), ", ") + "]", ", ");
final int addressedFeaturesNumber = addressedFeatures.keySet().size();
final int pluginsNumber = ids.size();
return StringUtil.pluralize("Plugin", pluginsNumber) + " supporting " + StringUtil.pluralize("feature", addressedFeaturesNumber) + " (" + addressedFeaturesPresentation + ") " + (pluginsNumber == 1 ? "is" : "are") + " currently " + (myPlugins.isEmpty() ? "disabled" : "not installed") + ".<br>";
}
}));
}
use of com.intellij.openapi.updateSettings.impl.PluginDownloader in project intellij-community by JetBrains.
the class UpdatePluginsFromCustomRepositoryTest method testOnlyCompatiblePluginsAreChecked.
@Test
public void testOnlyCompatiblePluginsAreChecked() throws Exception {
Map<PluginId, PluginDownloader> toUpdate = new LinkedHashMap<>();
IdeaPluginDescriptor[] descriptors = new IdeaPluginDescriptor[] { loadDescriptor("plugin1.xml"), loadDescriptor("plugin2.xml") };
BuildNumber currentBuildNumber = BuildNumber.fromString("IU-142.100");
for (IdeaPluginDescriptor descriptor : descriptors) {
PluginDownloader downloader = PluginDownloader.createDownloader(descriptor, null, currentBuildNumber);
UpdateChecker.checkAndPrepareToInstall(downloader, new InstalledPluginsState(), toUpdate, new ArrayList<>(), null);
}
assertEquals("Found: " + toUpdate.size(), 1, toUpdate.size());
PluginDownloader downloader = toUpdate.values().iterator().next();
assertNotNull(downloader);
assertEquals("0.1", downloader.getPluginVersion());
}
use of com.intellij.openapi.updateSettings.impl.PluginDownloader in project intellij-community by JetBrains.
the class CustomizeFeaturedPluginsStepPanel method onPluginGroupsLoaded.
private void onPluginGroupsLoaded() {
List<IdeaPluginDescriptor> pluginsFromRepository = myPluginGroups.getPluginsFromRepository();
if (pluginsFromRepository.isEmpty()) {
myInProgressLabel.setText("Cannot get featured plugins description online.");
return;
}
removeAll();
JPanel gridPanel = new JPanel(new GridLayout(0, 3));
JBScrollPane scrollPane = CustomizePluginsStepPanel.createScrollPane(gridPanel);
Map<String, String> config = myPluginGroups.getFeaturedPlugins();
for (Map.Entry<String, String> entry : config.entrySet()) {
JPanel groupPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.WEST;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1;
String title = entry.getKey();
String s = entry.getValue();
int i = s.indexOf(':');
String topic = s.substring(0, i);
int j = s.indexOf(':', i + 1);
String description = s.substring(i + 1, j);
final String pluginId = s.substring(j + 1);
IdeaPluginDescriptor foundDescriptor = null;
for (IdeaPluginDescriptor descriptor : pluginsFromRepository) {
if (descriptor.getPluginId().getIdString().equals(pluginId) && !PluginManagerCore.isBrokenPlugin(descriptor)) {
foundDescriptor = descriptor;
break;
}
}
if (foundDescriptor == null)
continue;
final IdeaPluginDescriptor descriptor = foundDescriptor;
final boolean isVIM = PluginGroups.IDEA_VIM_PLUGIN_ID.equals(descriptor.getPluginId().getIdString());
boolean isCloud = "#Cloud".equals(topic);
if (isCloud) {
title = descriptor.getName();
description = StringUtil.defaultIfEmpty(descriptor.getDescription(), "No description available");
topic = StringUtil.defaultIfEmpty(descriptor.getCategory(), "Unknown");
}
JLabel titleLabel = new JLabel("<html><body><h2 style=\"text-align:left;\">" + title + "</h2></body></html>");
JLabel topicLabel = new JLabel("<html><body><h4 style=\"text-align:left;color:#808080;font-weight:bold;\">" + topic + "</h4></body></html>");
JLabel descriptionLabel = createHTMLLabel(description);
JLabel warningLabel = null;
if (isVIM || isCloud) {
if (isCloud) {
warningLabel = createHTMLLabel("From your JetBrains account");
warningLabel.setIcon(AllIcons.General.BalloonInformation);
} else {
warningLabel = createHTMLLabel("Recommended only if you are<br> familiar with Vim.");
warningLabel.setIcon(AllIcons.General.BalloonWarning);
}
if (!SystemInfo.isWindows)
UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, warningLabel);
}
final CardLayout wrapperLayout = new CardLayout();
final JPanel buttonWrapper = new JPanel(wrapperLayout);
final JButton installButton = new JButton(isVIM ? "Install and Enable" : "Install");
final JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setStringPainted(true);
JPanel progressPanel = new JPanel(new VerticalFlowLayout(true, false));
progressPanel.add(progressBar);
final LinkLabel cancelLink = new LinkLabel("Cancel", AllIcons.Actions.Cancel);
JPanel linkWrapper = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
linkWrapper.add(cancelLink);
progressPanel.add(linkWrapper);
final JPanel buttonPanel = new JPanel(new VerticalFlowLayout(0, 0));
buttonPanel.add(installButton);
buttonWrapper.add(buttonPanel, "button");
buttonWrapper.add(progressPanel, "progress");
wrapperLayout.show(buttonWrapper, "button");
final ProgressIndicatorEx indicator = new AbstractProgressIndicatorExBase(true) {
@Override
public void start() {
myCanceled.set(false);
super.start();
SwingUtilities.invokeLater(() -> wrapperLayout.show(buttonWrapper, "progress"));
}
@Override
public void processFinish() {
super.processFinish();
SwingUtilities.invokeLater(() -> {
wrapperLayout.show(buttonWrapper, "button");
installButton.setEnabled(false);
installButton.setText("Installed");
});
}
@Override
public void setFraction(final double fraction) {
super.setFraction(fraction);
SwingUtilities.invokeLater(() -> {
int value = (int) (100 * fraction + .5);
progressBar.setValue(value);
progressBar.setString(value + "%");
});
}
@Override
public void cancel() {
stop();
myCanceled.set(true);
super.cancel();
SwingUtilities.invokeLater(() -> {
wrapperLayout.show(buttonWrapper, "button");
progressBar.setValue(0);
progressBar.setString("0%");
});
}
};
installButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
wrapperLayout.show(buttonWrapper, "progress");
ourService.execute(new Runnable() {
@Override
public void run() {
try {
indicator.start();
IdeInitialConfigButtonUsages.addDownloadedPlugin(descriptor.getPluginId().getIdString());
PluginDownloader downloader = PluginDownloader.createDownloader(descriptor);
downloader.prepareToInstall(indicator);
downloader.install();
indicator.processFinish();
} catch (Exception ignored) {
if (!myCanceled.get()) {
onFail();
}
}
}
void onFail() {
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
indicator.stop();
wrapperLayout.show(buttonWrapper, "progress");
progressBar.setString("Cannot download plugin");
});
}
});
}
});
cancelLink.setListener(new LinkListener() {
@Override
public void linkSelected(LinkLabel aSource, Object aLinkData) {
indicator.cancel();
}
}, null);
gbc.insets.left = installButton.getInsets().left / 2;
gbc.insets.right = installButton.getInsets().right / 2;
gbc.insets.bottom = -5;
groupPanel.add(titleLabel, gbc);
gbc.insets.bottom = SMALL_GAP;
groupPanel.add(topicLabel, gbc);
groupPanel.add(descriptionLabel, gbc);
gbc.weighty = 1;
groupPanel.add(Box.createVerticalGlue(), gbc);
gbc.weighty = 0;
if (warningLabel != null) {
Insets insetsBefore = gbc.insets;
gbc.insets = new Insets(0, -10, SMALL_GAP, -10);
gbc.insets.left += insetsBefore.left;
gbc.insets.right += insetsBefore.right;
JPanel warningPanel = new JPanel(new BorderLayout());
warningPanel.setBorder(new EmptyBorder(5, 10, 5, 10));
warningPanel.add(warningLabel);
groupPanel.add(warningPanel, gbc);
gbc.insets = insetsBefore;
}
gbc.insets.bottom = gbc.insets.left = gbc.insets.right = 0;
groupPanel.add(buttonWrapper, gbc);
gridPanel.add(groupPanel);
}
while (gridPanel.getComponentCount() < 4) {
gridPanel.add(Box.createVerticalBox());
}
int cursor = 0;
Component[] components = gridPanel.getComponents();
int rowCount = components.length / COLS;
for (Component component : components) {
((JComponent) component).setBorder(new CompoundBorder(new CustomLineBorder(ColorUtil.withAlpha(JBColor.foreground(), .2), 0, 0, cursor / 3 < rowCount && (!(component instanceof Box)) ? 1 : 0, cursor % COLS != COLS - 1 && (!(component instanceof Box)) ? 1 : 0) {
@Override
protected Color getColor() {
return ColorUtil.withAlpha(JBColor.foreground(), .2);
}
}, BorderFactory.createEmptyBorder(0, SMALL_GAP, 0, SMALL_GAP)));
cursor++;
}
add(scrollPane);
revalidate();
repaint();
}
use of com.intellij.openapi.updateSettings.impl.PluginDownloader in project intellij-community by JetBrains.
the class PluginsAdvertiserDialog method doOKAction.
@Override
protected void doOKAction() {
final Set<String> pluginsToEnable = new HashSet<>();
final List<PluginNode> nodes = new ArrayList<>();
for (PluginDownloader downloader : myUploadedPlugins) {
String pluginId = downloader.getPluginId();
if (!mySkippedPlugins.contains(pluginId)) {
pluginsToEnable.add(pluginId);
if (!pluginHelper.isDisabled(pluginId)) {
final PluginNode pluginNode = PluginDownloader.createPluginNode(null, downloader);
if (pluginNode != null) {
nodes.add(pluginNode);
}
}
}
}
PluginManagerMain.suggestToEnableInstalledDependantPlugins(pluginHelper, nodes);
final Runnable notifyRunnable = () -> PluginManagerMain.notifyPluginsUpdated(myProject);
for (String pluginId : pluginsToEnable) {
PluginManagerCore.enablePlugin(pluginId);
}
if (!nodes.isEmpty()) {
try {
PluginManagerMain.downloadPlugins(nodes, myAllPlugins, notifyRunnable, pluginHelper, null);
} catch (IOException e) {
LOG.error(e);
}
} else {
if (!pluginsToEnable.isEmpty()) {
notifyRunnable.run();
}
}
super.doOKAction();
}
Aggregations