View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.lifecycle.internal;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import org.apache.maven.execution.ExecutionEvent;
25  import org.apache.maven.execution.ExecutionListener;
26  import org.apache.maven.execution.MavenSession;
27  import org.apache.maven.plugin.MojoExecution;
28  
29  /**
30   * Assists in firing execution events. <strong>Warning:</strong> This is an internal utility class that is only public
31   * for technical reasons, it is not part of the public API. In particular, this class can be changed or deleted without
32   * prior notice.
33   *
34   */
35  @Named
36  @Singleton
37  public class DefaultExecutionEventCatapult implements ExecutionEventCatapult {
38  
39      public void fire(ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution) {
40          fire(eventType, session, mojoExecution, null);
41      }
42  
43      public void fire(
44              ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution, Exception exception) {
45          ExecutionListener listener = session.getRequest().getExecutionListener();
46  
47          if (listener != null) {
48              ExecutionEvent event = new DefaultExecutionEvent(eventType, session, mojoExecution, exception);
49  
50              switch (eventType) {
51                  case ProjectDiscoveryStarted:
52                      listener.projectDiscoveryStarted(event);
53                      break;
54  
55                  case SessionStarted:
56                      listener.sessionStarted(event);
57                      break;
58                  case SessionEnded:
59                      listener.sessionEnded(event);
60                      break;
61  
62                  case ProjectSkipped:
63                      listener.projectSkipped(event);
64                      break;
65                  case ProjectStarted:
66                      listener.projectStarted(event);
67                      break;
68                  case ProjectSucceeded:
69                      listener.projectSucceeded(event);
70                      break;
71                  case ProjectFailed:
72                      listener.projectFailed(event);
73                      break;
74  
75                  case MojoSkipped:
76                      listener.mojoSkipped(event);
77                      break;
78                  case MojoStarted:
79                      listener.mojoStarted(event);
80                      break;
81                  case MojoSucceeded:
82                      listener.mojoSucceeded(event);
83                      break;
84                  case MojoFailed:
85                      listener.mojoFailed(event);
86                      break;
87  
88                  case ForkStarted:
89                      listener.forkStarted(event);
90                      break;
91                  case ForkSucceeded:
92                      listener.forkSucceeded(event);
93                      break;
94                  case ForkFailed:
95                      listener.forkFailed(event);
96                      break;
97  
98                  case ForkedProjectStarted:
99                      listener.forkedProjectStarted(event);
100                     break;
101                 case ForkedProjectSucceeded:
102                     listener.forkedProjectSucceeded(event);
103                     break;
104                 case ForkedProjectFailed:
105                     listener.forkedProjectFailed(event);
106                     break;
107 
108                 default:
109                     throw new IllegalStateException("Unknown execution event type " + eventType);
110             }
111         }
112     }
113 }