class DefaultPluginConfigurationExpander implements PluginConfigurationExpander {

    @Override
    public Model expandPluginConfiguration(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
        Build build = model.getBuild();
        if (build != null) {
            build = build.withPlugins(expandPlugin(build.getPlugins()));
            PluginManagement pluginManagement = build.getPluginManagement();
            if (pluginManagement != null) {
                build = build.withPluginManagement(
                        pluginManagement.withPlugins(expandPlugin(pluginManagement.getPlugins())));
            }
            model = model.withBuild(build);
        }
        Reporting reporting = model.getReporting();
        if (reporting != null) {
            expandReport(reporting.getPlugins());
        }
        return model.withBuild(build);
    }

    private List<Plugin> expandPlugin(List<Plugin> oldPlugins) {
        return map(oldPlugins, plugin -> {
            XmlNode pluginConfiguration = plugin.getConfiguration();
            if (pluginConfiguration != null) {
                return plugin.withExecutions(map(
                        plugin.getExecutions(),
                        execution -> execution.withConfiguration(
                                XmlNode.merge(execution.getConfiguration(), pluginConfiguration))));
            } else {
                return plugin;
            }
        });
    }

    private List<ReportPlugin> expandReport(List<ReportPlugin> oldPlugins) {
        return map(oldPlugins, plugin -> {
            XmlNode pluginConfiguration = plugin.getConfiguration();
            if (pluginConfiguration != null) {
                return plugin.withReportSets(map(
                        plugin.getReportSets(),
                        report -> report.withConfiguration(
                                XmlNode.merge(report.getConfiguration(), pluginConfiguration))));
            } else {
                return plugin;
            }
        });
    }

    static <T> List<T> map(List<T> list, Function<T, T> mapper) {<FILL_FUNCTION_BODY>}
}

        List<T> newList = list;
        for (int i = 0; i < newList.size(); i++) {
            T oldT = newList.get(i);
            T newT = mapper.apply(oldT);
            if (newT != oldT) {
                if (newList == list) {
                    newList = new ArrayList<>(list);
                }
                newList.set(i, newT);
            }
        }
        return newList;
    
<no_super_class>