com.intellij.ide.plugins.PluginManagerCore Java Examples

The following examples show how to use com.intellij.ide.plugins.PluginManagerCore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KPXStartupNotification.java    From IntelliJ-Key-Promoter-X with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
  public void runActivity(@NotNull Project project) {
    if (ApplicationManager.getApplication().isUnitTestMode()) return;

    final Application application = ApplicationManager.getApplication();
    final KeyPromoterSettings settings = ServiceManager.getService(KeyPromoterSettings.class);
    final String installedVersion = settings.getInstalledVersion();

    final IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId("Key Promoter X"));
    if (installedVersion != null && plugin != null) {
      final int compare = VersionComparatorUtil.compare(installedVersion, plugin.getVersion());
//      if (true) { // TODO: Don't forget to remove that! For proofreading.
      if (compare < 0) {
        application.invokeLater(() -> KPXStartupDialog.showStartupDialog(project));
        settings.setInstalledVersion(plugin.getVersion());
      }
    }
  }
 
Example #2
Source File: DesktopHelpManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static HelpSet createHelpSet() {
  String urlToHelp = ApplicationInfo.getInstance().getHelpURL() + "/" + HELP_HS;
  HelpSet mainHelpSet = loadHelpSet(urlToHelp);
  if (mainHelpSet == null) return null;

  // merge plugins help sets
  PluginDescriptor[] pluginDescriptors = PluginManagerCore.getPlugins();
  for (PluginDescriptor pluginDescriptor : pluginDescriptors) {
    Collection<HelpSetPath> sets = pluginDescriptor.getHelpSets();
    for (HelpSetPath hsPath : sets) {
      String url = "jar:file:///" + pluginDescriptor.getPath().getAbsolutePath() + "/help/" + hsPath.getFile() + "!";
      if (!hsPath.getPath().startsWith("/")) {
        url += "/";
      }
      url += hsPath.getPath();
      HelpSet pluginHelpSet = loadHelpSet(url);
      if (pluginHelpSet != null) {
        mainHelpSet.add(pluginHelpSet);
      }
    }
  }

  return mainHelpSet;
}
 
Example #3
Source File: FileTemplatesLoader.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void loadDefaultTemplates() {
  final Set<URL> processedUrls = new HashSet<>();
  for (PluginDescriptor plugin : PluginManagerCore.getPlugins()) {
    if (plugin.isEnabled()) {
      final ClassLoader loader = plugin.getPluginClassLoader();
      try {
        final Enumeration<URL> systemResources = loader.getResources(DEFAULT_TEMPLATES_ROOT);
        if (systemResources.hasMoreElements()) {
          while (systemResources.hasMoreElements()) {
            final URL url = systemResources.nextElement();
            if (processedUrls.contains(url)) {
              continue;
            }
            processedUrls.add(url);
            loadDefaultsFromRoot(url);
          }
        }
      }
      catch (IOException e) {
        LOG.error(e);
      }
    }
  }
}
 
Example #4
Source File: StartupManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void runActivities(@Nonnull UIAccess uiAccess, @Nonnull Deque<? extends Consumer<UIAccess>> activities, @Nonnull String phaseName) {
  Activity activity = StartUpMeasurer.startMainActivity(phaseName);

  while (true) {
    Consumer<UIAccess> runnable;
    synchronized (myLock) {
      runnable = activities.pollFirst();
    }

    if (runnable == null) {
      break;
    }

    long startTime = StartUpMeasurer.getCurrentTime();

    PluginDescriptor plugin = PluginManager.getPlugin(runnable.getClass());
    String pluginId = plugin != null ? plugin.getPluginId().getIdString() : PluginManagerCore.CORE_PLUGIN_ID;

    runActivity(uiAccess, runnable);

    StartUpMeasurer.addCompletedActivity(startTime, runnable.getClass(), ActivityCategory.POST_STARTUP_ACTIVITY, pluginId, StartUpMeasurer.MEASURE_THRESHOLD);
  }

  activity.end();
}
 
