Search in sources :

Example 1 with IdeaPlugin

use of org.jetbrains.idea.devkit.dom.IdeaPlugin in project intellij-community by JetBrains.

the class PrepareToDeployAction method collectJpsPluginModules.

@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<>();
    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;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Module(com.intellij.openapi.module.Module) Extensions(org.jetbrains.idea.devkit.dom.Extensions) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IdeaPlugin

use of org.jetbrains.idea.devkit.dom.IdeaPlugin in project intellij-community by JetBrains.

the class RegistrationCheckerUtil method checkModule.

@Nullable
private static Set<PsiClass> checkModule(Module module, PsiClass psiClass, @Nullable Set<PsiClass> types, boolean includeActions) {
    final XmlFile pluginXml = PluginModuleType.getPluginXml(module);
    if (pluginXml == null)
        return null;
    final DomFileElement<IdeaPlugin> fileElement = DescriptorUtil.getIdeaPlugin(pluginXml);
    if (fileElement == null)
        return null;
    final String qualifiedName = psiClass.getQualifiedName();
    if (qualifiedName != null) {
        final RegistrationTypeFinder finder = new RegistrationTypeFinder(psiClass, types);
        // "main" plugin.xml
        processPluginXml(pluginXml, finder, includeActions);
        // <depends> plugin.xml files
        for (Dependency dependency : fileElement.getRootElement().getDependencies()) {
            final GenericAttributeValue<PathReference> configFileAttribute = dependency.getConfigFile();
            if (!DomUtil.hasXml(configFileAttribute))
                continue;
            final PathReference configFile = configFileAttribute.getValue();
            if (configFile != null) {
                final PsiElement resolve = configFile.resolve();
                if (!(resolve instanceof XmlFile))
                    continue;
                final XmlFile depPluginXml = (XmlFile) resolve;
                if (DescriptorUtil.isPluginXml(depPluginXml)) {
                    processPluginXml(depPluginXml, finder, includeActions);
                }
            }
        }
        types = finder.getTypes();
    }
    return types;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) XmlFile(com.intellij.psi.xml.XmlFile) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Dependency(org.jetbrains.idea.devkit.dom.Dependency) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with IdeaPlugin

use of org.jetbrains.idea.devkit.dom.IdeaPlugin in project intellij-community by JetBrains.

the class ExtensionNsConverter method getVariants.

@NotNull
public Collection<? extends IdeaPlugin> getVariants(ConvertContext context) {
    final IdeaPlugin ideaPlugin = context.getInvocationElement().getParentOfType(IdeaPlugin.class, true);
    if (ideaPlugin == null)
        return Collections.emptyList();
    final Collection<String> dependencies = ExtensionDomExtender.getDependencies(ideaPlugin);
    final List<IdeaPlugin> depPlugins = new ArrayList<>();
    final Set<String> depPluginsIds = new HashSet<>();
    for (IdeaPlugin plugin : IdeaPluginConverter.getAllPlugins(context.getProject())) {
        final String value = plugin.getPluginId();
        if (value != null && dependencies.contains(value) && !depPluginsIds.contains(value)) {
            depPlugins.add(plugin);
            depPluginsIds.add(value);
        }
    }
    return depPlugins;
}
Also used : IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with IdeaPlugin

use of org.jetbrains.idea.devkit.dom.IdeaPlugin in project intellij-community by JetBrains.

the class PluginDescriptorChooser method show.

public static void show(final Project project, final Editor editor, final PsiFile file, final Consumer<DomFileElement<IdeaPlugin>> consumer) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    assert module != null;
    List<DomFileElement<IdeaPlugin>> elements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, module.getModuleWithDependentsScope());
    elements = ContainerUtil.filter(elements, element -> {
        VirtualFile virtualFile = element.getFile().getVirtualFile();
        return virtualFile != null && ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile);
    });
    elements = findAppropriateIntelliJModule(module.getName(), elements);
    if (elements.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, "Cannot find plugin descriptor");
        return;
    }
    if (elements.size() == 1) {
        consumer.consume(elements.get(0));
        return;
    }
    final BaseListPopupStep<PluginDescriptorCandidate> popupStep = new BaseListPopupStep<PluginDescriptorCandidate>("Choose Plugin Descriptor", createCandidates(module, elements)) {

        @Override
        public boolean isSpeedSearchEnabled() {
            return true;
        }

        @Override
        public Icon getIconFor(PluginDescriptorCandidate candidate) {
            return candidate.getIcon();
        }

        @NotNull
        @Override
        public String getTextFor(PluginDescriptorCandidate candidate) {
            return candidate.getText();
        }

        @Nullable
        @Override
        public ListSeparator getSeparatorAbove(PluginDescriptorCandidate candidate) {
            final String separatorText = candidate.getSeparatorText();
            if (separatorText != null) {
                return new ListSeparator(separatorText);
            }
            return null;
        }

        @Override
        public PopupStep onChosen(PluginDescriptorCandidate selectedValue, boolean finalChoice) {
            consumer.consume(selectedValue.myDomFileElement);
            return FINAL_CHOICE;
        }
    };
    JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
}
Also used : IncludedXmlTag(com.intellij.xml.util.IncludedXmlTag) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ContainerUtil(com.intellij.util.containers.ContainerUtil) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Comparing(com.intellij.openapi.util.Comparing) Extensions(org.jetbrains.idea.devkit.dom.Extensions) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) EmptyIcon(com.intellij.util.ui.EmptyIcon) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) DomFileElement(com.intellij.util.xml.DomFileElement) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) ModulesAlphaComparator(com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator) List(java.util.List) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) DomService(com.intellij.util.xml.DomService) Function(com.intellij.util.Function) PopupStep(com.intellij.openapi.ui.popup.PopupStep) HintManager(com.intellij.codeInsight.hint.HintManager) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) DomFileElement(com.intellij.util.xml.DomFileElement) Module(com.intellij.openapi.module.Module)

