View Javadoc

1   package org.apache.maven.lifecycle;
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 org.apache.maven.lifecycle.internal.BuilderCommon;
23  import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
24  import org.apache.maven.plugin.MojoExecution;
25  import org.apache.maven.project.MavenProject;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * Defines scheduling information needed by weave mode.
32   * 
33   * @since 3.0
34   * @author Kristian Rosenvold
35   */
36  public class DefaultSchedules
37  {
38      List<Scheduling> schedules;
39  
40      @SuppressWarnings( { "UnusedDeclaration" } )
41      public DefaultSchedules()
42      {
43      }
44  
45      public DefaultSchedules( List<Scheduling> schedules )
46      {
47          this.schedules = schedules;
48      }
49  
50      public List<ExecutionPlanItem> createExecutionPlanItem( MavenProject mavenProject, List<MojoExecution> executions )
51      {
52          BuilderCommon.attachToThread( mavenProject );
53  
54          List<ExecutionPlanItem> result = new ArrayList<ExecutionPlanItem>();
55          for ( MojoExecution mojoExecution : executions )
56          {
57              String lifeCyclePhase = mojoExecution.getLifecyclePhase();
58              final Scheduling scheduling = getScheduling( "default" );
59              Schedule schedule = null;
60              if ( scheduling != null )
61              {
62                  schedule = scheduling.getSchedule( mojoExecution );
63                  if ( schedule == null )
64                  {
65                      schedule = scheduling.getSchedule( lifeCyclePhase );
66                  }
67              }
68              result.add( new ExecutionPlanItem( mojoExecution, schedule ) );
69  
70          }
71          return result;
72      }
73  
74      /**
75       * Gets scheduling associated with a given phase.
76       * <p/>
77       * This is part of the experimental weave mode and therefore not part of the public api.
78       *
79       * @param lifecyclePhaseName The name of the lifecycle phase
80       * @return Schecduling information related to phase
81       */
82  
83      Scheduling getScheduling( String lifecyclePhaseName )
84      {
85          for ( Scheduling schedule : schedules )
86          {
87              if ( lifecyclePhaseName.equals( schedule.getLifecycle() ) )
88              {
89                  return schedule;
90              }
91          }
92          return null;
93      }
94  
95      public List<Scheduling> getSchedules()
96      {
97          return schedules;
98      }
99  }