private void loadApplicationComponents() {
   final IdeaPluginDescriptor[] plugins = PluginManager.getPlugins();
   for (IdeaPluginDescriptor plugin : plugins) {
     if (PluginManager.shouldSkipPlugin(plugin)) continue;
     loadComponentsConfiguration(plugin.getAppComponents(), plugin, false);
   }
 }
 private Map<String, String> getPluginNameByIdMap() {
   if (myPluginNameById == null) {
     myPluginNameById = new HashMap<String, String>();
     for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) {
       myPluginNameById.put(descriptor.getPluginId().getIdString(), descriptor.getName());
     }
   }
   return myPluginNameById;
 }
Example #3
0
 @Nullable
 IdeaPluginDescriptor findPlugin(String id) {
   for (IdeaPluginDescriptor pluginDescriptor : myAllPlugins) {
     PluginId pluginId = pluginDescriptor.getPluginId();
     if (pluginId != null && StringUtil.equals(pluginId.getIdString(), id)) {
       return pluginDescriptor;
     }
   }
   return null;
 }
Example #4
0
  @Nullable
  public static VirtualFile getPluginVirtualDirectory() {
    IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("Lua"));
    if (descriptor != null) {
      File pluginPath = descriptor.getPath();

      String url = VfsUtil.pathToUrl(pluginPath.getAbsolutePath());

      return VirtualFileManager.getInstance().findFileByUrl(url);
    }

    return null;
  }
Example #5
0
 private List<String> getNonOptionalDependencies(final String id) {
   List<String> result = new ArrayList<String>();
   IdeaPluginDescriptor descriptor = findPlugin(id);
   if (descriptor != null) {
     for (PluginId pluginId : descriptor.getDependentPluginIds()) {
       if (pluginId.getIdString().equals("com.intellij")) continue;
       if (!ArrayUtil.contains(pluginId, descriptor.getOptionalDependentPluginIds())) {
         result.add(pluginId.getIdString());
       }
     }
   }
   return result;
 }
 private static void checkForUpdates() {
   PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
   long lastUpdate = propertiesComponent.getOrInitLong(KEY, 0);
   if (lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1)) {
     ApplicationManager.getApplication()
         .executeOnPooledThread(
             () -> {
               try {
                 String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
                 IdeaPluginDescriptor plugin = getPlugin();
                 String pluginVersion = plugin.getVersion();
                 String pluginId = plugin.getPluginId().getIdString();
                 String os =
                     URLEncoder.encode(
                         SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
                 String uid = PermanentInstallationID.get();
                 String url =
                     "https://plugins.jetbrains.com/plugins/list"
                         + "?pluginId="
                         + pluginId
                         + "&build="
                         + buildNumber
                         + "&pluginVersion="
                         + pluginVersion
                         + "&os="
                         + os
                         + "&uuid="
                         + uid;
                 PropertiesComponent.getInstance()
                     .setValue(KEY, String.valueOf(System.currentTimeMillis()));
                 HttpRequests.request(url)
                     .connect(
                         request -> {
                           try {
                             JDOMUtil.load(request.getReader());
                             LOG.info(
                                 (request.isSuccessful() ? "Successful" : "Unsuccessful")
                                     + " update: "
                                     + url);
                           } catch (JDOMException e) {
                             LOG.warn(e);
                           }
                           return null;
                         });
               } catch (UnknownHostException ignored) {
               } catch (IOException e) {
                 LOG.warn(e);
               }
             });
   }
 }
  private void mergeWithDefaultConfiguration() {
    final ArrayList<Configuration> cfgList = new ArrayList<Configuration>();
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
      final String config = support.getDefaultConfigUrl();
      final URL url = config == null ? null : support.getClass().getResource(config);
      if (url != null) {
        try {
          cfgList.add(load(url.openStream()));
        } catch (Exception e) {
          LOG.warn(e);
        }
      }
    }
    final THashSet<Object> visited = new THashSet<Object>();
    for (IdeaPluginDescriptor pluginDescriptor : PluginManager.getPlugins()) {
      if (pluginDescriptor instanceof IdeaPluginDescriptorImpl
          && !((IdeaPluginDescriptorImpl) pluginDescriptor).isEnabled()) continue;
      final ClassLoader loader = pluginDescriptor.getPluginClassLoader();
      if (!visited.add(loader)) continue;
      if (loader instanceof PluginClassLoader && ((PluginClassLoader) loader).getUrls().isEmpty())
        continue;
      try {
        final Enumeration<URL> enumeration = loader.getResources("META-INF/languageInjections.xml");
        if (enumeration == null) continue;
        while (enumeration.hasMoreElements()) {
          URL url = enumeration.nextElement();
          if (!visited.add(url.getFile())) continue; // for DEBUG mode
          try {
            cfgList.add(load(url.openStream()));
          } catch (Exception e) {
            LOG.warn(e);
          }
        }
      } catch (Exception e) {
        LOG.warn(e);
      }
    }

    final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>();
    final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>();
    myDefaultInjections = new ArrayList<BaseInjection>();
    for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
      for (Configuration cfg : cfgList) {
        final List<BaseInjection> imported = cfg.getInjections(supportId);
        myDefaultInjections.addAll(imported);
        importInjections(getInjections(supportId), imported, originalInjections, newInjections);
      }
    }
    replaceInjections(newInjections, originalInjections);
  }
  @Override
  public void setDefaultParameters(
      @NotNull Project project,
      @NotNull VirtualFile virtualFile,
      @NotNull BackgroundTaskByVfsParameters backgroundTaskByVfsParameters) {
    Sdk sdk = null;
    Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
    if (module != null) {
      sdk = ModuleUtilCore.getSdk(module, JavaModuleExtension.class);
    }

    if (sdk == null) {
      sdk = SdkTable.getInstance().findPredefinedSdkByType(JavaSdk.getInstance());
    }

    if (sdk == null) {
      sdk = SdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
    }

    List<String> parameters = new ArrayList<String>();
    if (sdk != null) {
      GeneralCommandLine generalCommandLine = new GeneralCommandLine();

      ((JavaSdkType) sdk.getSdkType()).setupCommandLine(generalCommandLine, sdk);
      backgroundTaskByVfsParameters.setExePath(generalCommandLine.getExePath());
      parameters.addAll(generalCommandLine.getParametersList().getList());
    } else {
      backgroundTaskByVfsParameters.setExePath(SystemInfo.isWindows ? "java.exe" : "java");
    }

    PluginClassLoader classLoader =
        (PluginClassLoader) JFlexBackgroundTaskProvider.class.getClassLoader();
    IdeaPluginDescriptor plugin = PluginManager.getPlugin(classLoader.getPluginId());
    assert plugin != null;
    parameters.add("-jar");
    parameters.add(new File(plugin.getPath(), "jflex/jflex.jar").getAbsolutePath());
    parameters.add("--charat");
    parameters.add("--noconstr");
    parameters.add("--nobak");
    parameters.add("--skel");
    parameters.add(new File(plugin.getPath(), "jflex/idea-flex.skeleton").getAbsolutePath());
    parameters.add("$FilePath$");

    backgroundTaskByVfsParameters.setProgramParameters(StringUtil.join(parameters, " "));
    backgroundTaskByVfsParameters.setWorkingDirectory("$FileParentPath$");
    backgroundTaskByVfsParameters.setOutPath("$FileParentPath$");
  }
