179
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.helium.logger.ant.listener;
|
|
18 |
|
|
19 |
import java.util.Vector;
|
|
20 |
|
|
21 |
import org.apache.tools.ant.BuildEvent;
|
|
22 |
import org.apache.tools.ant.BuildListener;
|
|
23 |
import org.apache.tools.ant.SubBuildListener;
|
|
24 |
import org.apache.tools.ant.Project;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* <code>StatusAndLogListener</code> implements {@link BuildListener} and
|
|
28 |
* listens to build events in particularly for activities such as ant logging
|
|
29 |
* and displaying build stage summary at the end of build process.
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
public class StatusAndLogListener implements BuildListener, SubBuildListener {
|
|
33 |
|
|
34 |
private static Vector<Handler> handlers = new Vector<Handler>();
|
|
35 |
private static Project project;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Default constructor
|
|
39 |
*/
|
|
40 |
public StatusAndLogListener() {
|
|
41 |
}
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Signals that the last target has finished. This event will still be fired
|
|
45 |
* if an error occurred during the build.
|
|
46 |
*
|
|
47 |
* @param event
|
|
48 |
* An event with any relevant extra information. Must not be
|
|
49 |
* <code>null</code>.
|
|
50 |
*
|
|
51 |
* @see BuildEvent#getException()
|
|
52 |
*/
|
|
53 |
public void buildStarted(BuildEvent event) {
|
|
54 |
project = event.getProject();
|
|
55 |
for (Handler handler : handlers) {
|
|
56 |
handler.handleBuildStarted(event);
|
|
57 |
}
|
|
58 |
|
|
59 |
}
|
|
60 |
/**
|
|
61 |
* Signals that a build has started. This event is fired before any targets
|
|
62 |
* have started.
|
|
63 |
*
|
|
64 |
* @param event
|
|
65 |
* An event with any relevant extra information. Must not be
|
|
66 |
* <code>null</code>.
|
|
67 |
*/
|
|
68 |
public void buildFinished(BuildEvent event) {
|
|
69 |
for ( Handler handler : handlers ) {
|
|
70 |
handler.handleBuildFinished( event );
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
|
|
75 |
/**
|
|
76 |
* Signals that a target is starting.
|
|
77 |
*
|
|
78 |
* @param event
|
|
79 |
* An event with any relevant extra information. Must not be
|
|
80 |
* <code>null</code>.
|
|
81 |
*
|
|
82 |
* @see BuildEvent#getTarget()
|
|
83 |
*/
|
|
84 |
public void targetStarted(BuildEvent event) {
|
|
85 |
for (Handler handler : handlers) {
|
|
86 |
handler.handleTargetStarted(event);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Signals that a target has finished. This event will still be fired if an
|
|
92 |
* error occurred during the build.
|
|
93 |
*
|
|
94 |
* @param event
|
|
95 |
* An event with any relevant extra information. Must not be
|
|
96 |
* <code>null</code>.
|
|
97 |
*
|
|
98 |
* @see BuildEvent#getException()
|
|
99 |
*/
|
|
100 |
public void targetFinished(BuildEvent event) {
|
|
101 |
for (Handler handler : handlers) {
|
|
102 |
handler.handleTargetFinished(event);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Signals that a task is starting.
|
|
108 |
*
|
|
109 |
* @param event
|
|
110 |
* An event with any relevant extra information. Must not be
|
|
111 |
* <code>null</code>.
|
|
112 |
*
|
|
113 |
* @see BuildEvent#getTask()
|
|
114 |
*/
|
|
115 |
public void taskStarted(BuildEvent event) {
|
|
116 |
// implement if needed
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Signals that a task has finished. This event will still be fired if an
|
|
121 |
* error occurred during the build.
|
|
122 |
*
|
|
123 |
* @param event
|
|
124 |
* An event with any relevant extra information. Must not be
|
|
125 |
* <code>null</code>.
|
|
126 |
*
|
|
127 |
* @see BuildEvent#getException()
|
|
128 |
*/
|
|
129 |
public void taskFinished(BuildEvent event) {
|
|
130 |
// implement if needed
|
|
131 |
}
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Signals that a subbuild has started. This event is fired before any targets have started.
|
|
135 |
* @param event
|
|
136 |
*/
|
|
137 |
public void subBuildStarted(BuildEvent event) {
|
|
138 |
|
|
139 |
}
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Signals that the last target has finished. This event will still be fired if an error occurred during the build.
|
|
143 |
* @param event
|
|
144 |
*/
|
|
145 |
|
|
146 |
public void subBuildFinished(BuildEvent event) {
|
|
147 |
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
/**
|
|
153 |
* Signals a message logging event.
|
|
154 |
*
|
|
155 |
* @param event
|
|
156 |
* An event with any relevant extra information. Must not be
|
|
157 |
* <code>null</code>.
|
|
158 |
*
|
|
159 |
* @see BuildEvent#getMessage()
|
|
160 |
* @see BuildEvent#getException()
|
|
161 |
* @see BuildEvent#getPriority()
|
|
162 |
*/
|
|
163 |
public void messageLogged(BuildEvent event) {
|
|
164 |
// implement if needed
|
|
165 |
|
|
166 |
}
|
|
167 |
|
|
168 |
/**
|
|
169 |
* Register the given handler.
|
|
170 |
*
|
|
171 |
* @param handler
|
|
172 |
* is the handler to register
|
|
173 |
*/
|
|
174 |
public static void register ( Handler handler ) {
|
|
175 |
handlers.add( handler );
|
|
176 |
}
|
|
177 |
|
|
178 |
/**
|
|
179 |
* Return root project name.
|
|
180 |
* @return
|
|
181 |
*/
|
|
182 |
public static Project getProject() {
|
|
183 |
return project;
|
|
184 |
}
|
|
185 |
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Check and return required type handler.
|
|
189 |
* @param handlerType
|
|
190 |
* @return
|
|
191 |
*/
|
|
192 |
public static Handler getHandler(Class handlerType) {
|
|
193 |
for (Handler handler : handlers) {
|
|
194 |
if (handlerType.isInstance(handler)) {
|
|
195 |
return handler;
|
|
196 |
}
|
|
197 |
}
|
|
198 |
return null;
|
|
199 |
}
|
|
200 |
|
|
201 |
}
|