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;
}
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;
}
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;
}
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);
}
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);
}
});
}
Aggregations