View Javadoc
1   package org.apache.maven.demo.extension;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.execution.AbstractExecutionListener;
23  import org.apache.maven.execution.ExecutionEvent;
24  
25  /**
26   * Execution Listener demo.<br>
27   * <b>Question:</b> how to instantiate and inject it to Maven runtime?<br>
28   * <b>Answer</b>: LifecycleParticipant (injected by Plexus/Sisu) can get original ExecutionListener from
29   * request and replace with this class that should delegate to original listener<br>
30   * <b>Example</b>: Maven's <a href=
31   * "https://maven.apache.org/ref/current/maven-embedder/xref/org/apache/maven/cli/MavenCli.html#L1446">CLI</a> creates
32   * a new instance of
33   * <a href=
34   * "https://maven.apache.org/ref/current/maven-embedder/apidocs/org/apache/maven/cli/event/ExecutionEventLogger.html"
35   * >ExecutionEventLogger</a> that displays to console, and calls
36   * {@code eventSpyDispatcher.chainListener(executionListener)}.
37   *
38   * @see org.apache.maven.execution.MavenExecutionRequest#setExecutionListener(org.apache.maven.execution.ExecutionListener)
39   */
40  // notice: just an object, not a Plexus/Sisu/JSR 330 component
41  public class ExecutionListenerDemo
42      extends AbstractExecutionListener
43  {
44      public void projectDiscoveryStarted( ExecutionEvent event )
45      {
46          System.err.println( "ExecutionListenerDemo projectDiscoveryStarted" );
47      }
48  
49      public void sessionStarted( ExecutionEvent event )
50      {
51          System.err.println( "ExecutionListenerDemo sessionStarted" );
52      }
53  
54      public void sessionEnded( ExecutionEvent event )
55      {
56          System.err.println( "ExecutionListenerDemo sessionEnded" );
57      }
58  
59      public void projectSkipped( ExecutionEvent event )
60      {
61          System.err.println( "ExecutionListenerDemo projectSkipped" );
62      }
63  
64      public void projectStarted( ExecutionEvent event )
65      {
66          System.err.println( "ExecutionListenerDemo projectStarted" );
67      }
68  
69      public void projectSucceeded( ExecutionEvent event )
70      {
71          System.err.println( "ExecutionListenerDemo projectSucceeded" );
72      }
73  
74      public void projectFailed( ExecutionEvent event )
75      {
76          System.err.println( "ExecutionListenerDemo projectFailed" );
77      }
78  
79      public void forkStarted( ExecutionEvent event )
80      {
81          System.err.println( "ExecutionListenerDemo forkStarted" );
82      }
83  
84      public void forkSucceeded( ExecutionEvent event )
85      {
86          System.err.println( "ExecutionListenerDemo forkSucceeded" );
87      }
88  
89      public void forkFailed( ExecutionEvent event )
90      {
91          System.err.println( "ExecutionListenerDemo forkFailed" );
92      }
93  
94      public void mojoSkipped( ExecutionEvent event )
95      {
96          System.err.println( "ExecutionListenerDemo mojoSkipped" );
97      }
98  
99      public void mojoStarted( ExecutionEvent event )
100     {
101         System.err.println( "ExecutionListenerDemo mojoStarted" );
102     }
103 
104     public void mojoSucceeded( ExecutionEvent event )
105     {
106         System.err.println( "ExecutionListenerDemo mojoSucceeded" );
107     }
108 
109     public void mojoFailed( ExecutionEvent event )
110     {
111         System.err.println( "ExecutionListenerDemo mojoFailed" );
112     }
113 
114     public void forkedProjectStarted( ExecutionEvent event )
115     {
116         System.err.println( "ExecutionListenerDemo forkedProjectStarted" );
117     }
118 
119     public void forkedProjectSucceeded( ExecutionEvent event )
120     {
121         System.err.println( "ExecutionListenerDemo forkedProjectSucceeded" );
122     }
123 
124     public void forkedProjectFailed( ExecutionEvent event )
125     {
126         System.err.println( "ExecutionListenerDemo forkedProjectFailed" );
127     }
128 }