Search in sources :

Example 1 with MavenDomPlugin

use of org.jetbrains.idea.maven.dom.model.MavenDomPlugin in project intellij-community by JetBrains.

the class MavenDuplicatePluginInspection method checkFileElement.

@Override
public void checkFileElement(DomFileElement<MavenDomProjectModel> domFileElement, DomElementAnnotationHolder holder) {
    MavenDomProjectModel projectModel = domFileElement.getRootElement();
    MultiMap<Pair<String, String>, MavenDomPlugin> duplicates = MultiMap.createSet();
    for (MavenDomPlugin plugin : projectModel.getBuild().getPlugins().getPlugins()) {
        String groupId = plugin.getGroupId().getStringValue();
        String artifactId = plugin.getArtifactId().getStringValue();
        if (StringUtil.isEmptyOrSpaces(artifactId))
            continue;
        if ("".equals(groupId) || "org.apache.maven.plugins".equals(groupId) || "org.codehaus.mojo".equals(groupId)) {
            groupId = null;
        }
        duplicates.putValue(Pair.create(groupId, artifactId), plugin);
    }
    for (Map.Entry<Pair<String, String>, Collection<MavenDomPlugin>> entry : duplicates.entrySet()) {
        Collection<MavenDomPlugin> set = entry.getValue();
        if (set.size() <= 1)
            continue;
        for (MavenDomPlugin dependency : set) {
            holder.createProblem(dependency, HighlightSeverity.WARNING, "Duplicated plugin declaration");
        }
    }
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenDomPlugin(org.jetbrains.idea.maven.dom.model.MavenDomPlugin) Collection(java.util.Collection) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) Pair(com.intellij.openapi.util.Pair)

Example 2 with MavenDomPlugin

use of org.jetbrains.idea.maven.dom.model.MavenDomPlugin in project intellij-community by JetBrains.

the class MavenVersionCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    if (parameters.getCompletionType() != CompletionType.BASIC)
        return;
    PsiElement element = parameters.getPosition();
    PsiElement xmlText = element.getParent();
    if (!(xmlText instanceof XmlText))
        return;
    PsiElement tagElement = xmlText.getParent();
    if (!(tagElement instanceof XmlTag))
        return;
    XmlTag tag = (XmlTag) tagElement;
    Project project = element.getProject();
    DomElement domElement = DomManager.getDomManager(project).getDomElement(tag);
    if (!(domElement instanceof GenericDomValue))
        return;
    DomElement parent = domElement.getParent();
    if (parent instanceof MavenDomArtifactCoordinates && ((GenericDomValue) domElement).getConverter() instanceof MavenArtifactCoordinatesVersionConverter) {
        MavenDomArtifactCoordinates coordinates = (MavenDomArtifactCoordinates) parent;
        String groupId = coordinates.getGroupId().getStringValue();
        String artifactId = coordinates.getArtifactId().getStringValue();
        if (StringUtil.isEmptyOrSpaces(artifactId))
            return;
        CompletionResultSet newResultSet = result.withRelevanceSorter(CompletionService.getCompletionService().emptySorter().weigh(new LookupElementWeigher("mavenVersionWeigher") {

            @Nullable
            @Override
            public Comparable weigh(@NotNull LookupElement element) {
                return new NegatingComparable(new MavenVersionComparable(element.getLookupString()));
            }
        }));
        MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
        Set<String> versions;
        if (StringUtil.isEmptyOrSpaces(groupId)) {
            if (!(coordinates instanceof MavenDomPlugin))
                return;
            versions = indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[0], artifactId);
            for (int i = 0; i < MavenArtifactUtil.DEFAULT_GROUPS.length; i++) {
                versions = Sets.union(versions, indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[i], artifactId));
            }
        } else {
            versions = indicesManager.getVersions(groupId, artifactId);
        }
        for (String version : versions) {
            newResultSet.addElement(LookupElementBuilder.create(version));
        }
        newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.ReleaseVersionId));
        newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.LatestVersionId));
    }
}
Also used : NegatingComparable(com.intellij.codeInsight.completion.impl.NegatingComparable) MavenProjectIndicesManager(org.jetbrains.idea.maven.indices.MavenProjectIndicesManager) MavenVersionComparable(org.jetbrains.idea.maven.dom.MavenVersionComparable) MavenDomPlugin(org.jetbrains.idea.maven.dom.model.MavenDomPlugin) MavenArtifactCoordinatesVersionConverter(org.jetbrains.idea.maven.dom.converters.MavenArtifactCoordinatesVersionConverter) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DomElement(com.intellij.util.xml.DomElement) LookupElementWeigher(com.intellij.codeInsight.lookup.LookupElementWeigher) XmlText(com.intellij.psi.xml.XmlText) MavenDomArtifactCoordinates(org.jetbrains.idea.maven.dom.model.MavenDomArtifactCoordinates) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Example 3 with MavenDomPlugin