Example #5
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
ActionManagerImpl(ActionToolbarFactory toolbarFactory) {
  myToolbarFactory = toolbarFactory;

  StatCollector collector = new StatCollector();

  for (PluginDescriptor plugin : PluginManager.getPlugins()) {
    if (PluginManagerCore.shouldSkipPlugin(plugin)) {
      continue;
    }

    collector.markWith(plugin.getPluginId().toString(), () -> {
      LocalizeHelper localizeHelper = LocalizeHelper.build(plugin);

      registerPluginActions(plugin, localizeHelper);
    });
  }

  collector.dump("ActionManager statistics", LOG::info);
}
 
Example #6
Source File: PantsClasspathRunConfigurationExtension.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Filter out all jars imported to the project with the exception of
 * jars on the JDK path, IntelliJ installation paths, and plugin installation path,
 * because Pants is already exporting all the runtime classpath in manifest.jar.
 *
 * Exception applies during unit test of this plugin because "JUnit" and "com.intellij"
 * plugin lives under somewhere under ivy, whereas during normal usage, they are covered
 * by `homePath`.
 *
 *
 * @param params JavaParameters
 * @return a set of paths that should be allowed to passed to the test runner.
 */
@NotNull
private Set<String> calculatePathsAllowed(JavaParameters params) {

  String homePath = PathManager.getHomePath();
  String pluginPath = PathManager.getPluginsPath();

  Set<String> pathsAllowed = Sets.newHashSet(homePath, pluginPath);

  if (ApplicationManager.getApplication().isUnitTestMode()) {
    // /Users/yic/.ivy2/pants/com.intellij.sdk.community/idea_rt/jars/idea_rt-latest.jar ->
    // /Users/yic/.ivy2/pants/com.intellij.sdk.community/
    Optional.ofNullable(PluginManagerCore.getPlugin(PluginId.getId("com.intellij")))
      .map(s -> s.getPath().getParentFile().getParentFile().getParentFile().getAbsolutePath())
      .ifPresent(pathsAllowed::add);

    // At this point we know junit plugin is already enabled.
    // //Users/yic/.ivy2/pants/com.intellij.junit-plugin/junit-rt/jars/junit-rt-latest.jar ->
    // /Users/yic/.ivy2/pants/com.intellij.junit-plugin/
    Optional.ofNullable(PluginManagerCore.getPlugin(PluginId.getId("JUnit")))
      .map(s -> s.getPath().getParentFile().getParentFile().getParentFile().getAbsolutePath())
      .ifPresent(pathsAllowed::add);
  }
  return pathsAllowed;
}
 
Example #7
Source File: SpringFormatComponent.java    From spring-javaformat with Apache License 2.0 6 votes vote down vote up
private void registerCodeStyleManager(CodeStyleManager manager) {
	if (ApplicationInfo.getInstance().getBuild().getBaselineVersion() >= 193) {
		IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId("spring-javaformat"));
		try {
			((ComponentManagerImpl) this.project).registerServiceInstance(CodeStyleManager.class, manager, plugin);
		}
		catch (NoSuchMethodError ex) {
			Method method = findRegisterServiceInstanceMethod(this.project.getClass());
			invokeRegisterServiceInstanceMethod(manager, plugin, method);
		}
	}
	else {
		MutablePicoContainer container = (MutablePicoContainer) this.project.getPicoContainer();
		container.unregisterComponent(CODE_STYLE_MANAGER_KEY);
		container.registerComponentInstance(CODE_STYLE_MANAGER_KEY, manager);
	}
}
 
