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      @Override
40      public void fire(ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution) {
41          fire(eventType, session, mojoExecution, null);
42      }
43  
44      @Override
45      public void fire(
46              ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution, Exception exception) {
47          ExecutionListener listener = session.getRequest().getExecutionListener();
48  
49          if (listener != null) {
50              ExecutionEvent event = new DefaultExecutionEvent(eventType, session, mojoExecution, exception);
51  
52              switch (eventType) {
53                  case ProjectDiscoveryStarted:
54                      listener.projectDiscoveryStarted(event);
55                      break;
56  
57                  case SessionStarted:
58                      listener.sessionStarted(event);
59                      break;
60                  case SessionEnded:
61                      listener.sessionEnded(event);
62                      break;
63  
64                  case ProjectSkipped:
65                      listener.projectSkipped(event);
66                      break;
67                  case ProjectStarted:
68                      listener.projectStarted(event);
69                      break;
70                  case ProjectSucceeded:
71                      listener.projectSucceeded(event);
72                      break;
73                  case ProjectFailed:
74                      listener.projectFailed(event);
75                      break;
76  
77                  case MojoSkipped:
78                      listener.mojoSkipped(event);
79                      break;
80                  case MojoStarted:
81                      listener.mojoStarted(event);
82                      break;
83                  case MojoSucceeded:
84                      listener.mojoSucceeded(event);
85                      break;
86                  case MojoFailed:
87                      listener.mojoFailed(event);
88                      break;
89  
90                  case ForkStarted:
91                      listener.forkStarted(event);
92                      break;
93                  case ForkSucceeded:
94                      listener.forkSucceeded(event);
95                      break;
96                  case ForkFailed:
97                      listener.forkFailed(event);
98                      break;
99  
100                 case ForkedProjectStarted:
101                     listener.forkedProjectStarted(event);
102                     break;
103                 case ForkedProjectSucceeded:
104                     listener.forkedProjectSucceeded(event);
105                     break;
106                 case ForkedProjectFailed:
107                     listener.forkedProjectFailed(event);
108                     break;
109 
110                 default:
111                     throw new IllegalStateException("Unknown execution event type " + eventType);
112             }
113         }
114     }
115 }