use of org.jetbrains.idea.maven.dom.model.MavenDomPlugin in project intellij-community by JetBrains.

the class MavenPluginDomUtil method getMavenPluginModel.

@Nullable
public static MavenDomPluginModel getMavenPluginModel(DomElement element) {
    Project project = element.getManager().getProject();
    MavenDomPlugin pluginElement = element.getParentOfType(MavenDomPlugin.class, false);
    if (pluginElement == null)
        return null;
    String groupId = pluginElement.getGroupId().getStringValue();
    String artifactId = pluginElement.getArtifactId().getStringValue();
    String version = pluginElement.getVersion().getStringValue();
    return getMavenPluginModel(project, groupId, artifactId, version);
}
Also used : Project(com.intellij.openapi.project.Project) MavenDomPlugin(org.jetbrains.idea.maven.dom.model.MavenDomPlugin) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with MavenDomPlugin

use of org.jetbrains.idea.maven.dom.model.MavenDomPlugin in project intellij-community by JetBrains.

the class MavenPluginDescriptor method processDescriptors.

public static boolean processDescriptors(Processor<MavenPluginDescriptor> processor, MavenDomConfiguration cfg) {
    Map<String, Map<String, Map<String, List<MavenPluginDescriptor>>>> map = getDescriptorsMap();
    DomElement parent = cfg.getParent();
    MavenDomPlugin plugin = DomUtil.getParentOfType(parent, MavenDomPlugin.class, false);
    if (plugin == null)
        return true;
    Map<String, Map<String, List<MavenPluginDescriptor>>> groupMap = map.get(plugin.getArtifactId().getStringValue());
    if (groupMap == null)
        return true;
    Map<String, List<MavenPluginDescriptor>> goalsMap = groupMap.get(plugin.getGroupId().getStringValue());
    if (goalsMap == null)
        return true;
    List<MavenPluginDescriptor> descriptorsForAllGoals = goalsMap.get(null);
    if (descriptorsForAllGoals != null) {
        for (MavenPluginDescriptor descriptor : descriptorsForAllGoals) {
            if (!processor.process(descriptor))
                return false;
        }
    }
    if (parent instanceof MavenDomPluginExecution) {
        for (MavenDomGoal goal : ((MavenDomPluginExecution) parent).getGoals().getGoals()) {
            List<MavenPluginDescriptor> descriptors = goalsMap.get(goal.getStringValue());
            if (descriptors != null) {
                for (MavenPluginDescriptor descriptor : descriptors) {
                    if (!processor.process(descriptor))
                        return false;
                }
            }
        }
    }
    return true;
}
Also used : MavenDomPluginExecution(org.jetbrains.idea.maven.dom.model.MavenDomPluginExecution) DomElement(com.intellij.util.xml.DomElement) MavenDomPlugin(org.jetbrains.idea.maven.dom.model.MavenDomPlugin) List(java.util.List) SmartList(com.intellij.util.SmartList) HashMap(java.util.HashMap) Map(java.util.Map) MavenDomGoal(org.jetbrains.idea.maven.dom.model.MavenDomGoal)

Aggregations

MavenDomPlugin (org.jetbrains.idea.maven.dom.model.MavenDomPlugin)4 Project (com.intellij.openapi.project.Project)2 DomElement (com.intellij.util.xml.DomElement)2 Map (java.util.Map)2 NegatingComparable (com.intellij.codeInsight.completion.impl.NegatingComparable)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementWeigher (com.intellij.codeInsight.lookup.LookupElementWeigher)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlText (com.intellij.psi.xml.XmlText)1 SmartList (com.intellij.util.SmartList)1 MultiMap (com.intellij.util.containers.MultiMap)1 GenericDomValue (com.intellij.util.xml.GenericDomValue)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 MavenVersionComparable (org.jetbrains.idea.maven.dom.MavenVersionComparable)1