001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
003 * agreements. See the NOTICE file distributed with this work for additional information regarding
004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
005 * "License"); you may not use this file except in compliance with the License. You may obtain a
006 * copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License
011 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing permissions and limitations under
013 * the License.
014 */
015
016package org.apache.maven.lifecycle.internal.stub;
017
018import org.apache.maven.execution.MavenSession;
019import org.apache.maven.lifecycle.internal.GoalTask;
020import org.apache.maven.lifecycle.internal.LifecycleTask;
021import org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator;
022import org.apache.maven.lifecycle.internal.TaskSegment;
023import org.apache.maven.plugin.InvalidPluginDescriptorException;
024import org.apache.maven.plugin.MojoNotFoundException;
025import org.apache.maven.plugin.PluginDescriptorParsingException;
026import org.apache.maven.plugin.PluginNotFoundException;
027import org.apache.maven.plugin.PluginResolutionException;
028import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
029import org.apache.maven.plugin.version.PluginVersionResolutionException;
030
031import java.util.ArrayList;
032import java.util.List;
033
034/**
035 * @author Kristian Rosenvold
036 */
037public class LifecycleTaskSegmentCalculatorStub
038    extends DefaultLifecycleTaskSegmentCalculator
039{
040    public static final String clean = "clean";
041
042    public static final String aggr = "aggr";
043
044    public static final String install = "install";
045
046
047    public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks )
048        throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
049        MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
050        PluginVersionResolutionException
051    {
052        List<TaskSegment> taskSegments = new ArrayList<TaskSegment>( tasks.size() );
053
054        TaskSegment currentSegment = null;
055
056        for ( String task : tasks )
057        {
058            if ( aggr.equals( task ) )
059            {
060                boolean aggregating = true;
061
062                if ( currentSegment == null || currentSegment.isAggregating() != aggregating )
063                {
064                    currentSegment = new TaskSegment( aggregating );
065                    taskSegments.add( currentSegment );
066                }
067
068                currentSegment.getTasks().add( new GoalTask( task ) );
069            }
070            else
071            {
072                // lifecycle phase
073                if ( currentSegment == null || currentSegment.isAggregating() )
074                {
075                    currentSegment = new TaskSegment( false );
076                    taskSegments.add( currentSegment );
077                }
078                currentSegment.getTasks().add( new LifecycleTask( task ) );
079            }
080        }
081
082        return taskSegments;
083    }
084
085    public boolean requiresProject( MavenSession session )
086    {
087        return true;
088    }
089}