View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  
16  package org.apache.maven.lifecycle.internal.stub;
17  
18  import org.apache.maven.execution.MavenSession;
19  import org.apache.maven.lifecycle.internal.GoalTask;
20  import org.apache.maven.lifecycle.internal.LifecycleTask;
21  import org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator;
22  import org.apache.maven.lifecycle.internal.TaskSegment;
23  import org.apache.maven.plugin.InvalidPluginDescriptorException;
24  import org.apache.maven.plugin.MojoNotFoundException;
25  import org.apache.maven.plugin.PluginDescriptorParsingException;
26  import org.apache.maven.plugin.PluginNotFoundException;
27  import org.apache.maven.plugin.PluginResolutionException;
28  import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
29  import org.apache.maven.plugin.version.PluginVersionResolutionException;
30  
31  import java.util.ArrayList;
32  import java.util.List;
33  
34  /**
35   * @author Kristian Rosenvold
36   */
37  public class LifecycleTaskSegmentCalculatorStub
38      extends DefaultLifecycleTaskSegmentCalculator
39  {
40      public static final String clean = "clean";
41  
42      public static final String aggr = "aggr";
43  
44      public static final String install = "install";
45  
46  
47      public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks )
48          throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
49          MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
50          PluginVersionResolutionException
51      {
52          List<TaskSegment> taskSegments = new ArrayList<>( tasks.size() );
53  
54          TaskSegment currentSegment = null;
55  
56          for ( String task : tasks )
57          {
58              if ( aggr.equals( task ) )
59              {
60                  boolean aggregating = true;
61  
62                  if ( currentSegment == null || currentSegment.isAggregating() != aggregating )
63                  {
64                      currentSegment = new TaskSegment( aggregating );
65                      taskSegments.add( currentSegment );
66                  }
67  
68                  currentSegment.getTasks().add( new GoalTask( task ) );
69              }
70              else
71              {
72                  // lifecycle phase
73                  if ( currentSegment == null || currentSegment.isAggregating() )
74                  {
75                      currentSegment = new TaskSegment( false );
76                      taskSegments.add( currentSegment );
77                  }
78                  currentSegment.getTasks().add( new LifecycleTask( task ) );
79              }
80          }
81  
82          return taskSegments;
83      }
84  
85      public boolean requiresProject( MavenSession session )
86      {
87          return true;
88      }
89  }