001    package org.apache.maven.lifecycle.internal;
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.Schedule;
023    import org.apache.maven.model.Plugin;
024    import org.apache.maven.plugin.MojoExecution;
025    import org.apache.maven.plugin.descriptor.MojoDescriptor;
026    
027    import java.util.concurrent.CountDownLatch;
028    
029    /**
030     * Wraps individual MojoExecutions, containing information about completion status and scheduling.
031     * <p/>
032     * NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
033     * 
034     * @since 3.0
035     * @author Kristian Rosenvold
036     */
037    public class ExecutionPlanItem
038    {
039        private final MojoExecution mojoExecution;
040    
041        private final Schedule schedule;
042        // Completeness just indicates that it has been run or failed
043    
044        private final CountDownLatch done = new CountDownLatch( 1 );
045    
046        public ExecutionPlanItem( MojoExecution mojoExecution, Schedule schedule )
047        {
048            this.mojoExecution = mojoExecution;
049            this.schedule = schedule;
050        }
051    
052        public MojoExecution getMojoExecution()
053        {
054            return mojoExecution;
055        }
056    
057        public String getLifecyclePhase()
058        {
059            return mojoExecution.getLifecyclePhase();
060        }
061    
062        public void setComplete()
063        {
064            done.countDown();
065        }
066    
067        public boolean isDone()
068        {
069            return done.getCount() < 1;
070        }
071    
072        public void forceComplete()
073        {
074            setComplete();
075        }
076    
077        public void waitUntilDone()
078            throws InterruptedException
079        {
080            done.await();
081        }
082    
083        public Schedule getSchedule()
084        {
085            return schedule;
086        }
087    
088        public Plugin getPlugin()
089        {
090            final MojoDescriptor mojoDescriptor = getMojoExecution().getMojoDescriptor();
091            return mojoDescriptor.getPluginDescriptor().getPlugin();
092        }
093    
094        @Override
095        public String toString()
096        {
097            return "ExecutionPlanItem{" + ", mojoExecution=" + mojoExecution + ", schedule=" + schedule + '}'
098                + super.toString();
099        }
100    
101    }