Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.intellij.ide.plugins.IdeaPluginDescriptor
- import com.intellij.ide.plugins.PluginManager
- import com.intellij.ide.plugins.PluginManagerCore
- import com.intellij.ide.plugins.PluginManagerMain
- import com.intellij.notification.Notification
- import com.intellij.notification.NotificationListener
- import com.intellij.notification.NotificationType
- import com.intellij.openapi.extensions.PluginId
- import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser
- import com.intellij.openapi.util.text.StringUtil
- import javax.swing.event.HyperlinkEvent
- import static liveplugin.PluginUtil.currentProjectInFrame
- import static liveplugin.PluginUtil.show
- //def console = showInConsole("PluginSync console started\n",
- // "PluginSync", currentProjectInFrame())
- //def log = { String s -> console.print(s + "\n", ConsoleViewContentType.SYSTEM_OUTPUT) }
- //def myAllPlugins = RepositoryHelper.loadPluginsFromAllRepositories(null)
- //def allPluginsAsString = myAllPlugins.stream()
- // .map { v -> v.getPluginId().idString }
- // .collect(Collectors.joining(", "))
- //log("All plugins:\n$allPluginsAsString\n")
- //
- //def installedPlugins = PluginManagerCore.getPlugins()
- //def installedPluginsString = Arrays.asList(installedPlugins).stream()
- // .map { v -> v.getPluginId().idString }
- // .collect(Collectors.joining("\n"))
- //log("Installed plugins:\n$installedPluginsString\n")
- final List<String> errorMessages = new ArrayList<>()
- List<PluginId> notInstalled = new ArrayList<>()
- List<IdeaPluginDescriptor> notEnabled = new ArrayList<>()
- def wantedPlugins = ["AceJump",
- "zielu.svntoolbox",
- "FrameSwitcher",
- "GrepConsole",
- "String Manipulation",
- "de.santiv.fastscrolling",
- "de.endrullis.idea.postfixtemplates",
- ]
- for (wanted in wantedPlugins) {
- def pId = PluginId.findId(wanted)
- if (pId == null) {
- show("Plugin $pId not found...")
- continue
- }
- def pDesc = PluginManager.getPlugin(pId)
- if (pDesc == null) {
- notInstalled.add(pId)
- errorMessages.add("Plugin '" + pId + "' isn't installed.")
- } else if (!pDesc.isEnabled()) {
- notEnabled.add(pDesc)
- errorMessages.add("Plugin '" + pDesc.getName() + "' isn't enabled.")
- }
- }
- if (!errorMessages.isEmpty()) {
- if (!notEnabled.isEmpty() && notInstalled.isEmpty()) {
- String plugins = notEnabled.size() == 1 ? notEnabled.get(0).getName() : "required plugins"
- errorMessages.add("<a href=\"enable\">Enable " + plugins + "</a>")
- } else if (!notEnabled.isEmpty() || !notInstalled.isEmpty()) {
- errorMessages.add("<a href=\"install\">Install required plugins</a>")
- }
- def message = StringUtil.join(errorMessages, "<br>")
- show(message, "Required plugins weren't loaded", NotificationType.ERROR, "wantedPlugins",
- [
- hyperlinkUpdate: { Notification notification, HyperlinkEvent event ->
- if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
- if ("enable" == event.getDescription()) {
- notification.expire()
- for (IdeaPluginDescriptor descriptor : notEnabled) {
- PluginManagerCore.enablePlugin(descriptor.getPluginId().getIdString())
- }
- PluginManagerMain.notifyPluginsUpdated(currentProjectInFrame())
- } else {
- Set<String> pluginIds = new HashSet<>()
- for (IdeaPluginDescriptor descriptor : notEnabled) {
- pluginIds.add(descriptor.getPluginId().getIdString())
- }
- for (PluginId pluginId : notInstalled) {
- pluginIds.add(pluginId.getIdString())
- }
- PluginsAdvertiser.installAndEnablePlugins(pluginIds,
- { notification.expire() } as Runnable)
- }
- }
- }
- ] as NotificationListener)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement