Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wildcard option for direct goal execution id from command line #357

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.lifecycle.MojoExecutionConfigurator;
import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoExecution;
Expand Down Expand Up @@ -153,6 +155,8 @@ private void setupMojoExecutions( MavenSession session, MavenProject project, Li
MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
{
final List<MojoExecution> setupMojoExecutions = new ArrayList<>();

for ( MojoExecution mojoExecution : mojoExecutions )
{
setupMojoExecution( session, project, mojoExecution );
Expand Down Expand Up @@ -206,12 +210,38 @@ public List<MojoExecution> calculateMojoExecutions( MavenSession session, MavenP
executionId = pluginGoal.substring( executionIdx + 1 );
}

MojoDescriptor mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor( pluginGoal, session, project );
final MojoDescriptor mojoDescriptor =
mojoDescriptorCreator.getMojoDescriptor( pluginGoal, session, project );

if ( executionId.equals( "*" ) )
{
final String g = mojoDescriptor.getPluginDescriptor().getGroupId();
final String a = mojoDescriptor.getPluginDescriptor().getArtifactId();

Plugin plugin = findPlugin( g, a, project.getBuildPlugins() );

if ( plugin == null && project.getPluginManagement() != null )
{
plugin = findPlugin( g, a, project.getPluginManagement().getPlugins() );
}

for ( final PluginExecution execution : plugin.getExecutions() )
{
final MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId(),
MojoExecution.Source.CLI );

MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, executionId,
MojoExecution.Source.CLI );
mojoExecutions.add( mojoExecution );
}

mojoExecutions.add( mojoExecution );
}
else
{

final MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, executionId,
MojoExecution.Source.CLI );

mojoExecutions.add( mojoExecution );
}
}
else if ( task instanceof LifecycleTask )
{
Expand All @@ -233,6 +263,19 @@ else if ( task instanceof LifecycleTask )
return mojoExecutions;
}

private Plugin findPlugin( final String groupId, final String artifactId, final Collection<Plugin> plugins )
{
for ( final Plugin plugin : plugins )
{
if ( artifactId.equals( plugin.getArtifactId() ) && groupId.equals( plugin.getGroupId() ) )
{
return plugin;
}
}

return null;
}

private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSession session, MavenProject project,
String lifecyclePhase )
throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException,
Expand Down