home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / tasks / system / ExitTask.php < prev    next >
Encoding:
PHP Script  |  2006-03-10  |  3.4 KB  |  119 lines

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