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    
016    package org.apache.maven.lifecycle.internal.stub;
017    
018    import org.apache.maven.execution.MavenSession;
019    import org.apache.maven.lifecycle.internal.GoalTask;
020    import org.apache.maven.lifecycle.internal.LifecycleTask;
021    import org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator;
022    import org.apache.maven.lifecycle.internal.TaskSegment;
023    import org.apache.maven.plugin.InvalidPluginDescriptorException;
024    import org.apache.maven.plugin.MojoNotFoundException;
025    import org.apache.maven.plugin.PluginDescriptorParsingException;
026    import org.apache.maven.plugin.PluginNotFoundException;
027    import org.apache.maven.plugin.PluginResolutionException;
028    import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
029    import org.apache.maven.plugin.version.PluginVersionResolutionException;
030    
031    import java.util.ArrayList;
032    import java.util.List;
033    
034    /**
035     * @author Kristian Rosenvold
036     */
037    public 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    }