BuildEvent.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /*
  3. * $Id: BuildEvent.php 905 2010-10-05 16:28:03Z mrook $
  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. require_once 'phing/system/lang/EventObject.php';
  22. /**
  23. * Encapsulates a build specific event.
  24. *
  25. * <p>We have three sources of events all handled by this class:
  26. *
  27. * <ul>
  28. * <li>Project level events</li>
  29. * <li>Target level events</li>
  30. * <li>Task level events</li>
  31. * </ul>
  32. *
  33. * <p> Events are all fired from the project class by creating an event object
  34. * using this class and passing it to the listeners.
  35. *
  36. * @author Andreas Aderhold <andi@binarycloud.com>
  37. * @author Hans Lellelid <hans@xmpl.org>
  38. * @version $Revision: 905 $
  39. * @package phing
  40. */
  41. class BuildEvent extends EventObject {
  42. /**
  43. * A reference to the project
  44. * @var Project
  45. */
  46. protected $project;
  47. /**
  48. * A reference to the target
  49. * @var Target
  50. */
  51. protected $target;
  52. /**
  53. * A reference to the task
  54. *
  55. * @var Task
  56. */
  57. protected $task;
  58. /**
  59. * The message of this event, if the event is a message
  60. * @var string
  61. */
  62. protected $message = null;
  63. /**
  64. * The priority of the message
  65. *
  66. * @var string
  67. * @see $message
  68. */
  69. protected $priority = Project::MSG_VERBOSE;
  70. /**
  71. * The execption that caused the event, if any
  72. *
  73. * @var object
  74. */
  75. protected $exception = null;
  76. /**
  77. * Construct a BuildEvent for a project, task or target source event
  78. *
  79. * @param object project the project that emitted the event.
  80. */
  81. public function __construct($source) {
  82. parent::__construct($source);
  83. if ($source instanceof Project) {
  84. $this->project = $source;
  85. $this->target = null;
  86. $this->task = null;
  87. } elseif ($source instanceof Target) {
  88. $this->project = $source->getProject();
  89. $this->target = $source;
  90. $this->task = null;
  91. } elseif ($source instanceof Task) {
  92. $this->project = $source->getProject();
  93. $this->target = $source->getOwningTarget();
  94. $this->task = $source;
  95. } else {
  96. throw new Exception("Can not construct BuildEvent, unknown source given.");
  97. }
  98. }
  99. /**
  100. * Sets the message with details and the message priority for this event.
  101. *
  102. * @param string The string message of the event
  103. * @param integer The priority this message should have
  104. */
  105. public function setMessage($message, $priority) {
  106. $this->message = (string) $message;
  107. $this->priority = (int) $priority;
  108. }
  109. /**
  110. * Set the exception that was the cause of this event.
  111. *
  112. * @param Exception The exception that caused the event
  113. */
  114. public function setException($exception) {
  115. $this->exception = $exception;
  116. }
  117. /**
  118. * Returns the project instance that fired this event.
  119. *
  120. * The reference to the project instance is set by the constructor if this
  121. * event was fired from the project class.
  122. *
  123. * @return Project The project instance that fired this event
  124. */
  125. public function getProject() {
  126. return $this->project;
  127. }
  128. /**
  129. * Returns the target instance that fired this event.
  130. *
  131. * The reference to the target instance is set by the constructor if this
  132. * event was fired from the target class.
  133. *
  134. * @return Target The target that fired this event
  135. */
  136. public function getTarget() {
  137. return $this->target;
  138. }
  139. /**
  140. * Returns the target instance that fired this event.
  141. *
  142. * The reference to the task instance is set by the constructor if this
  143. * event was fired within a task.
  144. *
  145. * @return Task The task that fired this event
  146. */
  147. public function getTask() {
  148. return $this->task;
  149. }
  150. /**
  151. * Returns the logging message. This field will only be set for
  152. * "messageLogged" events.
  153. *
  154. * @return string The log message
  155. */
  156. function getMessage() {
  157. return $this->message;
  158. }
  159. /**
  160. * Returns the priority of the logging message. This field will only
  161. * be set for "messageLogged" events.
  162. *
  163. * @return integer The message priority
  164. */
  165. function getPriority() {
  166. return $this->priority;
  167. }
  168. /**
  169. * Returns the exception that was thrown, if any.
  170. * This field will only be set for "taskFinished", "targetFinished", and
  171. * "buildFinished" events.
  172. *
  173. * @see BuildListener::taskFinished()
  174. * @see BuildListener::targetFinished()
  175. * @see BuildListener::buildFinished()
  176. * @return Exception
  177. */
  178. public function getException() {
  179. return $this->exception;
  180. }
  181. }