private static boolean downloadPluginsImpl(List<PluginNode> plugins,
                                             Collection<PluginNode> customPlugins,
                                             boolean allowInstallWithoutRestart,
                                             @Nullable Runnable onSuccess,
                                             com.intellij.ide.plugins.PluginEnabler pluginEnabler,
                                             @Nullable Consumer<Boolean> function,
                                             ModalityState modalityState,
                                             boolean inBackground) throws IOException {
    try {
      boolean[] result = new boolean[1];

      Consumer<ProgressIndicator> downloading = (ProgressIndicator indicator) -> {
        try {
          //TODO: `PluginInstallOperation` expects only `customPlugins`, but it can take `allPlugins` too
          PluginInstallOperation operation = new PluginInstallOperation(plugins, customPlugins, pluginEnabler, indicator);
          operation.setAllowInstallWithoutRestart(allowInstallWithoutRestart);
          operation.run();

          boolean success = operation.isSuccess();
          result[0] = success;
          if (success) {
            ApplicationManager.getApplication().invokeLater(() -> {
              if (allowInstallWithoutRestart) {
                for (PendingDynamicPluginInstall install : operation.getPendingDynamicPluginInstalls()) {
                  result[0] &= PluginInstaller.installAndLoadDynamicPlugin(install.getFile(), install.getPluginDescriptor());
                }
              }
              if (onSuccess != null) {
                onSuccess.run();
              }
            }, modalityState);
          }
        }
        finally {
          if (function != null) {
            ApplicationManager.getApplication().invokeLater(() -> function.accept(result[0]), ModalityState.any());
          }
        }
      };

      ProgressManager.getInstance().run(createTask(downloading, inBackground));
      return result[0];
    }
    catch (RuntimeException e) {
      Throwable cause = e.getCause();
      if (cause instanceof IOException) {
        throw (IOException)cause;
      }
      else {
        throw e;
      }
    }
  }
private static boolean downloadPluginsImpl(List<PluginNode> plugins,
                                             Collection<PluginNode> customPlugins,
                                             boolean allowInstallWithoutRestart,
                                             @Nullable Runnable onSuccess,
                                             com.intellij.ide.plugins.PluginEnabler pluginEnabler,
                                             @Nullable Consumer<Boolean> function,
                                             ModalityState modalityState,
                                             boolean inBackground)