1   package org.apache.maven.lifecycle.internal;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.execution.BuildSuccess;
24  import org.apache.maven.execution.ExecutionEvent;
25  import org.apache.maven.execution.MavenSession;
26  import org.apache.maven.lifecycle.MavenExecutionPlan;
27  import org.apache.maven.project.MavenProject;
28  import org.codehaus.plexus.component.annotations.Component;
29  import org.codehaus.plexus.component.annotations.Requirement;
30  
31  import java.util.HashSet;
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  @Component( role = LifecycleModuleBuilder.class )
44  public class LifecycleModuleBuilder
45  {
46  
47      @Requirement
48      private MojoExecutor mojoExecutor;
49  
50      @Requirement
51      private BuilderCommon builderCommon;
52  
53      @Requirement
54      private ExecutionEventCatapult eventCatapult;
55  
56      public void buildProject( MavenSession session, ReactorContext reactorContext, MavenProject currentProject,
57                                TaskSegment taskSegment )
58      {
59          buildProject( session, session, reactorContext, currentProject, taskSegment );
60      }
61  
62      public void buildProject( MavenSession session, MavenSession rootSession, ReactorContext reactorContext,
63                                MavenProject currentProject, TaskSegment taskSegment )
64      {
65          session.setCurrentProject( currentProject );
66  
67          long buildStartTime = System.currentTimeMillis();
68  
69          try
70          {
71  
72              if ( reactorContext.getReactorBuildStatus().isHaltedOrBlacklisted( currentProject ) )
73              {
74                  eventCatapult.fire( ExecutionEvent.Type.ProjectSkipped, session, null );
75                  return;
76              }
77  
78              eventCatapult.fire( ExecutionEvent.Type.ProjectStarted, session, null );
79  
80              BuilderCommon.attachToThread( currentProject );
81              MavenExecutionPlan executionPlan =
82                  builderCommon.resolveBuildPlan( session, currentProject, taskSegment, new HashSet<Artifact>() );
83  
84              mojoExecutor.execute( session, executionPlan.getMojoExecutions(), reactorContext.getProjectIndex() );
85  
86              long buildEndTime = System.currentTimeMillis();
87  
88              reactorContext.getResult().addBuildSummary(
89                  new BuildSuccess( currentProject, buildEndTime - buildStartTime ) );
90  
91              eventCatapult.fire( ExecutionEvent.Type.ProjectSucceeded, session, null );
92          }
93          catch ( Exception e )
94          {
95              builderCommon.handleBuildError( reactorContext, rootSession, session, currentProject, e, buildStartTime );
96          }
97          finally
98          {
99              session.setCurrentProject( null );
100 
101             Thread.currentThread().setContextClassLoader( reactorContext.getOriginalContextClassLoader() );
102         }
103     }
104 }