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