View Javadoc
1   package org.apache.maven.lifecycle.internal.builder.singlethreaded;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import javax.inject.Inject;
25  import javax.inject.Named;
26  import javax.inject.Singleton;
27  
28  import org.apache.maven.execution.MavenSession;
29  import org.apache.maven.lifecycle.internal.LifecycleModuleBuilder;
30  import org.apache.maven.lifecycle.internal.ProjectBuildList;
31  import org.apache.maven.lifecycle.internal.ProjectSegment;
32  import org.apache.maven.lifecycle.internal.ReactorBuildStatus;
33  import org.apache.maven.lifecycle.internal.ReactorContext;
34  import org.apache.maven.lifecycle.internal.TaskSegment;
35  import org.apache.maven.lifecycle.internal.builder.Builder;
36  
37  /**
38   * <p>
39   * A {@link Builder} encapsulates a strategy for building a set of Maven projects. The default strategy in Maven builds
40   * the the projects serially, but a {@link Builder} can employ any type of concurrency model to build the projects.
41   */
42  @Named( "singlethreaded" )
43  @Singleton
44  public class SingleThreadedBuilder
45      implements Builder
46  {
47      private final LifecycleModuleBuilder lifecycleModuleBuilder;
48  
49      @Inject
50      public SingleThreadedBuilder( LifecycleModuleBuilder lifecycleModuleBuilder )
51      {
52          this.lifecycleModuleBuilder = lifecycleModuleBuilder;
53      }
54  
55      public void build( MavenSession session, ReactorContext reactorContext, ProjectBuildList projectBuilds,
56                         List<TaskSegment> taskSegments, ReactorBuildStatus reactorBuildStatus )
57      {
58          for ( TaskSegment taskSegment : taskSegments )
59          {
60              for ( ProjectSegment projectBuild : projectBuilds.getByTaskSegment( taskSegment ) )
61              {
62                  try
63                  {
64                      lifecycleModuleBuilder.buildProject( session, reactorContext, projectBuild.getProject(),
65                                                           taskSegment );
66                      if ( reactorBuildStatus.isHalted() )
67                      {
68                          break;
69                      }
70                  }
71                  catch ( Exception e )
72                  {
73                      break; // Why are we just ignoring this exception? Are exceptions are being used for flow control
74                  }
75              }
76          }
77      }
78  }