Example #8
Source File: BlazeIntellijPluginDeployer.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String readPluginIdFromJar(String buildNumber, File jar)
    throws ExecutionException {
  IdeaPluginDescriptor pluginDescriptor = PluginManagerCore.loadDescriptor(jar, "plugin.xml");
  if (pluginDescriptor == null) {
    return null;
  }
  if (PluginManagerCore.isIncompatible(pluginDescriptor, BuildNumber.fromString(buildNumber))) {
    throw new ExecutionException(
        String.format(
            "Plugin SDK version '%s' is incompatible with this plugin "
                + "(since: '%s', until: '%s')",
            buildNumber, pluginDescriptor.getSinceBuild(), pluginDescriptor.getUntilBuild()));
  }
  return pluginDescriptor.getPluginId().getIdString();
}
 
Example #9
Source File: PantsCodeInsightFixtureTestCase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  getModule().setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, PantsConstants.SYSTEM_ID.getId());

  final String pyPluginId = "PythonCore";
  final IdeaPluginDescriptor pyPlugin = PluginManagerCore.getPlugin(PluginId.getId(pyPluginId));
  assertNotNull(
    "Python Community Edition plugin should be in classpath for tests\n" +
    "You need to include jars from ~/Library/Application Support/IdeaIC14/python/lib/",
    pyPlugin
  );

  if (!pyPlugin.isEnabled()) {
    assertTrue("Failed to enable Python plugin!", PluginManagerCore.enablePlugin(pyPluginId));
  }

  final String testUserHome = VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(PantsTestUtils.BASE_TEST_DATA_PATH + "/userHome"));
  final Optional<VirtualFile> folderWithPex =
    PantsUtil.findFolderWithPex(Optional.ofNullable(VirtualFileManager.getInstance().findFileByUrl(testUserHome)));
  assertTrue("Folder with pex files should be configured", folderWithPex.isPresent());
  final VirtualFile[] pexFiles = folderWithPex.get().getChildren();
  assertTrue("There should be only one pex file!", pexFiles.length == 1);

  ApplicationManager.getApplication().runWriteAction(() -> configurePantsLibrary(myFixture.getProject(), pexFiles[0]));
  assertNotNull(
    "Pants lib not configured!",
    LibraryTablesRegistrar.getInstance().getLibraryTable(myFixture.getProject()).getLibraryByName(PantsConstants.PANTS_LIBRARY_NAME)
  );
}
 
Example #10
Source File: PantsIntegrationTestCase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  cleanProjectIdeaDir();
  super.setUp();
  VfsRootAccess.allowRootAccess(myProject, "/");
  for (String pluginId : getRequiredPluginIds()) {
    IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId(pluginId));
    assertNotNull(pluginId + " plugin should be in classpath for integration tests!", plugin);
    assertTrue(pluginId + " is not enabled!", plugin.isEnabled());
  }

  myProjectSettings = new PantsProjectSettings();
  myCompilerTester = null;
}
 
Example #11
Source File: LegalNotice.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
protected final Action[] createActions() {
    DialogWrapperAction declineAction = new DialogWrapperAction(DECLINE) {
        @Override
        protected final void doAction(final ActionEvent e) {
            PluginManagerCore.disablePlugin(KODEBEAGLEIDEA);
            ApplicationManagerEx.getApplicationEx().restart(true);
        }
    };
    return new Action[]{getOKAction(), declineAction, getCancelAction()};
}
 
Example #12
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static boolean isPythonAvailable() {
  for (String pluginId : PYTHON_PLUGIN_IDS) {
    final IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId(pluginId));
    if (plugin != null && plugin.isEnabled()) {
      return true;
    }
  }

  return false;
}
 
Example #13
Source File: DisablePluginsTestRule.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void before() throws Throwable {
  if (ApplicationManager.getApplication() != null) {
    // We may be able to relax this constraint if we check that the desired
    // disabledPluginIds matches the existing value of ourDisabledPlugins.
    throw new RuntimeException("Cannot disable plugins; they've already been loaded.");
  }
  disabledPluginIds.forEach(PluginManagerCore::disablePlugin);
}
 
