You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/05/04 03:41:00 UTC
svn commit: r168041 -
/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
Author: brett
Date: Tue May 3 18:40:59 2005
New Revision: 168041
URL: http://svn.apache.org/viewcvs?rev=168041&view=rev
Log:
improve the structure of the lifecycle execution code
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=168041&r1=168040&r2=168041&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Tue May 3 18:40:59 2005
@@ -39,6 +39,7 @@
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -154,22 +155,26 @@
{
String task = (String) i.next();
- processGoalChain( task, session, phaseMap );
+ List goals = processGoalChain( task, session, phaseMap );
- try
+ for ( Iterator j = goals.iterator(); j.hasNext(); )
{
- if ( phaseMap.containsKey( task ) )
+ MojoDescriptor mojo = (MojoDescriptor) j.next();
+
+ if ( mojo.getExecutePhase() != null )
{
- executePhase( task, session, phaseMap );
+ // TODO: is this too broad to execute?
+ execute( Collections.singletonList( mojo.getExecutePhase() ), session );
}
- else
+
+ try
{
- executeMojo( task, session );
+ pluginManager.executeMojo( session, mojo );
+ }
+ catch ( PluginManagerException e )
+ {
+ throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
}
- }
- catch ( PluginManagerException e )
- {
- throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
}
}
}
@@ -282,7 +287,8 @@
// TODO: remove later
if ( mojoDescriptor.getGoal() == null )
{
- throw new LifecycleExecutionException( "The plugin " + artifactId + " was built with an older version of Maven" );
+ throw new LifecycleExecutionException(
+ "The plugin " + artifactId + " was built with an older version of Maven" );
}
if ( plugin.getGoals().isEmpty() || plugin.getGoalsAsMap().containsKey( mojoDescriptor.getGoal() ) )
@@ -323,9 +329,11 @@
}
}
- private void processGoalChain( String task, MavenSession session, Map phaseMap )
+ private List processGoalChain( String task, MavenSession session, Map phaseMap )
throws LifecycleExecutionException, ArtifactResolutionException
{
+ List goals = new ArrayList();
+
if ( phaseMap.containsKey( task ) )
{
// only execute up to the given phase
@@ -344,18 +352,20 @@
{
String goal = (String) k.next();
- configureMojo( goal, session, phaseMap );
+ goals.add( configureMojo( goal, session, phaseMap ) );
+
}
}
}
}
else
{
- configureMojo( task, session, phaseMap );
+ goals.add( configureMojo( task, session, phaseMap ) );
}
+ return goals;
}
- private void configureMojo( String task, MavenSession session, Map phaseMap )
+ private MojoDescriptor configureMojo( String task, MavenSession session, Map phaseMap )
throws LifecycleExecutionException, ArtifactResolutionException
{
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
@@ -386,90 +396,9 @@
}
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
- }
-
- private void executePhase( String phase, MavenSession session, Map phaseMap )
- throws MojoExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException,
- LifecycleExecutionException
- {
- // only execute up to the given phase
- int index = phases.indexOf( phaseMap.get( phase ) );
-
- EventDispatcher dispatcher = session.getEventDispatcher();
-
- for ( int j = 0; j <= index; j++ )
- {
- Phase p = (Phase) phases.get( j );
-
- p = (Phase) phaseMap.get( p.getId() );
-
- String event = MavenEvents.PHASE_EXECUTION;
-
- // !! This is ripe for refactoring to an aspect.
- // Event monitoring.
- dispatcher.dispatchStart( event, p.getId() );
- try
- {
- if ( p.getGoals() != null )
- {
- for ( Iterator i = p.getGoals().iterator(); i.hasNext(); )
- {
- String goal = (String) i.next();
-
- executeMojo( goal, session );
- }
- }
- }
- catch ( MojoExecutionException e )
- {
- dispatcher.dispatchError( event, p.getId(), e );
- throw e;
- }
- catch ( PluginManagerException e )
- {
- dispatcher.dispatchError( event, p.getId(), e );
- throw e;
- }
- catch ( ArtifactResolutionException e )
- {
- dispatcher.dispatchError( event, p.getId(), e );
- throw e;
- }
- dispatcher.dispatchEnd( event, p.getId() );
- }
+ return mojoDescriptor;
}
-
- protected void executeMojo( String id, MavenSession session )
- throws MojoExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException,
- LifecycleExecutionException
- {
- Logger logger = getLogger();
- logger.debug( "Resolving artifacts from:" );
- logger.debug( "\t{localRepository: " + session.getLocalRepository() + "}" );
- logger.debug( "\t{remoteRepositories: " + session.getRemoteRepositories() + "}" );
-
- pluginManager.verifyPluginForGoal( id, session );
-
- MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( id );
-
- if ( mojoDescriptor == null )
- {
- throw new MojoExecutionException( "Unable to find goal: " + id );
- }
-
- if ( mojoDescriptor.getExecutePhase() != null )
- {
- // TODO: is this too broad to execute?
- execute( Collections.singletonList( mojoDescriptor.getExecutePhase() ), session );
- }
-
- pluginManager.executeMojo( session, mojoDescriptor );
- }
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
public List getPhases()
{
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org