mirror of https://github.com/apache/maven.git
o allowing the selective execution of a set of mojos inside a plugins by
specifying a <goals/> section inside a <plugin/> configuration. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163539 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6b85885255
commit
e6d8aeb6c0
|
@ -152,18 +152,24 @@ public class DefaultMaven
|
||||||
|
|
||||||
if ( project.getModules() != null && !project.getModules().isEmpty() )
|
if ( project.getModules() != null && !project.getModules().isEmpty() )
|
||||||
{
|
{
|
||||||
String includes = StringUtils.join( project.getModules().iterator(), "/pom.xml," ) +
|
String includes = StringUtils.join( project.getModules().iterator(), "/pom.xml," ) + "/pom.xml";
|
||||||
"/pom.xml";
|
|
||||||
File baseDir = project.getFile().getParentFile();
|
File baseDir = project.getFile().getParentFile();
|
||||||
|
|
||||||
MavenExecutionRequest reactorRequest = new DefaultMavenExecutionRequest(
|
MavenExecutionRequest reactorRequest = new DefaultMavenExecutionRequest(
|
||||||
request.getLocalRepository(), request.getUserModel(), request.getEventDispatcher(),
|
request.getLocalRepository(),
|
||||||
request.getGoals(), FileUtils.getFiles( baseDir, includes, null ), baseDir.getPath() );
|
request.getUserModel(),
|
||||||
|
request.getEventDispatcher(),
|
||||||
|
request.getGoals(),
|
||||||
|
FileUtils.getFiles( baseDir, includes, null ),
|
||||||
|
baseDir.getPath() );
|
||||||
|
|
||||||
MavenExecutionResponse response = execute( reactorRequest );
|
MavenExecutionResponse response = execute( reactorRequest );
|
||||||
|
|
||||||
if ( response != null && response.isExecutionFailure() )
|
if ( response != null && response.isExecutionFailure() )
|
||||||
{
|
{
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !isPom )
|
if ( !isPom )
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.maven.execution.MavenExecutionResponse;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.PluginManagement;
|
import org.apache.maven.model.PluginManagement;
|
||||||
|
import org.apache.maven.model.Goal;
|
||||||
import org.apache.maven.monitor.event.EventDispatcher;
|
import org.apache.maven.monitor.event.EventDispatcher;
|
||||||
import org.apache.maven.monitor.event.MavenEvents;
|
import org.apache.maven.monitor.event.MavenEvents;
|
||||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||||
|
@ -84,27 +85,35 @@ public class DefaultLifecycleExecutor
|
||||||
{
|
{
|
||||||
MavenProject project = session.getProject();
|
MavenProject project = session.getProject();
|
||||||
|
|
||||||
// TODO: should enrich this with the type handler, but for now just
|
// TODO: should enrich this with the type artifactHandler, but for now just
|
||||||
// use "type" as is
|
// use "type" as is
|
||||||
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( project.getPackaging() );
|
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( project.getPackaging() );
|
||||||
|
|
||||||
if ( handler != null )
|
if ( artifactHandler != null )
|
||||||
{
|
{
|
||||||
// TODO: perhaps each type should define their own lifecycle
|
// TODO: perhaps each type should define their own lifecycle
|
||||||
// completely, using the base as a default?
|
// completely, using the base as a default?
|
||||||
// If so, remove both of these goals from type handler
|
// If so, remove both of these goals from type artifactHandler
|
||||||
if ( handler.packageGoal() != null )
|
if ( artifactHandler.packageGoal() != null )
|
||||||
{
|
{
|
||||||
verifyMojoPhase( handler.packageGoal(), session );
|
verifyMojoPhase( artifactHandler.packageGoal(), session );
|
||||||
}
|
}
|
||||||
if ( handler.additionalPlugin() != null )
|
|
||||||
|
if ( artifactHandler.additionalPlugin() != null )
|
||||||
{
|
{
|
||||||
String additionalPluginGroupId = "maven";
|
String additionalPluginGroupId = "maven";
|
||||||
String additionalPluginArtifactId = "maven-" + handler.additionalPlugin() + "-plugin";
|
|
||||||
|
String additionalPluginArtifactId = "maven-" + artifactHandler.additionalPlugin() + "-plugin";
|
||||||
|
|
||||||
injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId );
|
injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId );
|
||||||
|
|
||||||
processPluginPhases( "maven", "maven-" + handler.additionalPlugin() + "-plugin", session );
|
Plugin plugin = new Plugin();
|
||||||
|
|
||||||
|
plugin.setGroupId( additionalPluginGroupId );
|
||||||
|
|
||||||
|
plugin.setArtifactId( additionalPluginArtifactId );
|
||||||
|
|
||||||
|
processPluginPhases( plugin, session );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,18 +158,22 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId )
|
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId )
|
||||||
{
|
{
|
||||||
PluginManagement mgmt = project.getPluginManagement();
|
PluginManagement pluginManagement = project.getPluginManagement();
|
||||||
if( mgmt != null )
|
|
||||||
|
if ( pluginManagement != null )
|
||||||
{
|
{
|
||||||
List pluginList = mgmt.getPlugins();
|
List pluginList = pluginManagement.getPlugins();
|
||||||
|
|
||||||
Plugin handlerPlugin = null;
|
Plugin handlerPlugin = null;
|
||||||
|
|
||||||
for ( Iterator it = pluginList.iterator(); it.hasNext(); )
|
for ( Iterator it = pluginList.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Plugin plugin = (Plugin) it.next();
|
Plugin plugin = (Plugin) it.next();
|
||||||
|
|
||||||
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
|
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
|
||||||
{
|
{
|
||||||
handlerPlugin = plugin;
|
handlerPlugin = plugin;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,33 +193,78 @@ public class DefaultLifecycleExecutor
|
||||||
{
|
{
|
||||||
Plugin plugin = (Plugin) i.next();
|
Plugin plugin = (Plugin) i.next();
|
||||||
|
|
||||||
// TODO: should this flag be used in verifyPlugin, completely disabling the plugin?
|
processPluginPhases( plugin, mavenSession );
|
||||||
if ( Boolean.TRUE != plugin.isDisabled() )
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take each mojo contained with a plugin, look to see whether it contributes to a
|
||||||
|
* phase in the lifecycle and if it does place it at the end of the list of goals
|
||||||
|
* to execute for that given phase.
|
||||||
|
*
|
||||||
|
* @param mavenSession
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
// TODO: don't throw Exception
|
||||||
|
private void processPluginPhases( Plugin plugin, MavenSession mavenSession )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String groupId = plugin.getGroupId();
|
||||||
|
|
||||||
|
String artifactId = plugin.getArtifactId();
|
||||||
|
|
||||||
|
pluginManager.verifyPlugin( groupId, artifactId, mavenSession );
|
||||||
|
|
||||||
|
PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor( groupId, artifactId );
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Look to see if the plugin configuration specifies particular mojos
|
||||||
|
// within the plugin. If this is the case then simply configure the
|
||||||
|
// mojos the user has specified and ignore the rest.
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
if ( plugin.getGoals().size() > 0 )
|
||||||
|
{
|
||||||
|
String pluginId = pluginDescriptor.getArtifactId();
|
||||||
|
|
||||||
|
pluginId = pluginId.substring( 6 ).substring( 0, 7 );
|
||||||
|
|
||||||
|
for ( Iterator i = plugin.getGoals().iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
processPluginPhases( plugin.getGroupId(), plugin.getArtifactId(), mavenSession );
|
Goal goal = (Goal) i.next();
|
||||||
|
|
||||||
|
configureMojo( pluginManager.getMojoDescriptor( pluginId + ":" + goal.getId() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
|
||||||
|
{
|
||||||
|
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
|
||||||
|
|
||||||
|
configureMojo( mojoDescriptor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: don't throw Exception
|
/**
|
||||||
private void processPluginPhases( String groupId, String artifactId, MavenSession mavenSession )
|
* Take a look at a mojo contained within a plugin, look to see whether it contributes to a
|
||||||
|
* phase in the lifecycle and if it does place it at the end of the list of goals
|
||||||
|
* to execute for the stated phase.
|
||||||
|
*
|
||||||
|
* @param mojoDescriptor
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private void configureMojo( MojoDescriptor mojoDescriptor )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
pluginManager.verifyPlugin( groupId, artifactId, mavenSession );
|
if ( mojoDescriptor.getPhase() != null )
|
||||||
PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor( groupId, artifactId );
|
|
||||||
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
|
|
||||||
{
|
{
|
||||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
|
Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
|
||||||
|
|
||||||
// TODO: check if the goal exists in the configuration and is
|
phase.getGoals().add( mojoDescriptor.getId() );
|
||||||
// disabled
|
|
||||||
if ( mojoDescriptor.getPhase() != null )
|
|
||||||
{
|
|
||||||
Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
|
|
||||||
phase.getGoals().add( mojoDescriptor.getId() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processGoalChain( String task, MavenSession session )
|
private void processGoalChain( String task, MavenSession session )
|
||||||
|
@ -242,10 +300,13 @@ public class DefaultLifecycleExecutor
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
|
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
|
||||||
|
|
||||||
if ( mojoDescriptor == null )
|
if ( mojoDescriptor == null )
|
||||||
{
|
{
|
||||||
pluginManager.verifyPluginForGoal( task, session );
|
pluginManager.verifyPluginForGoal( task, session );
|
||||||
|
|
||||||
mojoDescriptor = pluginManager.getMojoDescriptor( task );
|
mojoDescriptor = pluginManager.getMojoDescriptor( task );
|
||||||
|
|
||||||
if ( mojoDescriptor == null )
|
if ( mojoDescriptor == null )
|
||||||
{
|
{
|
||||||
throw new LifecycleExecutionException( "Required goal not found: " + task );
|
throw new LifecycleExecutionException( "Required goal not found: " + task );
|
||||||
|
@ -254,6 +315,7 @@ public class DefaultLifecycleExecutor
|
||||||
if ( mojoDescriptor.getPhase() != null )
|
if ( mojoDescriptor.getPhase() != null )
|
||||||
{
|
{
|
||||||
Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
|
Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
|
||||||
|
|
||||||
phase.getGoals().add( task );
|
phase.getGoals().add( task );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,6 +351,7 @@ public class DefaultLifecycleExecutor
|
||||||
if ( pluginResponse.isExecutionFailure() )
|
if ( pluginResponse.isExecutionFailure() )
|
||||||
{
|
{
|
||||||
response.setExecutionFailure( goal, pluginResponse.getFailureResponse() );
|
response.setExecutionFailure( goal, pluginResponse.getFailureResponse() );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -444,7 +444,8 @@ public class DefaultPluginManager
|
||||||
// Mojo Parameter Handling
|
// Mojo Parameter Handling
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public static Map createParameters( MojoDescriptor goal, MavenSession session ) throws PluginConfigurationException
|
public static Map createParameters( MojoDescriptor goal, MavenSession session )
|
||||||
|
throws PluginConfigurationException
|
||||||
{
|
{
|
||||||
Map map = null;
|
Map map = null;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.apache.maven.project;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2005 The Apache Software Foundation.
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
|
Loading…
Reference in New Issue