// Remove extension as dominant and recessive have the same one
merged.setExtensions(null);
}
// Config
Map<String, String> cfgElmtsRefMap = new HashMap<>();
Configuration mergedConfiguration = merged.getConfig();
if (dominant.getConfig() != null && recessive.getConfig() != null)
{
for (ConfigurationElement e : dominant.getConfig().listConfigurationElements())
{
// FIXME: recursively do a diff of childrens, if any
cfgElmtsRefMap.put(e.getName(), e.toString());
}
for (ConfigurationElement e : recessive.getConfig().listConfigurationElements())
{
if (cfgElmtsRefMap.containsKey(e.getName()))
{
if (Strings.compare(cfgElmtsRefMap.get(e.getName()), e.toString()))
{
// Remove the configuration element as dominant and recessive have the same element
mergedConfiguration.removeConfigurationElement(e.getName());
}
}
}
}
merged.setConfig(mergedConfiguration);
// Executions
Map<String, PluginExecution> dominantExec = new MavenPluginAdapter(dominant).getExecutionsAsMap();
Map<String, PluginExecution> recessiveExec = new MavenPluginAdapter(recessive).getExecutionsAsMap();
Map<String, PluginExecution> mergedExec = merged.getExecutionsAsMap();
if (dominantExec != null && recessiveExec != null)
{
for (Map.Entry<String, PluginExecution> entry : recessiveExec.entrySet())
{
PluginExecution pluginExecutionRecessive = entry.getValue();
PluginExecution pluginExecutionDominant = dominantExec.get(entry.getKey());
if (pluginExecutionRecessive != null && pluginExecutionDominant != null)
{
PluginExecution pluginExecutionMerged = mergedExec.get(entry.getKey());
// Phase
if (Strings.compare(pluginExecutionRecessive.getPhase(), pluginExecutionDominant.getPhase()))
{
// Remove the phase as dominant and recessive are identical
pluginExecutionMerged.setPhase(null);
}
// Goals
Map<String, Boolean> hasGoals = new HashMap<>();
for (String goal : pluginExecutionRecessive.getGoals())
{
hasGoals.put(goal, new Boolean(true));
}
for (String goal : pluginExecutionDominant.getGoals())
{
if (hasGoals.get(goal))
{
// Remove the goal as dominant and recessive have the same goal
pluginExecutionMerged.removeGoal(goal);
}
}
// Configurations
Map<String, String> cfgExecElmtsRefMap = new HashMap<>();
if (pluginExecutionRecessive.getConfiguration() != null
&& pluginExecutionDominant.getConfiguration() != null)
{
Configuration pluginExecutionRecessiveCfg = new ConfigurationImpl(
(Xpp3Dom) pluginExecutionRecessive.getConfiguration());
Configuration pluginExecutionDominantCfg = new ConfigurationImpl(
(Xpp3Dom) pluginExecutionDominant.getConfiguration());
Configuration pluginExecutionMergedCfg = new ConfigurationImpl(
(Xpp3Dom) pluginExecutionMerged.getConfiguration());
for (ConfigurationElement e : pluginExecutionDominantCfg.listConfigurationElements())
{
// FIXME: recursively do a diff of childrens, if any
cfgExecElmtsRefMap.put(e.getName(), e.toString());
}
for (ConfigurationElement e : pluginExecutionRecessiveCfg.listConfigurationElements())
{
if (cfgExecElmtsRefMap.containsKey(e.getName()))
{
if (Strings.compare(cfgExecElmtsRefMap.get(e.getName()), e.toString()))
{
// Remove the execution configuration element as dominant and recessive have the same
// element
pluginExecutionMergedCfg.removeConfigurationElement(e.getName());
}
}
}
if (!pluginExecutionMergedCfg.hasConfigurationElements())
{
pluginExecutionMerged.setConfiguration(null);
}
try
{
pluginExecutionMerged.setConfiguration(Xpp3DomBuilder.build(
new ByteArrayInputStream(pluginExecutionMergedCfg.toString().getBytes()), "UTF-8"));
}
catch (Exception ex)
{
throw new RuntimeException("Exception while parsing configuration", ex);
}