Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: BuildEvent.php 173 2007-03-12 20:34:30Z hans $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information please see
19
 * <http://phing.info>.
20
 */
21
 
22
require_once 'phing/system/lang/EventObject.php';
23
 
24
/**
25
 * Encapsulates a build specific event.
26
 *
27
 * <p>We have three sources of events all handled by this class:
28
 *
29
 * <ul>
30
 *  <li>Project level events</li>
31
 *  <li>Target level events</li>
32
 *  <li>Task level events</li>
33
 * </ul>
34
 *
35
 * <p> Events are all fired from the project class by creating an event object
36
 * using this class and passing it to the listeners.
37
 *
38
 * @author    Andreas Aderhold <andi@binarycloud.com>
39
 * @author    Hans Lellelid <hans@xmpl.org>
40
 * @version   $Revision: 1.10 $
41
 * @package   phing
42
 */
43
class BuildEvent extends EventObject {
44
 
45
    /**
46
     * A reference to the project
47
     * @var Project
48
     */
49
    protected $project;
50
 
51
    /**
52
     * A reference to the target
53
     * @var Target
54
     */
55
    protected $target;
56
 
57
    /**
58
     * A reference to the task
59
     *
60
     * @var Task
61
     */
62
    protected $task;
63
 
64
    /**
65
     * The message of this event, if the event is a message
66
     * @var string
67
     */
68
    protected $message = null;
69
 
70
    /**
71
     * The priority of the message
72
     *
73
     * @var    string
74
     * @see    $message
75
     */
76
    protected $priority = Project::MSG_VERBOSE;
77
 
78
    /**
79
     * The execption that caused the event, if any
80
     *
81
     * @var    object
82
     */
83
    protected $exception = null;
84
 
85
    /**
86
     * Construct a BuildEvent for a project, task or target source event
87
     *
88
     * @param  object  project the project that emitted the event.
89
     */
90
    public function __construct($source) {
91
        parent::__construct($source);
92
        if ($source instanceof Project) {
93
            $this->project = $source;
94
            $this->target = null;
95
            $this->task = null;
96
        } elseif ($source instanceof Target) {
97
            $this->project = $source->getProject();
98
            $this->target = $source;
99
            $this->task = null;
100
        } elseif ($source instanceof Task) {
101
            $this->project = $source->getProject();
102
            $this->target = $source->getOwningTarget();
103
            $this->task = $source;
104
        } else {
105
            throw new Exception("Can not construct BuildEvent, unknown source given.");
106
        }
107
    }
108
 
109
    /**
110
     * Sets the message with details and the message priority for this event.
111
     *
112
     * @param  string   The string message of the event
113
     * @param  integer  The priority this message should have
114
     */
115
    public function setMessage($message, $priority) {
116
        $this->message = (string) $message;
117
        $this->priority = (int) $priority;
118
    }
119
 
120
    /**
121
     * Set the exception that was the cause of this event.
122
     *
123
     * @param  Exception The exception that caused the event
124
     */
125
    public function setException($exception) {
126
        $this->exception = $exception;
127
    }
128
 
129
    /**
130
     * Returns the project instance that fired this event.
131
     *
132
     * The reference to the project instance is set by the constructor if this
133
     * event was fired from the project class.
134
     *
135
     * @return  Project  The project instance that fired this event
136
     */
137
    public function getProject() {
138
        return $this->project;
139
    }
140
 
141
    /**
142
     * Returns the target instance that fired this event.
143
     *
144
     * The reference to the target instance is set by the constructor if this
145
     * event was fired from the target class.
146
     *
147
     * @return Target The target that fired this event
148
     */
149
    public function getTarget() {
150
        return $this->target;
151
    }
152
 
153
    /**
154
     * Returns the target instance that fired this event.
155
     *
156
     * The reference to the task instance is set by the constructor if this
157
     * event was fired within a task.
158
     *
159
     * @return Task The task that fired this event
160
     */
161
    public function getTask() {
162
        return $this->task;
163
    }
164
 
165
    /**
166
     * Returns the logging message. This field will only be set for
167
     * "messageLogged" events.
168
     *
169
     * @return string The log message
170
     */
171
    function getMessage() {
172
        return $this->message;
173
    }
174
 
175
    /**
176
     * Returns the priority of the logging message. This field will only
177
     * be set for "messageLogged" events.
178
     *
179
     * @return integer The message priority
180
     */
181
    function getPriority() {
182
        return $this->priority;
183
    }
184
 
185
    /**
186
     * Returns the exception that was thrown, if any.
187
     * This field will only be set for "taskFinished", "targetFinished", and
188
     * "buildFinished" events.
189
     *
190
     * @see BuildListener::taskFinished()
191
     * @see BuildListener::targetFinished()
192
     * @see BuildListener::buildFinished()
193
     * @return Exception
194
     */
195
    public function getException() {
196
        return $this->exception;
197
    }
198
}