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.execution.ExecutionEvent;
023    import org.apache.maven.execution.ExecutionListener;
024    import org.apache.maven.execution.MavenSession;
025    import org.apache.maven.plugin.MojoExecution;
026    import org.codehaus.plexus.component.annotations.Component;
027    
028    /**
029     * Assists in firing execution events. <strong>Warning:</strong> This is an internal utility class that is only public
030     * for technical reasons, it is not part of the public API. In particular, this class can be changed or deleted without
031     * prior notice.
032     * 
033     * @author Benjamin Bentmann
034     */
035    @Component( role = ExecutionEventCatapult.class )
036    public class DefaultExecutionEventCatapult
037        implements ExecutionEventCatapult
038    {
039    
040        public void fire( ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution )
041        {
042            fire( eventType, session, mojoExecution, null );
043        }
044    
045        public void fire( ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution,
046                          Exception exception )
047        {
048            ExecutionListener listener = session.getRequest().getExecutionListener();
049    
050            if ( listener != null )
051            {
052                ExecutionEvent event = new DefaultExecutionEvent( eventType, session, mojoExecution, exception );
053    
054                switch ( eventType )
055                {
056                    case ProjectDiscoveryStarted:
057                        listener.projectDiscoveryStarted( event );
058                        break;
059    
060                    case SessionStarted:
061                        listener.sessionStarted( event );
062                        break;
063                    case SessionEnded:
064                        listener.sessionEnded( event );
065                        break;
066    
067                    case ProjectSkipped:
068                        listener.projectSkipped( event );
069                        break;
070                    case ProjectStarted:
071                        listener.projectStarted( event );
072                        break;
073                    case ProjectSucceeded:
074                        listener.projectSucceeded( event );
075                        break;
076                    case ProjectFailed:
077                        listener.projectFailed( event );
078                        break;
079    
080                    case MojoSkipped:
081                        listener.mojoSkipped( event );
082                        break;
083                    case MojoStarted:
084                        listener.mojoStarted( event );
085                        break;
086                    case MojoSucceeded:
087                        listener.mojoSucceeded( event );
088                        break;
089                    case MojoFailed:
090                        listener.mojoFailed( event );
091                        break;
092    
093                    case ForkStarted:
094                        listener.forkStarted( event );
095                        break;
096                    case ForkSucceeded:
097                        listener.forkSucceeded( event );
098                        break;
099                    case ForkFailed:
100                        listener.forkFailed( event );
101                        break;
102    
103                    case ForkedProjectStarted:
104                        listener.forkedProjectStarted( event );
105                        break;
106                    case ForkedProjectSucceeded:
107                        listener.forkedProjectSucceeded( event );
108                        break;
109                    case ForkedProjectFailed:
110                        listener.forkedProjectFailed( event );
111                        break;
112    
113                    default:
114                        throw new IllegalStateException( "Unknown execution event type " + eventType );
115                }
116            }
117        }
118    
119    }