Example #14
Source File: ComponentManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void registerServices(InjectingContainerBuilder builder) {
  for (PluginDescriptor plugin : PluginManager.getPlugins()) {
    if (!PluginManagerCore.shouldSkipPlugin(plugin)) {
      List<ComponentConfig> componentConfigs = getComponentConfigs(plugin);

      for (ComponentConfig componentConfig : componentConfigs) {
        registerComponent(componentConfig, plugin);
      }
    }
  }

  myComponentsRegistry.loadClasses(myNotLazyServices, builder);
}
 
Example #15
Source File: ExportSettingsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String getComponentPresentableName(@Nonnull State state, @Nonnull Class<?> aClass) {
  String defaultName = state.name();
  String resourceBundleName;

  PluginDescriptor pluginDescriptor = null;
  ClassLoader classLoader = aClass.getClassLoader();

  if(classLoader instanceof PluginClassLoader) {
    pluginDescriptor = PluginManager.getPlugin(((PluginClassLoader)classLoader).getPluginId());
  }

  if (pluginDescriptor != null && !PluginManagerCore.CORE_PLUGIN.equals(pluginDescriptor.getPluginId())) {
    resourceBundleName = pluginDescriptor.getResourceBundleBaseName();
  }
  else {
    resourceBundleName = OptionsBundle.PATH_TO_BUNDLE;
  }

  if (resourceBundleName == null) {
    return defaultName;
  }

  if (classLoader != null) {
    ResourceBundle bundle = AbstractBundle.getResourceBundle(resourceBundleName, classLoader);
    if (bundle != null) {
      return CommonBundle.messageOrDefault(bundle, "exportable." + defaultName + ".presentable.name", defaultName);
    }
  }
  return defaultName;
}
 
Example #16
Source File: ComponentManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void fillListenerDescriptors(MultiMap<String, PluginListenerDescriptor> mapByTopic) {
  for (PluginDescriptor plugin : PluginManager.getPlugins()) {
    if (!PluginManagerCore.shouldSkipPlugin(plugin)) {
      List<PluginListenerDescriptor> descriptors = getPluginListenerDescriptors(plugin);

      for (PluginListenerDescriptor descriptor : descriptors) {
        mapByTopic.putValue(descriptor.topicClassName, descriptor);
      }
    }
  }
}
 
Example #17
Source File: PluginAdvertiserEditorNotificationProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static PluginDescriptor getDisabledPlugin(Set<String> plugins) {
  final List<String> disabledPlugins = new ArrayList<>(PluginManagerCore.getDisabledPlugins());
  disabledPlugins.retainAll(plugins);
  if (disabledPlugins.size() == 1) {
    return PluginManager.getPlugin(PluginId.getId(disabledPlugins.get(0)));
  }
  return null;
}
 
Example #18
Source File: PluginExtensionRegistrator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void registerExtensionPointsAndExtensions(ExtensionAreaId areaId, ExtensionsAreaImpl area) {
  Iterable<PluginDescriptor> plugins = PluginManager.getPlugins();
  List<PluginDescriptor> list = new ArrayList<>();
  for (PluginDescriptor plugin : plugins) {
    if (!PluginManagerCore.shouldSkipPlugin(plugin)) {
      list.add(plugin);
    }
  }

  registerExtensionPointsAndExtensions(areaId, area, list);
}
 
