@NotNull
  private static Map<Module, String> collectJpsPluginModules(@NotNull Module module) {
    XmlFile pluginXml = PluginModuleType.getPluginXml(module);
    if (pluginXml == null) return Collections.emptyMap();

    DomFileElement<IdeaPlugin> fileElement =
        DomManager.getDomManager(module.getProject()).getFileElement(pluginXml, IdeaPlugin.class);
    if (fileElement == null) return Collections.emptyMap();

    Map<Module, String> jpsPluginToOutputPath = new HashMap<Module, String>();
    IdeaPlugin plugin = fileElement.getRootElement();
    List<Extensions> extensions = plugin.getExtensions();
    for (Extensions extensionGroup : extensions) {
      XmlTag extensionsTag = extensionGroup.getXmlTag();
      String defaultExtensionNs = extensionsTag.getAttributeValue("defaultExtensionNs");
      for (XmlTag tag : extensionsTag.getSubTags()) {
        String name = tag.getLocalName();
        String qualifiedName = defaultExtensionNs != null ? defaultExtensionNs + "." + name : name;
        if (CompileServerPlugin.EP_NAME.getName().equals(qualifiedName)) {
          String classpath = tag.getAttributeValue("classpath");
          if (classpath != null) {
            for (String path : StringUtil.split(classpath, ";")) {
              String moduleName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
              Module jpsModule =
                  ModuleManager.getInstance(module.getProject()).findModuleByName(moduleName);
              if (jpsModule != null) {
                jpsPluginToOutputPath.put(jpsModule, path);
              }
            }
          }
        }
      }
    }
    return jpsPluginToOutputPath;
  }
 public void update(AnActionEvent e) {
   final Module module = LangDataKeys.MODULE.getData(e.getDataContext());
   boolean enabled = module != null && PluginModuleType.isOfType(module);
   e.getPresentation().setVisible(enabled);
   e.getPresentation().setEnabled(enabled);
   if (enabled) {
     e.getPresentation().setText(DevKitBundle.message("prepare.for.deployment", module.getName()));
   }
 }
  @Override
  public void patchJavaParameters(@Nullable final Module module, JavaParameters javaParameters) {
    if (module != null
        && PsiUtil.isIdeaProject(module.getProject())
        && !javaParameters.getVMParametersList().hasParameter(SYSTEM_CL_PROPERTY)) {
      final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(module.getProject());
      final String qualifiedName = UrlClassLoader.class.getName();
      final PsiClass urlLoaderClass =
          ApplicationManager.getApplication()
              .runReadAction(
                  new Computable<PsiClass>() {
                    @Override
                    public PsiClass compute() {
                      return psiFacade.findClass(
                          qualifiedName,
                          GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
                    }
                  });
      if (urlLoaderClass != null) {
        javaParameters.getVMParametersList().addProperty(SYSTEM_CL_PROPERTY, qualifiedName);
      }
    }

    Sdk jdk = javaParameters.getJdk();
    jdk = IdeaJdk.findIdeaJdk(jdk);
    if (jdk == null) return;

    String libPath = jdk.getHomePath() + File.separator + "lib";

    final ParametersList vm = javaParameters.getVMParametersList();
    vm.add("-Xbootclasspath/a:" + libPath + File.separator + "boot.jar");
    if (!vm.hasProperty("idea.load.plugins.id")
        && module != null
        && PluginModuleType.isOfType(module)) {
      final String id = DescriptorUtil.getPluginId(module);
      if (id != null) {
        vm.defineProperty("idea.load.plugins.id", id);
      }
    }

    final File sandboxHome = getSandboxPath(jdk);
    if (sandboxHome != null) {
      if (!vm.hasProperty("idea.home.path")) {
        File homeDir = new File(sandboxHome, "test");
        FileUtil.createDirectory(homeDir);
        vm.defineProperty("idea.home.path", homeDir.getAbsolutePath());
      }
      if (!vm.hasProperty("idea.plugins.path")) {
        vm.defineProperty("idea.plugins.path", new File(sandboxHome, "plugins").getAbsolutePath());
      }
    }

    javaParameters.getClassPath().addFirst(libPath + File.separator + "idea.jar");
    javaParameters.getClassPath().addFirst(libPath + File.separator + "resources.jar");
    javaParameters.getClassPath().addFirst(((JavaSdkType) jdk.getSdkType()).getToolsPath(jdk));
  }
 public void actionPerformed(final AnActionEvent e) {
   final Module module = LangDataKeys.MODULE.getData(e.getDataContext());
   if (module != null && PluginModuleType.isOfType(module)) {
     doPrepare(Arrays.asList(module), CommonDataKeys.PROJECT.getData(e.getDataContext()));
   }
 }