Search in sources :

Example 1 with MavenDomPluginExecution

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

the class MavenPluginConfigurationDomExtender method collectParameters.

private static Collection<ParameterData> collectParameters(MavenDomPluginModel pluginModel, MavenDomConfiguration config) {
    List<String> selectedGoals = null;
    MavenDomPluginExecution executionElement = config.getParentOfType(MavenDomPluginExecution.class, false);
    if (executionElement != null) {
        selectedGoals = new ArrayList<>();
        String id = executionElement.getId().getStringValue();
        String defaultPrefix = "default-";
        if (id != null && id.startsWith(defaultPrefix)) {
            String goal = id.substring(defaultPrefix.length());
            if (!StringUtil.isEmptyOrSpaces(goal))
                selectedGoals.add(goal);
        }
        for (GenericDomValue<String> goal : executionElement.getGoals().getGoals()) {
            selectedGoals.add(goal.getStringValue());
        }
    }
    Map<String, ParameterData> namesWithParameters = new THashMap<>();
    for (MavenDomMojo eachMojo : pluginModel.getMojos().getMojos()) {
        String goal = eachMojo.getGoal().getStringValue();
        if (goal == null)
            continue;
        if (selectedGoals == null || selectedGoals.contains(goal)) {
            for (MavenDomParameter eachParameter : eachMojo.getParameters().getParameters()) {
                if (eachParameter.getEditable().getValue() == Boolean.FALSE)
                    continue;
                String name = eachParameter.getName().getStringValue();
                if (name == null)
                    continue;
                ParameterData data = new ParameterData(eachParameter);
                fillParameterData(name, data, eachMojo);
                ParameterData oldParameter = namesWithParameters.get(name);
                if (oldParameter == null || hasMorePriority(data, oldParameter, executionElement != null)) {
                    namesWithParameters.put(name, data);
                }
            }
        }
    }
    return namesWithParameters.values();
}
Also used : MavenDomPluginExecution(org.jetbrains.idea.maven.dom.model.MavenDomPluginExecution) THashMap(gnu.trove.THashMap) MavenDomMojo(org.jetbrains.idea.maven.dom.plugin.MavenDomMojo) MavenDomParameter(org.jetbrains.idea.maven.dom.plugin.MavenDomParameter)

Example 2 with MavenDomPluginExecution

use of org.jetbrains.idea.maven.dom.model.MavenDomPluginExecution 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

MavenDomPluginExecution (org.jetbrains.idea.maven.dom.model.MavenDomPluginExecution)2 SmartList (com.intellij.util.SmartList)1 DomElement (com.intellij.util.xml.DomElement)1 THashMap (gnu.trove.THashMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 MavenDomGoal (org.jetbrains.idea.maven.dom.model.MavenDomGoal)1 MavenDomPlugin (org.jetbrains.idea.maven.dom.model.MavenDomPlugin)1 MavenDomMojo (org.jetbrains.idea.maven.dom.plugin.MavenDomMojo)1 MavenDomParameter (org.jetbrains.idea.maven.dom.plugin.MavenDomParameter)1