Example #9
0
 private void collectInvolvedIds(final String pluginId, boolean toEnable, Set<String> ids) {
   ids.add(pluginId);
   if (toEnable) {
     for (String id : getNonOptionalDependencies(pluginId)) {
       collectInvolvedIds(id, true, ids);
     }
   } else {
     Condition<PluginId> condition =
         new Condition<PluginId>() {
           @Override
           public boolean value(PluginId id) {
             return pluginId.equals(id.getIdString());
           }
         };
     for (final IdeaPluginDescriptor plugin : myAllPlugins) {
       if (null != ContainerUtil.find(plugin.getDependentPluginIds(), condition)
           && null == ContainerUtil.find(plugin.getOptionalDependentPluginIds(), condition)) {
         collectInvolvedIds(plugin.getPluginId().getIdString(), false, ids);
       }
     }
   }
 }
  @Override
  public void initComponent() {
    IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(getId("IntelliJEval"));
    if (pluginDescriptor != null && pluginDescriptor.isEnabled()) {
      livePluginNotificationGroup
          .createNotification(
              "It seems that you have IntelliJEval plugin enabled.<br/>Please disable it to use LivePlugin.",
              NotificationType.ERROR)
          .notify(null);
      return;
    }
    checkThatGroovyIsOnClasspath();

    Settings settings = Settings.getInstance();
    if (settings.justInstalled) {
      installHelloWorldPlugin();
      settings.justInstalled = false;
    }
    if (settings.runAllPluginsOnIDEStartup) {
      runAllPlugins();
    }

    new PluginToolWindowManager().init();
  }