Example #19
Source File: ClionUnitTestSystemPropertiesRule.java    From intellij with Apache License 2.0 4 votes vote down vote up
/** Sets up the necessary system properties for running IntelliJ tests via blaze/bazel. */
private static void configureSystemProperties() throws IOException {
  File sandbox = new File(getTmpDirFile(), "_intellij_test_sandbox");

  setSandboxPath("idea.home.path", new File(sandbox, "home"));
  setSandboxPath("idea.config.path", new File(sandbox, "config"));
  setSandboxPath("idea.system.path", new File(sandbox, "system"));

  setSandboxPath("java.util.prefs.userRoot", new File(sandbox, "userRoot"));
  setSandboxPath("java.util.prefs.systemRoot", new File(sandbox, "systemRoot"));

  setIfEmpty("idea.classpath.index.enabled", "false");

  // Some plugins have a since-build and until-build restriction, so we need
  // to update the build number here
  PluginManagerCore.BUILD_NUMBER = readApiVersionNumber();

  // Tests fail if they access files outside of the project roots and other system directories.
  // Ensure runfiles and platform api are whitelisted.
  VfsRootAccess.allowRootAccess(RUNFILES_PATH);
  String platformApi = getPlatformApiPath();
  if (platformApi != null) {
    VfsRootAccess.allowRootAccess(platformApi);
  }

  List<String> pluginJars = Lists.newArrayList();
  try {
    Enumeration<URL> urls =
        ClionUnitTestSystemPropertiesRule.class
            .getClassLoader()
            .getResources("META-INF/plugin.xml");
    while (urls.hasMoreElements()) {
      URL url = urls.nextElement();
      addArchiveFile(url, pluginJars);
    }
  } catch (IOException e) {
    System.err.println("Cannot find plugin.xml resources");
    e.printStackTrace();
  }

  setIfEmpty("idea.plugins.path", Joiner.on(File.pathSeparator).join(pluginJars));
}
 
Example #20
Source File: TipUIUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getPoweredByText(@Nonnull TipAndTrickBean tip) {
  PluginDescriptor descriptor = tip.getPluginDescriptor();
  return !PluginManagerCore.CORE_PLUGIN_ID.equals(descriptor.getPluginId().getIdString()) ? descriptor.getName() : "";
}
 
Example #21
Source File: LegalNotice.java    From KodeBeagle with Apache License 2.0 4 votes vote down vote up
@Override
public final void doCancelAction() {
    super.doCancelAction();
    PluginManagerCore.disablePlugin(KODEBEAGLEIDEA);
    ApplicationManagerEx.getApplicationEx().restart(true);
}
 
Example #22
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void projectOpened(@Nonnull MessageBusConnection connection) {
  //myFocusWatcher.install(myWindows.getComponent ());
  getMainSplitters().startListeningFocus();

  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject);
  if (fileStatusManager != null) {
    /*
      Updates tabs colors
     */
    final MyFileStatusListener myFileStatusListener = new MyFileStatusListener();
    fileStatusManager.addFileStatusListener(myFileStatusListener, myProject);
  }
  connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());
  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootsListener());

  /*
    Updates tabs names
   */
  final MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener();
  VirtualFileManager.getInstance().addVirtualFileListener(myVirtualFileListener, myProject);
  /*
    Extends/cuts number of opened tabs. Also updates location of tabs.
   */
  connection.subscribe(UISettingsListener.TOPIC, new MyUISettingsListener());

  StartupManager.getInstance(myProject).registerPostStartupActivity((DumbAwareRunnable)() -> {
    if (myProject.isDisposed()) return;
    setTabsMode(UISettings.getInstance().getEditorTabPlacement() != UISettings.TABS_NONE);

    ToolWindowManager.getInstance(myProject).invokeLater(() -> {
      if (!myProject.isDisposed()) {
        CommandProcessor.getInstance().executeCommand(myProject, () -> {
          ApplicationManager.getApplication().invokeLater(() -> {
            long currentTime = System.nanoTime();
            Long startTime = myProject.getUserData(ProjectImpl.CREATION_TIME);
            if (startTime != null) {
              LOG.info("Project opening took " + (currentTime - startTime) / 1000000 + " ms");
              PluginManagerCore.dumpPluginClassStatistics(LOG);
            }
          }, myProject.getDisposed());
          // group 1
        }, "", null);
      }
    });
  });
}
 
Example #23
Source File: GoogleJavaFormatInstaller.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
private static void setManager(Project project, CodeStyleManager newManager) {
  ComponentManagerImpl platformComponentManager = (ComponentManagerImpl) project;
  IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId("google-java-format"));
  checkState(plugin != null, "Couldn't locate our own PluginDescriptor.");
  platformComponentManager.registerServiceInstance(CodeStyleManager.class, newManager, plugin);
}