Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. import com.intellij.ide.plugins.IdeaPluginDescriptor
  2. import com.intellij.ide.plugins.PluginManager
  3. import com.intellij.ide.plugins.PluginManagerCore
  4. import com.intellij.ide.plugins.PluginManagerMain
  5. import com.intellij.notification.Notification
  6. import com.intellij.notification.NotificationListener
  7. import com.intellij.notification.NotificationType
  8. import com.intellij.openapi.extensions.PluginId
  9. import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser
  10. import com.intellij.openapi.util.text.StringUtil
  11.  
  12. import javax.swing.event.HyperlinkEvent
  13.  
  14. import static liveplugin.PluginUtil.currentProjectInFrame
  15. import static liveplugin.PluginUtil.show
  16.  
  17. //def console = showInConsole("PluginSync console started\n",
  18. // "PluginSync", currentProjectInFrame())
  19. //def log = { String s -> console.print(s + "\n", ConsoleViewContentType.SYSTEM_OUTPUT) }
  20. //def myAllPlugins = RepositoryHelper.loadPluginsFromAllRepositories(null)
  21. //def allPluginsAsString = myAllPlugins.stream()
  22. // .map { v -> v.getPluginId().idString }
  23. // .collect(Collectors.joining(", "))
  24. //log("All plugins:\n$allPluginsAsString\n")
  25. //
  26. //def installedPlugins = PluginManagerCore.getPlugins()
  27. //def installedPluginsString = Arrays.asList(installedPlugins).stream()
  28. // .map { v -> v.getPluginId().idString }
  29. // .collect(Collectors.joining("\n"))
  30. //log("Installed plugins:\n$installedPluginsString\n")
  31.  
  32. final List<String> errorMessages = new ArrayList<>()
  33. List<PluginId> notInstalled = new ArrayList<>()
  34. List<IdeaPluginDescriptor> notEnabled = new ArrayList<>()
  35.  
  36. def wantedPlugins = ["AceJump",
  37. "zielu.svntoolbox",
  38. "FrameSwitcher",
  39. "GrepConsole",
  40. "String Manipulation",
  41. "de.santiv.fastscrolling",
  42. "de.endrullis.idea.postfixtemplates",
  43. ]
  44.  
  45. for (wanted in wantedPlugins) {
  46. def pId = PluginId.findId(wanted)
  47. if (pId == null) {
  48. show("Plugin $pId not found...")
  49. continue
  50. }
  51. def pDesc = PluginManager.getPlugin(pId)
  52. if (pDesc == null) {
  53. notInstalled.add(pId)
  54. errorMessages.add("Plugin '" + pId + "' isn't installed.")
  55. } else if (!pDesc.isEnabled()) {
  56. notEnabled.add(pDesc)
  57. errorMessages.add("Plugin '" + pDesc.getName() + "' isn't enabled.")
  58. }
  59. }
  60. if (!errorMessages.isEmpty()) {
  61. if (!notEnabled.isEmpty() && notInstalled.isEmpty()) {
  62. String plugins = notEnabled.size() == 1 ? notEnabled.get(0).getName() : "required plugins"
  63. errorMessages.add("<a href=\"enable\">Enable " + plugins + "</a>")
  64. } else if (!notEnabled.isEmpty() || !notInstalled.isEmpty()) {
  65. errorMessages.add("<a href=\"install\">Install required plugins</a>")
  66. }
  67. def message = StringUtil.join(errorMessages, "<br>")
  68. show(message, "Required plugins weren't loaded", NotificationType.ERROR, "wantedPlugins",
  69. [
  70. hyperlinkUpdate: { Notification notification, HyperlinkEvent event ->
  71. if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
  72. if ("enable" == event.getDescription()) {
  73. notification.expire()
  74. for (IdeaPluginDescriptor descriptor : notEnabled) {
  75. PluginManagerCore.enablePlugin(descriptor.getPluginId().getIdString())
  76. }
  77. PluginManagerMain.notifyPluginsUpdated(currentProjectInFrame())
  78. } else {
  79. Set<String> pluginIds = new HashSet<>()
  80. for (IdeaPluginDescriptor descriptor : notEnabled) {
  81. pluginIds.add(descriptor.getPluginId().getIdString())
  82. }
  83. for (PluginId pluginId : notInstalled) {
  84. pluginIds.add(pluginId.getIdString())
  85. }
  86. PluginsAdvertiser.installAndEnablePlugins(pluginIds,
  87. { notification.expire() } as Runnable)
  88. }
  89. }
  90. }
  91. ] as NotificationListener)
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement