use of com.intellij.externalDependencies.DependencyOnPlugin in project intellij-community by JetBrains.
the class CheckRequiredPluginsActivity method runCheck.
public static void runCheck(@NotNull final Project project) {
List<DependencyOnPlugin> dependencies = ExternalDependenciesManager.getInstance(project).getDependencies(DependencyOnPlugin.class);
if (dependencies.isEmpty())
return;
List<String> customRepositories = UpdateSettings.getInstance().getStoredPluginHosts();
final List<String> errorMessages = new ArrayList<>();
final List<String> missingCustomRepositories = new ArrayList<>();
final List<IdeaPluginDescriptor> disabled = new ArrayList<>();
final List<PluginId> notInstalled = new ArrayList<>();
for (DependencyOnPlugin dependency : dependencies) {
PluginId pluginId = PluginId.getId(dependency.getPluginId());
String channel = dependency.getChannel();
String customRepository = getCustomRepository(pluginId, channel);
if (!StringUtil.isEmpty(channel) && customRepositoryNotSpecified(customRepositories, customRepository)) {
errorMessages.add("Custom repository '" + customRepository + "' required for '" + project.getName() + "' project isn't installed.");
missingCustomRepositories.add(customRepository);
}
IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId);
if (plugin == null) {
errorMessages.add("Plugin '" + dependency.getPluginId() + "' required for '" + project.getName() + "' project isn't installed.");
notInstalled.add(pluginId);
continue;
}
if (!plugin.isEnabled()) {
errorMessages.add("Plugin '" + plugin.getName() + "' required for '" + project.getName() + "' project is disabled.");
disabled.add(plugin);
continue;
}
String minVersion = dependency.getMinVersion();
if (minVersion != null && VersionComparatorUtil.compare(plugin.getVersion(), minVersion) < 0) {
errorMessages.add("Project '" + project.getName() + "' requires plugin '" + plugin.getName() + "' version '" + minVersion + "' or higher, but '" + plugin.getVersion() + "' is installed.");
}
String maxVersion = dependency.getMaxVersion();
if (maxVersion != null && VersionComparatorUtil.compare(plugin.getVersion(), maxVersion) > 0) {
errorMessages.add("Project '" + project.getName() + "' requires plugin '" + plugin.getName() + "' version '" + maxVersion + "' or lower, but '" + plugin.getVersion() + "' is installed.");
}
}
if (!errorMessages.isEmpty()) {
if (!missingCustomRepositories.isEmpty()) {
errorMessages.add("<a href=\"addRepositories\">Add custom repositories and install required plugins</a>");
} else if (!disabled.isEmpty() && notInstalled.isEmpty()) {
String plugins = disabled.size() == 1 ? disabled.get(0).getName() : "required plugins";
errorMessages.add("<a href=\"enable\">Enable " + plugins + "</a>");
} else if (!disabled.isEmpty() || !notInstalled.isEmpty()) {
errorMessages.add("<a href=\"install\">Install required plugins</a>");
}
NOTIFICATION_GROUP.createNotification("Required plugins weren't loaded", StringUtil.join(errorMessages, "<br>"), NotificationType.ERROR, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull final Notification notification, @NotNull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if ("addRepositories".equals(event.getDescription())) {
UpdateSettings.getInstance().getStoredPluginHosts().addAll(missingCustomRepositories);
}
if ("enable".equals(event.getDescription())) {
notification.expire();
for (IdeaPluginDescriptor descriptor : disabled) {
PluginManagerCore.enablePlugin(descriptor.getPluginId().getIdString());
}
PluginManagerMain.notifyPluginsUpdated(project);
} else if ("install".equals(event.getDescription()) || "addRepositories".equals(event.getDescription())) {
Set<String> pluginIds = new HashSet<>();
for (IdeaPluginDescriptor descriptor : disabled) {
pluginIds.add(descriptor.getPluginId().getIdString());
}
for (PluginId pluginId : notInstalled) {
pluginIds.add(pluginId.getIdString());
}
PluginsAdvertiser.installAndEnablePlugins(pluginIds, () -> notification.expire());
}
}
}
}).notify(project);
}
}
use of com.intellij.externalDependencies.DependencyOnPlugin in project intellij-community by JetBrains.
the class ExternalDependenciesConfigurable method editPluginDependency.
@Nullable
private DependencyOnPlugin editPluginDependency(@NotNull JComponent parent, @NotNull final DependencyOnPlugin original) {
List<String> pluginIds = new ArrayList<>(getPluginNameByIdMap().keySet());
if (!original.getPluginId().isEmpty() && !pluginIds.contains(original.getPluginId())) {
pluginIds.add(original.getPluginId());
}
Collections.sort(pluginIds, (o1, o2) -> getPluginNameById(o1).compareToIgnoreCase(getPluginNameById(o2)));
final ComboBox pluginChooser = new ComboBox(ArrayUtilRt.toStringArray(pluginIds), 250);
pluginChooser.setRenderer(new ListCellRendererWrapper<String>() {
@Override
public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
setText(getPluginNameById(value));
}
});
new ComboboxSpeedSearch(pluginChooser) {
@Override
protected String getElementText(Object element) {
return getPluginNameById((String) element);
}
};
pluginChooser.setSelectedItem(original.getPluginId());
final JBTextField minVersionField = new JBTextField(StringUtil.notNullize(original.getMinVersion()));
final JBTextField maxVersionField = new JBTextField(StringUtil.notNullize(original.getMaxVersion()));
final JBTextField channelField = new JBTextField(StringUtil.notNullize(original.getChannel()));
minVersionField.getEmptyText().setText("<any>");
minVersionField.setColumns(10);
maxVersionField.getEmptyText().setText("<any>");
maxVersionField.setColumns(10);
channelField.setColumns(10);
JPanel panel = FormBuilder.createFormBuilder().addLabeledComponent("Plugin:", pluginChooser).addLabeledComponent("Minimum version:", minVersionField).addLabeledComponent("Maximum version:", maxVersionField).addLabeledComponent("Channel:", channelField).getPanel();
final DialogBuilder dialogBuilder = new DialogBuilder(parent).title("Required Plugin").centerPanel(panel);
dialogBuilder.setPreferredFocusComponent(pluginChooser);
pluginChooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialogBuilder.setOkActionEnabled(!StringUtil.isEmpty((String) pluginChooser.getSelectedItem()));
}
});
if (dialogBuilder.show() == DialogWrapper.OK_EXIT_CODE) {
return new DependencyOnPlugin(((String) pluginChooser.getSelectedItem()), StringUtil.nullize(minVersionField.getText().trim()), StringUtil.nullize(maxVersionField.getText().trim()), StringUtil.nullize(channelField.getText().trim()));
}
return null;
}
use of com.intellij.externalDependencies.DependencyOnPlugin in project intellij by bazelbuild.
the class PluginDependencyHelper method addDependency.
/**
* Adds dependency, or replaces existing dependency of same type. Doesn't trigger any update
* checking
*/
private static void addDependency(Project project, DependencyOnPlugin newDep) {
ExternalDependenciesManager manager = ExternalDependenciesManager.getInstance(project);
List<ProjectExternalDependency> deps = Lists.newArrayList(manager.getAllDependencies());
boolean added = false;
for (int i = 0; i < deps.size(); i++) {
ProjectExternalDependency dep = deps.get(i);
if (!(dep instanceof DependencyOnPlugin)) {
continue;
}
DependencyOnPlugin pluginDep = (DependencyOnPlugin) dep;
if (pluginDep.getPluginId().equals(newDep.getPluginId())) {
added = true;
deps.set(i, newDep);
}
}
if (!added) {
deps.add(newDep);
}
manager.setAllDependencies(deps);
}
use of com.intellij.externalDependencies.DependencyOnPlugin in project intellij-community by JetBrains.
the class ExternalDependenciesConfigurable method createComponent.
@Nullable
@Override
public JComponent createComponent() {
final JBList dependenciesList = new JBList();
dependenciesList.setCellRenderer(new ColoredListCellRendererWrapper<DependencyOnPlugin>() {
@Override
protected void doCustomize(JList list, DependencyOnPlugin value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
append(getPluginNameById(value.getPluginId()), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
String minVersion = value.getMinVersion();
String maxVersion = value.getMaxVersion();
if (minVersion != null || maxVersion != null) {
append(", version ");
}
if (minVersion != null && minVersion.equals(maxVersion)) {
append(minVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
} else if (minVersion != null && maxVersion != null) {
append("between ");
append(minVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
append(" and ");
append(maxVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
} else if (minVersion != null) {
append("at least ");
append(minVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
} else if (maxVersion != null) {
append("at most ");
append(maxVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
}
}
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
return editSelectedDependency(dependenciesList);
}
}.installOn(dependenciesList);
dependenciesList.setModel(myListModel);
JPanel dependenciesPanel = ToolbarDecorator.createDecorator(dependenciesList).disableUpDownActions().setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
replaceDependency(new DependencyOnPlugin("", null, null, null), dependenciesList);
}
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
editSelectedDependency(dependenciesList);
}
}).createPanel();
return FormBuilder.createFormBuilder().addLabeledComponentFillVertically("Plugins which are required to work on this project.", dependenciesPanel).getPanel();
}
use of com.intellij.externalDependencies.DependencyOnPlugin in project intellij-community by JetBrains.
the class ExternalDependenciesConfigurable method replaceDependency.
private void replaceDependency(DependencyOnPlugin original, JBList dependenciesList) {
DependencyOnPlugin dependency = editPluginDependency(dependenciesList, original);
if (dependency != null) {
for (ProjectExternalDependency dependency1 : new ArrayList<>(myListModel.getItems())) {
if (dependency1 instanceof DependencyOnPlugin && ((DependencyOnPlugin) dependency1).getPluginId().equals(dependency.getPluginId())) {
myListModel.remove(dependency1);
}
}
myListModel.add(dependency);
dependenciesList.setSelectedValue(dependency, true);
}
}
Aggregations