001    package org.apache.maven.lifecycle;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.lifecycle.internal.BuilderCommon;
023    import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
024    import org.apache.maven.plugin.MojoExecution;
025    import org.apache.maven.project.MavenProject;
026    
027    import java.util.ArrayList;
028    import java.util.List;
029    
030    /**
031     * Defines scheduling information needed by weave mode.
032     * 
033     * @since 3.0
034     * @author Kristian Rosenvold
035     */
036    public class DefaultSchedules
037    {
038        List<Scheduling> schedules;
039    
040        public DefaultSchedules()
041        {
042        }
043    
044        public DefaultSchedules( List<Scheduling> schedules )
045        {
046            this.schedules = schedules;
047        }
048    
049        public List<ExecutionPlanItem> createExecutionPlanItem( MavenProject mavenProject, List<MojoExecution> executions )
050        {
051            BuilderCommon.attachToThread( mavenProject );
052    
053            List<ExecutionPlanItem> result = new ArrayList<ExecutionPlanItem>();
054            for ( MojoExecution mojoExecution : executions )
055            {
056                String lifeCyclePhase = mojoExecution.getLifecyclePhase();
057                final Scheduling scheduling = getScheduling( "default" );
058    
059                Schedule schedule = null;
060                if ( scheduling != null )
061                {
062                    schedule = scheduling.getSchedule( mojoExecution );
063                    if ( schedule == null )
064                    {
065                        schedule = scheduling.getSchedule( lifeCyclePhase );
066                    }
067                }
068    
069                result.add( new ExecutionPlanItem( mojoExecution, schedule ) );
070            }
071            return result;
072        }
073    
074        /**
075         * Gets scheduling associated with a given phase.
076         * <p/>
077         * This is part of the experimental weave mode and therefore not part of the public api.
078         *
079         * @param lifecyclePhaseName The name of the lifecycle phase
080         * @return Schecduling information related to phase
081         */
082    
083        Scheduling getScheduling( String lifecyclePhaseName )
084        {
085            for ( Scheduling schedule : schedules )
086            {
087                if ( lifecyclePhaseName.equals( schedule.getLifecycle() ) )
088                {
089                    return schedule;
090                }
091            }
092            return null;
093        }
094    
095        public List<Scheduling> getSchedules()
096        {
097            return schedules;
098        }
099    }