source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/BuildEvent.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 6.3 KB
Line 
1/*
2 * Copyright 2000,2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant;
18
19import java.util.EventObject;
20
21/**
22 * Class representing an event occurring during a build. An
23 * event is built by specifying either a project, a task or a target.
24 * A project level event will only have a project reference;
25 * a target level event will have project and target references;
26 * a task level event will have project, target and task references.
27 *
28 */
29public class BuildEvent extends EventObject {
30
31 /** Project which emitted the event. */
32 private Project project;
33 /** Target which emitted the event, if specified. */
34 private Target target;
35 /** Task which emitted the event, if specified. */
36 private Task task;
37 /**
38 * Message associated with the event. This is only used for
39 * "messageLogged" events.
40 */
41 private String message;
42 /**
43 * The priority of the message, for "messageLogged" events.
44 */
45 private int priority = Project.MSG_VERBOSE;
46 /**
47 * The exception associated with this event, if any.
48 * This is only used for "taskFinished", "targetFinished",
49 * and "buildFinished" events.
50 */
51 private Throwable exception;
52
53 /**
54 * Construct a BuildEvent for a project level event.
55 *
56 * @param project the project that emitted the event.
57 * Should not be <code>null</code>.
58 */
59 public BuildEvent(Project project) {
60 super(project);
61 this.project = project;
62 this.target = null;
63 this.task = null;
64 }
65
66 /**
67 * Construct a BuildEvent for a target level event.
68 * The project associated with the event is derived
69 * from the given target.
70 *
71 * @param target the target that emitted the event.
72 * Must not be <code>null</code>.
73 */
74 public BuildEvent(Target target) {
75 super(target);
76 this.project = target.getProject();
77 this.target = target;
78 this.task = null;
79 }
80
81 /**
82 * Construct a BuildEvent for a task level event.
83 * The project and target associated with the event
84 * are derived from the given task.
85 *
86 * @param task the task that emitted the event.
87 * Must not be <code>null</code>.
88 */
89 public BuildEvent(Task task) {
90 super(task);
91 this.project = task.getProject();
92 this.target = task.getOwningTarget();
93 this.task = task;
94 }
95
96 /**
97 * Sets the message and priority associated with this event.
98 * This is used for "messageLogged" events.
99 *
100 * @param message the message to be associated with this event.
101 * Should not be <code>null</code>.
102 * @param priority the priority to be associated with this event,
103 * as defined in the {@link Project Project} class.
104 *
105 * @see BuildListener#messageLogged(BuildEvent)
106 */
107 public void setMessage(String message, int priority) {
108 this.message = message;
109 this.priority = priority;
110 }
111
112 /**
113 * Sets the exception associated with this event. This is used
114 * for "taskFinished", "targetFinished", and "buildFinished"
115 * events.
116 *
117 * @param exception The exception to be associated with this event.
118 * May be <code>null</code>.
119 *
120 * @see BuildListener#taskFinished(BuildEvent)
121 * @see BuildListener#targetFinished(BuildEvent)
122 * @see BuildListener#buildFinished(BuildEvent)
123 */
124 public void setException(Throwable exception) {
125 this.exception = exception;
126 }
127
128 /**
129 * Returns the project that fired this event.
130 *
131 * @return the project that fired this event
132 */
133 public Project getProject() {
134 return project;
135 }
136
137 /**
138 * Returns the target that fired this event.
139 *
140 * @return the project that fired this event, or <code>null</code>
141 * if this event is a project level event.
142 */
143 public Target getTarget() {
144
145 return target;
146 }
147
148 /**
149 * Returns the task that fired this event.
150 *
151 * @return the task that fired this event, or <code>null</code>
152 * if this event is a project or target level event.
153 */
154 public Task getTask() {
155 return task;
156 }
157
158 /**
159 * Returns the logging message. This field will only be set
160 * for "messageLogged" events.
161 *
162 * @return the message associated with this event, or <code>null</code>
163 * if no message has been set.
164 *
165 * @see BuildListener#messageLogged(BuildEvent)
166 */
167 public String getMessage() {
168 return message;
169 }
170
171 /**
172 * Returns the priority of the logging message. This field will only
173 * be set for "messageLogged" events. The meaning of this priority
174 * is as specified by the constants in the {@link Project Project} class.
175 *
176 * @return the priority associated with this event.
177 *
178 * @see BuildListener#messageLogged(BuildEvent)
179 */
180 public int getPriority() {
181 return priority;
182 }
183
184 /**
185 * Returns the exception that was thrown, if any. This field will only
186 * be set for "taskFinished", "targetFinished", and "buildFinished"
187 * events.
188 *
189 * @return the exception associated with this exception, or
190 * <code>null</code> if no exception has been set.
191 *
192 * @see BuildListener#taskFinished(BuildEvent)
193 * @see BuildListener#targetFinished(BuildEvent)
194 * @see BuildListener#buildFinished(BuildEvent)
195 */
196 public Throwable getException() {
197 return exception;
198 }
199}
Note: See TracBrowser for help on using the repository browser.