ExitTask.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. * $Id: ExitTask.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/Task.php';
  22. /**
  23. * Exits the active build, giving an additional message
  24. * if available.
  25. *
  26. * @author Hans Lellelid <hans@xmpl.org> (Phing)
  27. * @author Nico Seessle <nico@seessle.de> (Ant)
  28. * @version $Revision: 905 $
  29. * @package phing.tasks.system
  30. */
  31. class ExitTask extends Task {
  32. private $message;
  33. private $ifCondition;
  34. private $unlessCondition;
  35. /**
  36. * A message giving further information on why the build exited.
  37. *
  38. * @param string $value message to output
  39. */
  40. public function setMsg($value) {
  41. $this->setMessage($value);
  42. }
  43. /**
  44. * A message giving further information on why the build exited.
  45. *
  46. * @param value message to output
  47. */
  48. public function setMessage($value) {
  49. $this->message = $value;
  50. }
  51. /**
  52. * Only fail if a property of the given name exists in the current project.
  53. * @param c property name
  54. */
  55. public function setIf($c) {
  56. $this->ifCondition = $c;
  57. }
  58. /**
  59. * Only fail if a property of the given name does not
  60. * exist in the current project.
  61. * @param c property name
  62. */
  63. public function setUnless($c) {
  64. $this->unlessCondition = $c;
  65. }
  66. /**
  67. * @throws BuildException
  68. */
  69. public function main() {
  70. if ($this->testIfCondition() && $this->testUnlessCondition()) {
  71. if ($this->message !== null) {
  72. throw new BuildException($this->message);
  73. } else {
  74. throw new BuildException("No message");
  75. }
  76. }
  77. }
  78. /**
  79. * Set a multiline message.
  80. */
  81. public function addText($msg) {
  82. if ($this->message === null) {
  83. $this->message = "";
  84. }
  85. $this->message .= $this->project->replaceProperties($msg);
  86. }
  87. /**
  88. * @return boolean
  89. */
  90. private function testIfCondition() {
  91. if ($this->ifCondition === null || $this->ifCondition === "") {
  92. return true;
  93. }
  94. return $this->project->getProperty($this->ifCondition) !== null;
  95. }
  96. /**
  97. * @return boolean
  98. */
  99. private function testUnlessCondition() {
  100. if ($this->unlessCondition === null || $this->unlessCondition === "") {
  101. return true;
  102. }
  103. return $this->project->getProperty($this->unlessCondition) === null;
  104. }
  105. }