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 org.apache.maven.execution.ExecutionEvent;
22  import org.apache.maven.execution.ExecutionListener;
23  import org.apache.maven.execution.MavenSession;
24  import org.apache.maven.plugin.MojoExecution;
25  import org.codehaus.plexus.component.annotations.Component;
26  
27  /**
28   * Assists in firing execution events. <strong>Warning:</strong> This is an internal utility class that is only public
29   * for technical reasons, it is not part of the public API. In particular, this class can be changed or deleted without
30   * prior notice.
31   *
32   * @author Benjamin Bentmann
33   */
34  @Component(role = ExecutionEventCatapult.class)
35  public class DefaultExecutionEventCatapult implements ExecutionEventCatapult {
36  
37      public void fire(ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution) {
38          fire(eventType, session, mojoExecution, null);
39      }
40  
41      public void fire(
42              ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution, Exception exception) {
43          ExecutionListener listener = session.getRequest().getExecutionListener();
44  
45          if (listener != null) {
46              ExecutionEvent event = new DefaultExecutionEvent(eventType, session, mojoExecution, exception);
47  
48              switch (eventType) {
49                  case ProjectDiscoveryStarted:
50                      listener.projectDiscoveryStarted(event);
51                      break;
52  
53                  case SessionStarted:
54                      listener.sessionStarted(event);
55                      break;
56                  case SessionEnded:
57                      listener.sessionEnded(event);
58                      break;
59  
60                  case ProjectSkipped:
61                      listener.projectSkipped(event);
62                      break;
63                  case ProjectStarted:
64                      listener.projectStarted(event);
65                      break;
66                  case ProjectSucceeded:
67                      listener.projectSucceeded(event);
68                      break;
69                  case ProjectFailed:
70                      listener.projectFailed(event);
71                      break;
72  
73                  case MojoSkipped:
74                      listener.mojoSkipped(event);
75                      break;
76                  case MojoStarted:
77                      listener.mojoStarted(event);
78                      break;
79                  case MojoSucceeded:
80                      listener.mojoSucceeded(event);
81                      break;
82                  case MojoFailed:
83                      listener.mojoFailed(event);
84                      break;
85  
86                  case ForkStarted:
87                      listener.forkStarted(event);
88                      break;
89                  case ForkSucceeded:
90                      listener.forkSucceeded(event);
91                      break;
92                  case ForkFailed:
93                      listener.forkFailed(event);
94                      break;
95  
96                  case ForkedProjectStarted:
97                      listener.forkedProjectStarted(event);
98                      break;
99                  case ForkedProjectSucceeded:
100                     listener.forkedProjectSucceeded(event);
101                     break;
102                 case ForkedProjectFailed:
103                     listener.forkedProjectFailed(event);
104                     break;
105 
106                 default:
107                     throw new IllegalStateException("Unknown execution event type " + eventType);
108             }
109         }
110     }
111 }