Example 5 with IdeaPlugin

use of org.jetbrains.idea.devkit.dom.IdeaPlugin in project intellij-community by JetBrains.

the class PluginDescriptorChooser method createCandidates.

private static List<PluginDescriptorCandidate> createCandidates(final Module currentModule, List<DomFileElement<IdeaPlugin>> elements) {
    ModuleGrouper grouper = ModuleGrouper.instanceFor(currentModule.getProject());
    final List<String> groupPath = grouper.getGroupPath(currentModule);
    elements.sort((o1, o2) -> {
        // current module = first group
        final Module module1 = o1.getModule();
        final Module module2 = o2.getModule();
        if (currentModule.equals(module1))
            return -1;
        if (currentModule.equals(module2))
            return 1;
        if (module1 != null && module2 != null) {
            int groupComparison = Comparing.compare(groupMatchLevel(groupPath, grouper.getGroupPath(module2)), groupMatchLevel(groupPath, grouper.getGroupPath(module1)));
            if (groupComparison != 0) {
                return groupComparison;
            }
        }
        return ModulesAlphaComparator.INSTANCE.compare(module1, module2);
    });
    elements.sort((o1, o2) -> {
        if (!Comparing.equal(o1.getModule(), o2.getModule()))
            return 0;
        String pluginId1 = o1.getRootElement().getPluginId();
        String pluginId2 = o2.getRootElement().getPluginId();
        if (pluginId1 == null && pluginId2 == null) {
            return o1.getFile().getName().compareTo(o2.getFile().getName());
        }
        if (pluginId1 == null)
            return 1;
        if (pluginId2 == null)
            return -1;
        return Comparing.compare(pluginId1, pluginId2);
    });
    return ContainerUtil.map(elements, new Function<DomFileElement<IdeaPlugin>, PluginDescriptorCandidate>() {

        private Module myLastModule = currentModule;

        @Override
        public PluginDescriptorCandidate fun(DomFileElement<IdeaPlugin> element) {
            final Module module = element.getModule();
            boolean startsNewGroup = !myLastModule.equals(module);
            myLastModule = module;
            return new PluginDescriptorCandidate(element, startsNewGroup);
        }
    });
}
Also used : ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) DomFileElement(com.intellij.util.xml.DomFileElement) Module(com.intellij.openapi.module.Module)

Aggregations

IdeaPlugin (org.jetbrains.idea.devkit.dom.IdeaPlugin)9 NotNull (org.jetbrains.annotations.NotNull)5 Module (com.intellij.openapi.module.Module)3 XmlFile (com.intellij.psi.xml.XmlFile)3 Nullable (org.jetbrains.annotations.Nullable)3 Extensions (org.jetbrains.idea.devkit.dom.Extensions)3 ModuleGrouper (com.intellij.openapi.module.ModuleGrouper)2 DomFileElement (com.intellij.util.xml.DomFileElement)2 IncludedXmlTag (com.intellij.xml.util.IncludedXmlTag)2 HintManager (com.intellij.codeInsight.hint.HintManager)1 AllIcons (com.intellij.icons.AllIcons)1 Editor (com.intellij.openapi.editor.Editor)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 PathReference (com.intellij.openapi.paths.PathReference)1 Project (com.intellij.openapi.project.Project)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 ModulesAlphaComparator (com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1 ListSeparator (com.intellij.openapi.ui.popup.ListSeparator)1 PopupStep (com.intellij.openapi.ui.popup.PopupStep)1