{
List<PluginExecution> executions = new ArrayList<PluginExecution>();
// Create a list of dominant executions, with the configurations merged with recessive if needed
for (Map.Entry<String, PluginExecution> entry : dominant.entrySet())
{
PluginExecution pluginExecution = entry.getValue();
PluginExecution mergedPluginExecution = new PluginExecution();
mergedPluginExecution.setId(pluginExecution.getId());
// Phase
if (Strings.isNullOrEmpty(pluginExecution.getPhase()) && recessive.containsKey(entry.getKey()))
{
mergedPluginExecution.setPhase(recessive.get(entry.getKey()).getPhase());
}
else
{
mergedPluginExecution.setPhase(pluginExecution.getPhase());
}
// Goals
Map<String, Boolean> hasGoals = new HashMap<String, Boolean>();
for (String goal : pluginExecution.getGoals())
{
mergedPluginExecution.addGoal(goal);
hasGoals.put(goal, new Boolean(true));
}
if (recessive.containsKey(entry.getKey()))
{
for (String goal : recessive.get(entry.getKey()).getGoals())
{
if (!hasGoals.containsKey(goal))
{
mergedPluginExecution.addGoal(goal);
}
}
}
// Configurations
if (pluginExecution.getConfiguration() != null)
{
if (recessive.containsKey(entry.getKey())
&& recessive.get(entry.getKey()).getConfiguration() != null)
{
// Merge configurations
Xpp3Dom mergedDomConfig = Xpp3Dom.mergeXpp3Dom((Xpp3Dom) pluginExecution.getConfiguration(),
(Xpp3Dom) recessive.get(entry.getKey()).getConfiguration());
mergedPluginExecution.setConfiguration(mergedDomConfig);
}
else
{
// Keep master config
mergedPluginExecution.setConfiguration(pluginExecution.getConfiguration());
}
}
executions.add(mergedPluginExecution);
}
// Add the executions of the recessive that are not defined in dominant
for (Map.Entry<String, PluginExecution> entry : recessive.entrySet())
{
if (!dominant.containsKey(entry.getKey()))
{
PluginExecution pluginExecution = entry.getValue();
PluginExecution mergedPluginExecution = new PluginExecution();
mergedPluginExecution.setId(pluginExecution.getId());
mergedPluginExecution.setPhase(pluginExecution.getPhase());
// Goals
for (String goal : pluginExecution.getGoals())
{
mergedPluginExecution.addGoal(goal);
}
// Configuration
if (pluginExecution.getConfiguration() != null)
{
mergedPluginExecution.setConfiguration(pluginExecution.getConfiguration());
}
executions.add(mergedPluginExecution);
}
}
return executions;