o bootstrap working on my branch with all the changes. i need to pull from trunk and spend a few more hours on adding tests that need to be written that never were. the

guts of the plugin manager and lifecycle executor internals are not really covered much.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@751989 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-10 06:07:02 +00:00
parent 191aded423
commit 39af2b8f7e
8 changed files with 120 additions and 120 deletions

View File

@ -171,7 +171,6 @@ END SNIPPET: ant-bootstrap -->
</macrodef>
<modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/>
<modello file="maven-lifecycle/src/main/mdo/maven-lifecycle.mdo"/>
<modello file="maven-plugin-api/src/main/mdo/lifecycle.mdo"/>
<modello file="maven-project/src/main/mdo/profiles.mdo"/>
<modello file="maven-core/src/main/mdo/settings.mdo"/>

View File

@ -36,6 +36,7 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.Lifecycle;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.TaskValidationResult;
@ -80,6 +81,11 @@ public class DefaultMaven
@Requirement
private Logger logger;
public List<Lifecycle> getLifecyclePhases()
{
return lifecycleExecutor.getLifecyclePhases();
}
// ----------------------------------------------------------------------
// Project execution
// ----------------------------------------------------------------------

View File

@ -19,9 +19,12 @@ package org.apache.maven;
* under the License.
*/
import java.util.List;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.Lifecycle;
/**
* @author Jason van Zyl
@ -40,4 +43,6 @@ public interface Maven
MavenExecutionResult execute( MavenExecutionRequest request );
ReactorManager createReactorManager( MavenExecutionRequest request, MavenExecutionResult result );
List<Lifecycle> getLifecyclePhases();
}

View File

@ -59,6 +59,7 @@ import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@ -70,10 +71,11 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
*/
@Component(role = LifecycleExecutor.class)
public class DefaultLifecycleExecutor
extends AbstractLogEnabled
implements LifecycleExecutor
{
@Requirement
private Logger logger;
//@Requirement
//private getLogger() getLogger();
@Requirement
private PluginManager pluginManager;
@ -84,10 +86,11 @@ public class DefaultLifecycleExecutor
private Map phaseToLifecycleMap;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public List<Lifecycle> getLifecyclePhases()
{
return lifecycles;
}
public static boolean isValidPhaseName( final String phaseName )
{
LifecycleBindings test = new LifecycleBindings();
@ -231,9 +234,9 @@ public class DefaultLifecycleExecutor
{
line();
logger.info( "Building " + rootProject.getName() );
getLogger().info( "Building " + rootProject.getName() );
logger.info( " " + segment );
getLogger().info( " " + segment );
line();
@ -273,11 +276,11 @@ public class DefaultLifecycleExecutor
{
line();
logger.info( "SKIPPING " + rootProject.getName() );
getLogger().info( "SKIPPING " + rootProject.getName() );
logger.info( " " + segment );
getLogger().info( " " + segment );
logger.info( "This project has been banned from further executions due to previous failures." );
getLogger().info( "This project has been banned from further executions due to previous failures." );
line();
}
@ -295,9 +298,9 @@ public class DefaultLifecycleExecutor
{
line();
logger.info( "Building " + currentProject.getName() );
getLogger().info( "Building " + currentProject.getName() );
logger.info( " " + segment );
getLogger().info( " " + segment );
line();
@ -335,11 +338,11 @@ public class DefaultLifecycleExecutor
{
line();
logger.info( "SKIPPING " + currentProject.getName() );
getLogger().info( "SKIPPING " + currentProject.getName() );
logger.info( " " + segment );
getLogger().info( " " + segment );
logger.info( "This project has been banned from further executions due to previous failures." );
getLogger().info( "This project has been banned from further executions due to previous failures." );
line();
}
@ -514,7 +517,7 @@ public class DefaultLifecycleExecutor
}
else
{
logger.info( "No goals needed for project - skipping" );
getLogger().info( "No goals needed for project - skipping" );
}
}
@ -592,7 +595,7 @@ public class DefaultLifecycleExecutor
if ( project.getModel().getReports() != null )
{
logger.error( "Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." );
getLogger().error( "Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." );
}
if ( project.getReporting() == null || !project.getReporting().isExcludeDefaults() )
@ -614,7 +617,7 @@ public class DefaultLifecycleExecutor
int count = tok.countTokens();
if ( count != 2 && count != 3 )
{
logger.warn( "Invalid default report ignored: '" + report + "' (must be groupId:artifactId[:version])" );
getLogger().warn( "Invalid default report ignored: '" + report + "' (must be groupId:artifactId[:version])" );
}
else
{
@ -684,7 +687,7 @@ public class DefaultLifecycleExecutor
if ( forkEntryPoints.contains( mojoDescriptor ) )
{
logger.debug( "Omitting report: " + mojoDescriptor.getFullGoalName() + " from reports list. It initiated part of the fork currently executing." );
getLogger().debug( "Omitting report: " + mojoDescriptor.getFullGoalName() + " from reports list. It initiated part of the fork currently executing." );
continue;
}
@ -737,7 +740,7 @@ public class DefaultLifecycleExecutor
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
logger.info( "Preparing " + pluginDescriptor.getGoalPrefix() + ":" + mojoDescriptor.getGoal() );
getLogger().info( "Preparing " + pluginDescriptor.getGoalPrefix() + ":" + mojoDescriptor.getGoal() );
if ( mojoDescriptor.isAggregator() )
{
@ -747,7 +750,7 @@ public class DefaultLifecycleExecutor
line();
logger.info( "Building " + reactorProject.getName() );
getLogger().info( "Building " + reactorProject.getName() );
line();
@ -960,7 +963,7 @@ public class DefaultLifecycleExecutor
if ( lifecycleForkers.contains( execution.getMojoDescriptor() ) )
{
taskIterator.remove();
logger.warn( "Removing: " + execution.getMojoDescriptor().getGoal() + " from forked lifecycle, to prevent recursive invocation." );
getLogger().warn( "Removing: " + execution.getMojoDescriptor().getGoal() + " from forked lifecycle, to prevent recursive invocation." );
}
}
}
@ -1088,7 +1091,7 @@ public class DefaultLifecycleExecutor
}
catch ( ComponentLookupException e )
{
logger.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + lifecycle.getId() + ". Error: " + e.getMessage(), e );
getLogger().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + lifecycle.getId() + ". Error: " + e.getMessage(), e );
}
}
@ -1128,7 +1131,7 @@ public class DefaultLifecycleExecutor
{
if ( plugin.getGoals() != null )
{
logger.error( "Plugin contains a <goals/> section: this is IGNORED - please use <executions/> instead." );
getLogger().error( "Plugin contains a <goals/> section: this is IGNORED - please use <executions/> instead." );
}
List executions = plugin.getExecutions();
@ -1199,7 +1202,7 @@ public class DefaultLifecycleExecutor
if ( settings.isOffline() && mojoDescriptor.isOnlineRequired() )
{
String goal = mojoDescriptor.getGoal();
logger.warn( goal + " requires online mode, but maven is currently offline. Disabling " + goal + "." );
getLogger().warn( goal + " requires online mode, but maven is currently offline. Disabling " + goal + "." );
}
else
{
@ -1227,7 +1230,7 @@ public class DefaultLifecycleExecutor
}
return goals;
}
MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project )
throws LifecycleExecutionException
{
@ -1235,12 +1238,14 @@ public class DefaultLifecycleExecutor
Plugin plugin;
PluginDescriptor pluginDescriptor = null;
String[] taskSegments = StringUtils.split( task, ":" );
if ( taskSegments.length == 2 )
StringTokenizer tok = new StringTokenizer( task, ":" );
int numTokens = tok.countTokens();
if ( numTokens == 2 )
{
String prefix = taskSegments[0];
goal = taskSegments[1];
String prefix = tok.nextToken();
goal = tok.nextToken();
// This is the case where someone has executed a single goal from the command line
// of the form:
@ -1285,18 +1290,18 @@ public class DefaultLifecycleExecutor
plugin.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( prefix ) );
}
}
else if ( taskSegments.length == 3 || taskSegments.length == 4 )
else if ( numTokens == 3 || numTokens == 4 )
{
plugin = new Plugin();
plugin.setGroupId( taskSegments[0] );
plugin.setArtifactId( taskSegments[1] );
plugin.setGroupId( tok.nextToken() );
plugin.setArtifactId( tok.nextToken() );
if ( taskSegments.length == 4 )
if ( numTokens == 4 )
{
plugin.setVersion( taskSegments[3] );
plugin.setVersion( tok.nextToken() );
}
goal = taskSegments[4];
goal = tok.nextToken();
}
else
{
@ -1336,7 +1341,7 @@ public class DefaultLifecycleExecutor
protected void line()
{
logger.info( "------------------------------------------------------------------------" );
getLogger().info( "------------------------------------------------------------------------" );
}
public Map getPhaseToLifecycleMap()

View File

@ -19,6 +19,8 @@ package org.apache.maven.lifecycle;
* under the License.
*/
import java.util.List;
import org.apache.maven.BuildFailureException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
@ -30,6 +32,8 @@ import org.apache.maven.project.MavenProject;
*/
public interface LifecycleExecutor
{
List<Lifecycle> getLifecyclePhases();
TaskValidationResult isTaskValid( String task, MavenSession session, MavenProject rootProject );
void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher )

View File

@ -55,6 +55,7 @@ import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
@ -492,8 +493,44 @@ public class DefaultPluginManager
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
Xpp3Dom dom = mojoExecution.getConfiguration();
// Here we are walking throught the POM to find plugin configuraiton that we
// need to inject into the POM. Shane will soon take care of this.
// Merge the plugin level configuration with the execution level configuration
// where the latter is dominant.
if ( project.getBuildPlugins() != null )
{
for ( Plugin buildPlugin : project.getBuildPlugins() )
{
// The POM builder should have merged any configuration at the upper level of the plugin
// element with the execution level configuration where our goal is.
// We have our plugin
if ( buildPlugin.getArtifactId().equals( pluginDescriptor.getArtifactId() ) )
{
Xpp3Dom dom = (Xpp3Dom) buildPlugin.getConfiguration();
// Search through executions
for ( PluginExecution e : buildPlugin.getExecutions() )
{
// Search though goals to match what's been asked for.
for ( String g : e.getGoals() )
{
// This goal matches what's been asked for.
if ( g.equals( mojoDescriptor.getGoal() ) )
{
dom = Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) e.getConfiguration(), dom );
}
}
}
mojoExecution.setConfiguration( dom );
}
}
}
Xpp3Dom dom = mojoExecution.getConfiguration();
if ( dom != null )
{
try
@ -578,43 +615,7 @@ public class DefaultPluginManager
throw e;
}
catch ( LinkageError e )
{
if ( logger.isFatalErrorEnabled() )
{
StringBuffer sb = new StringBuffer();
sb.append( mojoDescriptor.getImplementation() ).append( "#execute() caused a linkage error (" );
sb.append( e.getClass().getName() ).append( "). Check the realms:" );
ClassRealm r = pluginDescriptor.getClassRealm();
sb.append( "\n\nNOTE:\nPlugin realm is: " ).append( r.getId() );
sb.append( "\nContainer realm is: " ).append( container.getContainerRealm().getId() );
sb.append( "\n\n" );
do
{
sb.append( "Realm ID: " ).append( r.getId() ).append( '\n' );
for ( int i = 0; i < r.getURLs().length; i++ )
{
sb.append( "urls[" ).append( i ).append( "] = " ).append( r.getURLs()[i] );
if ( i != ( r.getURLs().length - 1 ) )
{
sb.append( '\n' );
}
}
sb.append( "\n\n" );
r = r.getParentRealm();
}
while ( r != null );
logger.fatalError( sb.toString(), e );
}
session.getEventDispatcher().dispatchError( event, goalExecId, e );
throw e;
}
catch ( PluginManagerException e )
{
session.getEventDispatcher().dispatchError( event, goalExecId, e );

View File

@ -29,7 +29,6 @@ import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class LifecycleExecutorTest
@ -67,7 +66,7 @@ public class LifecycleExecutorTest
// Our test POM and this is actually the Maven POM so not the best idea.
File pom = new File( getBasedir(), "src/test/pom.xml" );
File targetPom = new File( getBasedir(), "target/pom-plugin.xml" );
File targetPom = new File( getBasedir(), "target/lifecycle-executor/pom-plugin.xml" );
FileUtils.copyFile( pom, targetPom );
if ( !targetPom.getParentFile().exists() )
{
@ -114,29 +113,29 @@ public class LifecycleExecutorTest
MojoExecution me = new MojoExecution( mojoDescriptor );
for ( Plugin bp : project.getBuildPlugins() )
{
// The POM builder should have merged any configuration at the upper level of the plugin
// element with the execution level configuration where our goal is.
// We have our plugin
if ( bp.getArtifactId().equals( pd.getArtifactId() ) )
{
// Search through executions
for( PluginExecution e : bp.getExecutions() )
{
// Search though goals to match what's been asked for.
for ( String g : e.getGoals() )
{
// This goal matches what's been asked for.
if( g.equals( goal ) )
{
me.setConfiguration( (Xpp3Dom) e.getConfiguration() );
}
}
}
}
}
// for ( Plugin bp : project.getBuildPlugins() )
// {
// // The POM builder should have merged any configuration at the upper level of the plugin
// // element with the execution level configuration where our goal is.
//
// // We have our plugin
// if ( bp.getArtifactId().equals( pd.getArtifactId() ) )
// {
// // Search through executions
// for( PluginExecution e : bp.getExecutions() )
// {
// // Search though goals to match what's been asked for.
// for ( String g : e.getGoals() )
// {
// // This goal matches what's been asked for.
// if( g.equals( goal ) )
// {
// me.setConfiguration( (Xpp3Dom) e.getConfiguration() );
// }
// }
// }
// }
// }
// Need some xpath action in here. Make sure the mojoExecution configuration is intact

View File

@ -418,31 +418,12 @@ public class MavenEmbedder
return getBuildLifecyclePhases();
}
public List getAllLifecyclePhases()
{
return LifecycleUtils.getValidPhaseNames();
}
public List getDefaultLifecyclePhases()
{
return getBuildLifecyclePhases();
}
public List getBuildLifecyclePhases()
{
return LifecycleUtils.getValidBuildPhaseNames();
}
public List getCleanLifecyclePhases()
{
return LifecycleUtils.getValidCleanPhaseNames();
}
public List getSiteLifecyclePhases()
{
return LifecycleUtils.getValidSitePhaseNames();
}
// ----------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------