KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > BuildEvent


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant;
19
20 import java.util.EventObject JavaDoc;
21
22 /**
23  * Class representing an event occurring during a build. An
24  * event is built by specifying either a project, a task or a target.
25  * A project level event will only have a project reference;
26  * a target level event will have project and target references;
27  * a task level event will have project, target and task references.
28  *
29  */

30 public class BuildEvent extends EventObject JavaDoc {
31
32     /** Project which emitted the event. */
33     private Project project;
34     /** Target which emitted the event, if specified. */
35     private Target target;
36     /** Task which emitted the event, if specified. */
37     private Task task;
38     /**
39      * Message associated with the event. This is only used for
40      * "messageLogged" events.
41      */

42     private String JavaDoc message;
43     /**
44      * The priority of the message, for "messageLogged" events.
45      */

46     private int priority = Project.MSG_VERBOSE;
47     /**
48      * The exception associated with this event, if any.
49      * This is only used for "messageLogged", "taskFinished", "targetFinished",
50      * and "buildFinished" events.
51      */

52     private Throwable JavaDoc exception;
53
54     /**
55      * Construct a BuildEvent for a project level event.
56      *
57      * @param project the project that emitted the event.
58      * Should not be <code>null</code>.
59      */

60     public BuildEvent(Project project) {
61         super(project);
62         this.project = project;
63         this.target = null;
64         this.task = null;
65     }
66
67     /**
68      * Construct a BuildEvent for a target level event.
69      * The project associated with the event is derived
70      * from the given target.
71      *
72      * @param target the target that emitted the event.
73      * Must not be <code>null</code>.
74      */

75     public BuildEvent(Target target) {
76         super(target);
77         this.project = target.getProject();
78         this.target = target;
79         this.task = null;
80     }
81
82     /**
83      * Construct a BuildEvent for a task level event.
84      * The project and target associated with the event
85      * are derived from the given task.
86      *
87      * @param task the task that emitted the event.
88      * Must not be <code>null</code>.
89      */

90     public BuildEvent(Task task) {
91         super(task);
92         this.project = task.getProject();
93         this.target = task.getOwningTarget();
94         this.task = task;
95     }
96
97     /**
98      * Sets the message and priority associated with this event.
99      * This is used for "messageLogged" events.
100      *
101      * @param message the message to be associated with this event.
102      * Should not be <code>null</code>.
103      * @param priority the priority to be associated with this event,
104      * as defined in the {@link Project Project} class.
105      *
106      * @see BuildListener#messageLogged(BuildEvent)
107      */

108     public void setMessage(String JavaDoc message, int priority) {
109         this.message = message;
110         this.priority = priority;
111     }
112
113     /**
114      * Sets the exception associated with this event. This is used
115      * for "messageLogged", "taskFinished", "targetFinished", and "buildFinished"
116      * events.
117      *
118      * @param exception The exception to be associated with this event.
119      * May be <code>null</code>.
120      *
121      * @see BuildListener#messageLogged(BuildEvent)
122      * @see BuildListener#taskFinished(BuildEvent)
123      * @see BuildListener#targetFinished(BuildEvent)
124      * @see BuildListener#buildFinished(BuildEvent)
125      */

126     public void setException(Throwable JavaDoc exception) {
127         this.exception = exception;
128     }
129
130     /**
131      * Returns the project that fired this event.
132      *
133      * @return the project that fired this event
134      */

135     public Project getProject() {
136         return project;
137     }
138
139     /**
140      * Returns the target that fired this event.
141      *
142      * @return the project that fired this event, or <code>null</code>
143      * if this event is a project level event.
144      */

145     public Target getTarget() {
146         return target;
147     }
148
149     /**
150      * Returns the task that fired this event.
151      *
152      * @return the task that fired this event, or <code>null</code>
153      * if this event is a project or target level event.
154      */

155     public Task getTask() {
156         return task;
157     }
158
159     /**
160      * Returns the logging message. This field will only be set
161      * for "messageLogged" events.
162      *
163      * @return the message associated with this event, or <code>null</code>
164      * if no message has been set.
165      *
166      * @see BuildListener#messageLogged(BuildEvent)
167      */

168     public String JavaDoc getMessage() {
169         return message;
170     }
171
172     /**
173      * Returns the priority of the logging message. This field will only
174      * be set for "messageLogged" events. The meaning of this priority
175      * is as specified by the constants in the {@link Project Project} class.
176      *
177      * @return the priority associated with this event.
178      *
179      * @see BuildListener#messageLogged(BuildEvent)
180      */

181     public int getPriority() {
182         return priority;
183     }
184
185     /**
186      * Returns the exception that was thrown, if any. This field will only
187      * be set for "messageLogged", "taskFinished", "targetFinished", and "buildFinished"
188      * events.
189      *
190      * @return the exception associated with this exception, or
191      * <code>null</code> if no exception has been set.
192      *
193      * @see BuildListener#messageLogged(BuildEvent)
194      * @see BuildListener#taskFinished(BuildEvent)
195      * @see BuildListener#targetFinished(BuildEvent)
196      * @see BuildListener#buildFinished(BuildEvent)
197      */

198     public Throwable JavaDoc getException() {
199         return exception;
200     }
201 }
202
Popular Tags