Example #11
0
 @NotNull
 @Override
 public ComponentConfig[] getMyComponentConfigsFromDescriptor(
     @NotNull IdeaPluginDescriptor plugin) {
   return plugin.getModuleComponents();
 }
 // Get version info of our Plugin
 private String getPluginVersion() {
   final IdeaPluginDescriptor plugin =
       PluginManager.getPlugin(PluginId.getId("com.microsoft.vso.idea"));
   final String v = plugin != null ? plugin.getVersion() : DEFAULT_VERSION;
   return StringUtils.isNotEmpty(v) ? v : DEFAULT_VERSION;
 }
  private static boolean doSubmit(
      final IdeaLoggingEvent event,
      final Component parentComponent,
      final Consumer<SubmittedReportInfo> callback,
      final ErrorBean bean,
      final String description) {
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);

    bean.setDescription(description);
    bean.setMessage(event.getMessage());

    Throwable throwable = event.getThrowable();
    if (throwable != null) {
      final PluginId pluginId = IdeErrorsDialog.findPluginId(throwable);
      if (pluginId != null) {
        final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
        if (ideaPluginDescriptor != null && !ideaPluginDescriptor.isBundled()) {
          bean.setPluginName(ideaPluginDescriptor.getName());
          bean.setPluginVersion(ideaPluginDescriptor.getVersion());
        }
      }
    }

    Object data = event.getData();

    if (data instanceof LogMessageEx) {
      bean.setAttachments(((LogMessageEx) data).getAttachments());
    }

    LinkedHashMap<String, String> reportValues =
        IdeaITNProxy.getKeyValuePairs(
            bean,
            ApplicationManager.getApplication(),
            (ApplicationInfoEx) ApplicationInfo.getInstance(),
            ApplicationNamesInfo.getInstance());

    final Project project = CommonDataKeys.PROJECT.getData(dataContext);

    Consumer<String> successCallback =
        new Consumer<String>() {
          @Override
          public void consume(String token) {
            final SubmittedReportInfo reportInfo =
                new SubmittedReportInfo(
                    null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
            callback.consume(reportInfo);

            ReportMessages.GROUP
                .createNotification(
                    ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null)
                .setImportant(false)
                .notify(project);
          }
        };

    Consumer<Exception> errorCallback =
        new Consumer<Exception>() {
          @Override
          public void consume(Exception e) {
            String message = GoBundle.message("go.error.report.message", e.getMessage());
            ReportMessages.GROUP
                .createNotification(
                    ReportMessages.ERROR_REPORT,
                    message,
                    NotificationType.ERROR,
                    NotificationListener.URL_OPENING_LISTENER)
                .setImportant(false)
                .notify(project);
          }
        };
    AnonymousFeedbackTask task =
        new AnonymousFeedbackTask(
            project, "Submitting error report", true, reportValues, successCallback, errorCallback);
    if (project == null) {
      task.run(new EmptyProgressIndicator());
    } else {
      ProgressManager.getInstance().run(task);
    }
    return true;
  }
  @Nullable
  private EditorNotificationPanel createPanel(
      final String extension, final Set<PluginsAdvertiser.Plugin> plugins) {
    final EditorNotificationPanel panel = new EditorNotificationPanel();

    panel.setText("Plugins supporting " + extension + " files found.");
    final IdeaPluginDescriptor disabledPlugin = PluginsAdvertiser.getDisabledPlugin(plugins);
    if (disabledPlugin != null) {
      panel.createActionLabel(
          "Enable " + disabledPlugin.getName() + " plugin",
          () -> {
            myEnabledExtensions.add(extension);
            myNotifications.updateAllNotifications();
            PluginsAdvertiser.enablePlugins(myProject, Collections.singletonList(disabledPlugin));
          });
    } else if (hasNonBundledPlugin(plugins)) {
      panel.createActionLabel(
          "Install plugins",
          () -> {
            Set<String> pluginIds = new HashSet<>();
            for (PluginsAdvertiser.Plugin plugin : plugins) {
              pluginIds.add(plugin.myPluginId);
            }
            PluginsAdvertiser.installAndEnablePlugins(
                pluginIds,
                () -> {
                  myEnabledExtensions.add(extension);
                  myNotifications.updateAllNotifications();
                });
          });
    } else if (PluginsAdvertiser.hasBundledPluginToInstall(plugins) != null) {
      if (PropertiesComponent.getInstance()
          .isTrueValue(PluginsAdvertiser.IGNORE_ULTIMATE_EDITION)) {
        return null;
      }
      panel.setText(
          extension + " files are supported by " + PluginsAdvertiser.IDEA_ULTIMATE_EDITION);

      panel.createActionLabel(
          PluginsAdvertiser.CHECK_ULTIMATE_EDITION_TITLE,
          () -> {
            myEnabledExtensions.add(extension);
            PluginsAdvertiser.openDownloadPage();
          });

      panel.createActionLabel(
          PluginsAdvertiser.ULTIMATE_EDITION_SUGGESTION,
          () -> {
            PropertiesComponent.getInstance()
                .setValue(PluginsAdvertiser.IGNORE_ULTIMATE_EDITION, "true");
            myNotifications.updateAllNotifications();
          });
    } else {
      return null;
    }
    panel.createActionLabel(
        "Ignore extension",
        () -> {
          UnknownFeaturesCollector.getInstance(myProject)
              .ignoreFeature(createExtensionFeature(extension));
          myNotifications.updateAllNotifications();
        });
    return panel;
  }
  @NotNull
  protected String[] getSystemLibraryUrlsImpl(
      @NotNull Sdk sdk, String name, OrderRootType orderRootType) {
    if (orderRootType == BinariesOrderRootType.getInstance()) {
      File libraryByAssemblyName = getLibraryByAssemblyName(name, null);
      if (libraryByAssemblyName == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }

      return new String[] {
        VirtualFileManager.constructUrl(
                DotNetModuleFileType.PROTOCOL, libraryByAssemblyName.getPath())
            + ArchiveFileSystem.ARCHIVE_SEPARATOR
      };
    } else if (orderRootType == DocumentationOrderRootType.getInstance()) {
      String[] systemLibraryUrls = getSystemLibraryUrls(name, BinariesOrderRootType.getInstance());
      if (systemLibraryUrls.length != 1) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }
      VirtualFile libraryFile =
          VirtualFileManager.getInstance().findFileByUrl(systemLibraryUrls[0]);
      if (libraryFile == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }
      VirtualFile localFile = ArchiveVfsUtil.getVirtualFileForArchive(libraryFile);
      if (localFile == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
      }
      VirtualFile docFile =
          localFile.getParent().findChild(localFile.getNameWithoutExtension() + ".xml");
      if (docFile != null) {
        return new String[] {docFile.getUrl()};
      }
      return ArrayUtil.EMPTY_STRING_ARRAY;
    } else if (orderRootType == ExternalAttributesRootOrderType.getInstance()) {
      try {
        final Ref<Couple<String>> ref = Ref.create();
        File libraryFile = getLibraryByAssemblyName(name, ref);
        if (libraryFile == null) {
          return ArrayUtil.EMPTY_STRING_ARRAY;
        }

        assert ref.get() != null;

        PluginClassLoader classLoader = (PluginClassLoader) getClass().getClassLoader();
        IdeaPluginDescriptor plugin = PluginManager.getPlugin(classLoader.getPluginId());
        assert plugin != null;
        File dir = new File(plugin.getPath(), "externalAttributes");

        val urls = new SmartList<String>();
        val requiredFileName = name + ".xml";
        FileUtil.visitFiles(
            dir,
            new Processor<File>() {
              @Override
              public boolean process(File file) {
                if (file.isDirectory()) {
                  return true;
                }
                if (Comparing.equal(requiredFileName, file.getName(), false)
                    && isValidExternalFile(ref.get().getSecond(), file)) {
                  urls.add(VfsUtil.pathToUrl(file.getPath()));
                }
                return true;
              }
            });

        return ArrayUtil.toStringArray(urls);
      } catch (Exception e) {
        LOGGER.error(e);
      }
    }
    return ArrayUtil.EMPTY_STRING_ARRAY;
  }
  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<String>();
    final List<String> missingCustomRepositories = new ArrayList<String>();
    final List<IdeaPluginDescriptor> disabled = new ArrayList<IdeaPluginDescriptor>();
    final List<PluginId> notInstalled = new ArrayList<PluginId>();
    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 '"
                + minVersion
                + "' 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<String>();
                      for (IdeaPluginDescriptor descriptor : disabled) {
                        pluginIds.add(descriptor.getPluginId().getIdString());
                      }
                      for (PluginId pluginId : notInstalled) {
                        pluginIds.add(pluginId.getIdString());
                      }
                      PluginsAdvertiser.installAndEnablePlugins(
                          pluginIds, () -> notification.expire());
                    }
                  }
                }
              })
          .notify(project);
    }
  }