/*-
 * Copyright (c) 2018 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fedoraproject.xmvn.connector.aether;

import org.apache.maven.lifecycle.MojoExecutionConfigurator;
import org.apache.maven.lifecycle.internal.DefaultMojoExecutionConfigurator;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;

/**
 * @author Mikolaj Izdebski
 */
@Component( role = MojoExecutionConfigurator.class )
public class XMvnMojoExecutionConfigurator
    extends DefaultMojoExecutionConfigurator
{
    @Override
    public void configure( MavenProject project, MojoExecution execution, boolean allowPluginLevelConfig )
    {
        PluginDescriptor originalPluginDescriptor = execution.getMojoDescriptor().getPluginDescriptor();

        PluginDescriptor aliasedPluginDescriptor = originalPluginDescriptor.clone();
        aliasedPluginDescriptor.setGroupId( execution.getPlugin().getGroupId() );
        aliasedPluginDescriptor.setArtifactId( execution.getPlugin().getArtifactId() );

        try
        {
            execution.getMojoDescriptor().setPluginDescriptor( aliasedPluginDescriptor );
            super.configure( project, execution, allowPluginLevelConfig );
        }
        finally
        {
            execution.getMojoDescriptor().setPluginDescriptor( originalPluginDescriptor );
        }
    }
}

Fix configuration of aliased plugins
Fix configuration of aliased plugins

Normally Maven tries to look up plugin configuration using plugin
coordinates taken from plugin descriptor.  This works with pure Maven
as plugin descriptor always matches <plugin> reference in POM.
However in XMvn they can differ when plugin artifact is resolved
throug artifact alias, so XMvn should force use of coordinates
specified in <plugin> in POM.
