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