maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-core/src/main/java/org/apache/maven DefaultMaven.java
Date Wed, 16 Mar 2005 23:19:00 GMT
brett       2005/03/16 15:19:00

  Modified:    maven-core/src/main/java/org/apache/maven/lifecycle
                        DefaultLifecycleExecutor.java
                        LifecycleExecutor.java Phase.java
               maven-core/src/main/java/org/apache/maven DefaultMaven.java
  Log:
  PR: MNG-209
  re-initialise lifecycle on each execution. Make it threadsafe.
  
  Revision  Changes    Path
  1.26      +38 -44    maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
  
  Index: DefaultLifecycleExecutor.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- DefaultLifecycleExecutor.java	15 Mar 2005 21:48:55 -0000	1.25
  +++ DefaultLifecycleExecutor.java	16 Mar 2005 23:19:00 -0000	1.26
  @@ -34,7 +34,6 @@
   import org.apache.maven.project.MavenProjectBuilder;
   import org.codehaus.plexus.logging.AbstractLogEnabled;
   import org.codehaus.plexus.logging.Logger;
  -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
   
   import java.util.Date;
   import java.util.HashMap;
  @@ -49,7 +48,7 @@
    */
   public class DefaultLifecycleExecutor
       extends AbstractLogEnabled
  -    implements LifecycleExecutor, Initializable
  +    implements LifecycleExecutor
   {
       // ----------------------------------------------------------------------
       // Components
  @@ -65,8 +64,6 @@
   
       private List phases;
   
  -    private Map phaseMap;
  -
       // ----------------------------------------------------------------------
       //
       // ----------------------------------------------------------------------
  @@ -84,6 +81,16 @@
   
           response.setStart( new Date() );
   
  +        Map phaseMap = new HashMap();
  +
  +        for ( Iterator i = phases.iterator(); i.hasNext(); )
  +        {
  +            Phase p = (Phase) i.next();
  +
  +            // Make a copy of the phase as we will modify it
  +            phaseMap.put( p.getId(), new Phase( p ) );
  +        }
  +
           try
           {
               MavenProject project = session.getProject();
  @@ -94,7 +101,7 @@
               {
                   if ( artifactHandler.packageGoal() != null )
                   {
  -                    verifyMojoPhase( artifactHandler.packageGoal(), session );
  +                    verifyMojoPhase( artifactHandler.packageGoal(), session, phaseMap );
                   }
   
                   if ( artifactHandler.additionalPlugin() != null )
  @@ -111,21 +118,21 @@
   
                       plugin.setArtifactId( additionalPluginArtifactId );
   
  -                    processPluginPhases( plugin, session );
  +                    processPluginPhases( plugin, session, phaseMap );
                   }
               }
   
  -            processPluginConfiguration( session.getProject(), session );
  +            processPluginConfiguration( session.getProject(), session, phaseMap );
   
               for ( Iterator i = tasks.iterator(); i.hasNext(); )
               {
                   String task = (String) i.next();
   
  -                processGoalChain( task, session );
  +                processGoalChain( task, session, phaseMap );
   
                   if ( phaseMap.containsKey( task ) )
                   {
  -                    executePhase( task, session, response );
  +                    executePhase( task, session, response, phaseMap );
                   }
                   else
                   {
  @@ -184,14 +191,14 @@
       }
   
       // TODO: don't throw Exception
  -    private void processPluginConfiguration( MavenProject project, MavenSession mavenSession
)
  +    private void processPluginConfiguration( MavenProject project, MavenSession mavenSession,
Map phaseMap )
           throws Exception
       {
           for ( Iterator i = project.getPlugins().iterator(); i.hasNext(); )
           {
               Plugin plugin = (Plugin) i.next();
   
  -            processPluginPhases( plugin, mavenSession );
  +            processPluginPhases( plugin, mavenSession, phaseMap );
           }
       }
   
  @@ -204,7 +211,7 @@
        * @throws Exception
        */
       // TODO: don't throw Exception
  -    private void processPluginPhases( Plugin plugin, MavenSession mavenSession )
  +    private void processPluginPhases( Plugin plugin, MavenSession mavenSession, Map phaseMap
)
           throws Exception
       {
           String groupId = plugin.getGroupId();
  @@ -225,7 +232,7 @@
           {
               String pluginId = pluginDescriptor.getArtifactId();
   
  -            // Right now this maven-foo-plugin so this is a hack right now.
  +            // TODO: Right now this maven-foo-plugin so this is a hack right now.
   
               pluginId = pluginId.substring( 6 );
   
  @@ -245,7 +252,7 @@
                           "A goal '" + mojoId + "' was declared in pom.xml, but does not
exist" );
                   }
   
  -                configureMojo( mojoDescriptor );
  +                configureMojo( mojoDescriptor, phaseMap );
               }
           }
           else
  @@ -254,7 +261,7 @@
               {
                   MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
   
  -                configureMojo( mojoDescriptor );
  +                configureMojo( mojoDescriptor, phaseMap );
               }
           }
       }
  @@ -267,7 +274,7 @@
        * @param mojoDescriptor
        * @throws Exception
        */
  -    private void configureMojo( MojoDescriptor mojoDescriptor )
  +    private void configureMojo( MojoDescriptor mojoDescriptor, Map phaseMap )
           throws Exception
       {
           if ( mojoDescriptor.getPhase() != null )
  @@ -278,7 +285,7 @@
           }
       }
   
  -    private void processGoalChain( String task, MavenSession session )
  +    private void processGoalChain( String task, MavenSession session, Map phaseMap )
           throws Exception
       {
           if ( phaseMap.containsKey( task ) )
  @@ -288,26 +295,29 @@
   
               for ( int j = 0; j <= index; j++ )
               {
  +                // TODO: phases should just be strings...
                   Phase p = (Phase) phases.get( j );
   
  +                p = (Phase) phaseMap.get( p.getId() );
  +
                   if ( p.getGoals() != null )
                   {
                       for ( Iterator k = p.getGoals().iterator(); k.hasNext(); )
                       {
                           String goal = (String) k.next();
   
  -                        verifyMojoPhase( goal, session );
  +                        verifyMojoPhase( goal, session, phaseMap );
                       }
                   }
               }
           }
           else
           {
  -            verifyMojoPhase( task, session );
  +            verifyMojoPhase( task, session, phaseMap );
           }
       }
   
  -    private void verifyMojoPhase( String task, MavenSession session )
  +    private void verifyMojoPhase( String task, MavenSession session, Map phaseMap )
           throws Exception
       {
           MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
  @@ -332,7 +342,7 @@
           }
       }
   
  -    private void executePhase( String phase, MavenSession session, MavenExecutionResponse
response )
  +    private void executePhase( String phase, MavenSession session, MavenExecutionResponse
response, Map phaseMap )
           throws LifecycleExecutionException
       {
           // only execute up to the given phase
  @@ -344,6 +354,8 @@
           {
               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.
  @@ -395,7 +407,11 @@
           try
           {
               Logger logger = getLogger();
  -            logger.debug( "Resolving artifacts from:\n" + "\t{localRepository: " + session.getLocalRepository()
+ "}\n" + "\t{remoteRepositories: " + session.getRemoteRepositories() + "}" );
  +            logger.debug(
  +                "Resolving artifacts from:\n" + "\t{localRepository: " + session.getLocalRepository()
+ "}\n" +
  +                "\t{remoteRepositories: " +
  +                session.getRemoteRepositories() +
  +                "}" );
   
               return pluginManager.executeMojo( session, id );
           }
  @@ -413,26 +429,4 @@
       {
           return phases;
       }
  -
  -    public Phase getPhase( String id )
  -    {
  -        return (Phase) phaseMap.get( id );
  -    }
  -
  -    // ----------------------------------------------------------------------
  -    // Lifecylce Management
  -    // ----------------------------------------------------------------------
  -
  -    public void initialize()
  -        throws Exception
  -    {
  -        phaseMap = new HashMap();
  -
  -        for ( Iterator i = phases.iterator(); i.hasNext(); )
  -        {
  -            Phase p = (Phase) i.next();
  -
  -            phaseMap.put( p.getId(), p );
  -        }
  -    }
   }
  \ No newline at end of file
  
  
  
  1.4       +1 -3      maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
  
  Index: LifecycleExecutor.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LifecycleExecutor.java	27 Feb 2005 05:39:55 -0000	1.3
  +++ LifecycleExecutor.java	16 Mar 2005 23:19:00 -0000	1.4
  @@ -34,6 +34,4 @@
           throws LifecycleExecutionException;
   
       List getPhases();
  -
  -    Phase getPhase( String id );    
   }
  
  
  
  1.3       +36 -1     maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/Phase.java
  
  Index: Phase.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/Phase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Phase.java	27 Feb 2005 05:39:55 -0000	1.2
  +++ Phase.java	16 Mar 2005 23:19:00 -0000	1.3
  @@ -30,6 +30,19 @@
   
       private Set goals;
   
  +    public Phase()
  +    {
  +    }
  +
  +    Phase( Phase phase )
  +    {
  +        this.id = phase.id;
  +        if ( phase.goals != null )
  +        {
  +            this.goals = new HashSet( phase.goals );
  +        }
  +    }
  +
       public String getId()
       {
           return id;
  @@ -43,4 +56,26 @@
           }
           return goals;
       }
  +
  +    public boolean equals( Object obj )
  +    {
  +        if ( obj == this )
  +        {
  +            return true;
  +        }
  +
  +        if ( !( obj instanceof Phase ) )
  +        {
  +            return false;
  +        }
  +
  +        Phase p = (Phase) obj;
  +
  +        return id.equals( p.id );
  +    }
  +
  +    public int hashCode()
  +    {
  +        return id.hashCode();
  +    }
   }
  
  
  
  1.38      +6 -6      maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
  
  Index: DefaultMaven.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- DefaultMaven.java	16 Mar 2005 06:29:34 -0000	1.37
  +++ DefaultMaven.java	16 Mar 2005 23:19:00 -0000	1.38
  @@ -189,12 +189,12 @@
   
       private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject
project,
                                                      EventDispatcher dispatcher, List goals
)
  -        throws ComponentLookupException
  +        throws Exception
       {
           MavenSession session = createSession( request );
   
           session.setProject( project );
  -        
  +
           session.setRemoteRepositories( getArtifactRepositories( project, request.getSettings()
) );
   
           resolveParameters( request );
  @@ -216,6 +216,7 @@
           catch ( Exception e )
           {
               dispatcher.dispatchError( event, project.getId(), e );
  +            throw e;
           }
           // End event monitoring.
   
  @@ -298,9 +299,8 @@
   
           if ( proxy != null )
           {
  -            wagonManager.setProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(),
  -                                   proxy.getUsername(), proxy.getPassword(),
  -                                   proxy.getNonProxyHosts() );
  +            wagonManager.setProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(),
proxy.getUsername(),
  +                                   proxy.getPassword(), proxy.getNonProxyHosts() );
           }
   
       }
  
  
  

Mime
View raw message