Skip to content

Commit

Permalink
Fix configuration of aliased plugins
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mizdebsk committed Mar 16, 2018
1 parent 68d0731 commit 0168fb6
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*-
* 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 );
}
}
}

0 comments on commit 0168fb6

Please sign in to comment.