1 /*
2 * #%L
3 * Native ARchive plugin for Maven
4 * %%
5 * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6 * %%
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * #L%
19 */
20 package com.github.maven_nar.cpptasks;
21
22 import java.util.Vector;
23
24 import org.apache.tools.ant.BuildEvent;
25 import org.apache.tools.ant.BuildListener;
26
27 /**
28 * Captures build events
29 *
30 */
31 public class MockBuildListener implements BuildListener {
32 private final Vector buildFinishedEvents = new Vector();
33 private final Vector buildStartedEvents = new Vector();
34 private final Vector messageLoggedEvents = new Vector();
35 private final Vector targetFinishedEvents = new Vector();
36 private final Vector targetStartedEvents = new Vector();
37 private final Vector taskFinishedEvents = new Vector();
38 private final Vector taskStartedEvents = new Vector();
39
40 /**
41 * Signals that the last target has finished. This event will still be
42 * fired if an error occurred during the build.
43 *
44 * @param event
45 * An event with any relevant extra information. Must not be
46 * <code>null</code>.
47 *
48 * @see BuildEvent#getException()
49 */
50 @Override
51 public void buildFinished(final BuildEvent event) {
52 this.buildFinishedEvents.addElement(event);
53 }
54
55 /**
56 * Signals that a build has started. This event is fired before any targets
57 * have started.
58 *
59 * @param event
60 * An event with any relevant extra information. Must not be
61 * <code>null</code>.
62 */
63 @Override
64 public void buildStarted(final BuildEvent event) {
65 this.buildStartedEvents.addElement(event);
66 }
67
68 public Vector getBuildFinishedEvents() {
69 return new Vector(this.buildFinishedEvents);
70 }
71
72 /**
73 * Gets a list of buildStarted events
74 *
75 * @return list of build started events
76 */
77 public Vector getBuildStartedEvents() {
78 return new Vector(this.buildStartedEvents);
79 }
80
81 /**
82 * Gets message logged events
83 *
84 * @return vector of "MessageLogged" events.
85 */
86 public Vector getMessageLoggedEvents() {
87 return new Vector(this.messageLoggedEvents);
88 }
89
90 /**
91 * Gets target finished events
92 *
93 * @return vector of "TargetFinished" events.
94 */
95 public Vector getTargetFinishedEvents() {
96 return new Vector(this.targetFinishedEvents);
97 }
98
99 /**
100 * Gets target started events
101 *
102 * @return vector of "TargetStarted" events.
103 */
104 public Vector getTargetStartedEvents() {
105 return new Vector(this.targetStartedEvents);
106 }
107
108 /**
109 * Gets task finished events
110 *
111 * @return vector of "TaskFinished" events.
112 */
113 public Vector getTaskFinishedEvents() {
114 return new Vector(this.taskFinishedEvents);
115 }
116
117 /**
118 * Gets task started events
119 *
120 * @return vector of "TaskStarted" events.
121 */
122 public Vector getTaskStartedEvents() {
123 return new Vector(this.taskStartedEvents);
124 }
125
126 /**
127 * Signals a message logging event.
128 *
129 * @param event
130 * An event with any relevant extra information. Must not be
131 * <code>null</code>.
132 *
133 * @see BuildEvent#getMessage()
134 * @see BuildEvent#getPriority()
135 */
136 @Override
137 public void messageLogged(final BuildEvent event) {
138 this.messageLoggedEvents.addElement(event);
139 }
140
141 /**
142 * Signals that a target has finished. This event will still be fired if an
143 * error occurred during the build.
144 *
145 * @param event
146 * An event with any relevant extra information. Must not be
147 * <code>null</code>.
148 *
149 * @see BuildEvent#getException()
150 */
151 @Override
152 public void targetFinished(final BuildEvent event) {
153 this.targetFinishedEvents.addElement(event);
154 }
155
156 /**
157 * Signals that a target is starting.
158 *
159 * @param event
160 * An event with any relevant extra information. Must not be
161 * <code>null</code>.
162 *
163 * @see BuildEvent#getTarget()
164 */
165 @Override
166 public void targetStarted(final BuildEvent event) {
167 this.targetStartedEvents.addElement(event);
168 }
169
170 /**
171 * Signals that a task has finished. This event will still be fired if an
172 * error occurred during the build.
173 *
174 * @param event
175 * An event with any relevant extra information. Must not be
176 * <code>null</code>.
177 *
178 * @see BuildEvent#getException()
179 */
180 @Override
181 public void taskFinished(final BuildEvent event) {
182 this.taskFinishedEvents.addElement(event);
183 }
184
185 /**
186 * Signals that a task is starting.
187 *
188 * @param event
189 * An event with any relevant extra information. Must not be
190 * <code>null</code>.
191 *
192 * @see BuildEvent#getTask()
193 */
194 @Override
195 public void taskStarted(final BuildEvent event) {
196 this.taskStartedEvents.addElement(event);
197 }
198 }