Changeset 299

Show
Ignore:
Timestamp:
11/08/07 20:31:19 (1 year ago)
Author:
hans
Message:

Fixes #181 - make PhingCallTask default to halting on failure.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.3/classes/phing/tasks/system/PhingCallTask.php

    r144 r299  
    11<?php 
    22/* 
    3  *  $Id$   
    4  *  
     3 *  $Id$ 
     4 * 
    55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    66 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     
    2525 * Call another target in the same project. 
    2626 * 
    27  *   <pre
     27 * <samp
    2828 *    <target name="foo"> 
    2929 *      <phingcall target="bar"> 
     
    3636 *      <echo message="prop is ${property1} ${foo}" /> 
    3737 *    </target> 
    38  * </pre
     38 * </samp
    3939 * 
    40  * <p>This only works as expected if neither property1 nor foo are 
    41  *  defined in the project itself. 
     40 * This only works as expected if neither property1 nor foo are defined in the project itself. 
    4241 * 
    4342 * @author    Andreas Aderhold <andi@binarycloud.com> 
     
    4948class PhingCallTask extends Task { 
    5049 
    51     private $callee; 
    52     private $subTarget; 
    53     // must match the default value of PhingTask#inheritAll 
    54     private $inheritAll = true; 
    55     // must match the default value of PhingTask#inheritRefs 
    56     private $inheritRefs = false; 
     50        /** 
     51         * The called Phing task. 
     52         * 
     53         * @var PhingTask 
     54         */ 
     55       private $callee; 
    5756 
    58     /** 
    59      *  If true, pass all properties to the new Phing project. 
    60      *  Defaults to true. Future use. 
    61      *  @param boolean new value 
    62      */ 
    63     function setInheritAll($inherit) { 
    64         $this->inheritAll = (boolean) $inherit; 
    65     } 
     57        /** 
     58         * The target to call. 
     59         * 
     60         * @var string 
     61         */ 
     62        private $subTarget; 
    6663 
    67     /** 
    68      *  If true, pass all references to the new Phing project. 
    69      *  Defaults to false. Future use. 
    70     * 
    71      *  @param boolean new value 
    72      */ 
    73     function setInheritRefs($inheritRefs) { 
    74         $this->inheritRefs = (boolean) $inheritRefs; 
    75     } 
     64        /** 
     65         * Whether to inherit all properties from current project. 
     66         * 
     67         * @var boolean 
     68         */ 
     69        private $inheritAll = true; 
    7670 
    77     /** 
    78      *  init this task by creating new instance of the phing task and 
    79      *  configuring it's by calling its own init method. 
    80      */ 
    81     function init() { 
    82         $this->callee = $this->project->createTask("phing"); 
    83         $this->callee->setOwningTarget($this->getOwningTarget()); 
    84         $this->callee->setTaskName($this->getTaskName()); 
    85         $this->callee->setLocation($this->getLocation()); 
    86         $this->callee->init(); 
    87     } 
     71        /** 
     72         * Whether to inherit refs from current project. 
     73         * 
     74         * @var boolean 
     75         */ 
     76        private $inheritRefs = false; 
    8877 
    89     /** 
    90      *  hand off the work to the phing task of ours, after setting it up 
    91      *  @throws BuildException on validation failure or if the target didn't 
    92      *  execute 
    93      */ 
    94     function main() {         
    95              
    96         $this->log("Running PhingCallTask for target '" . $this->subTarget . "'", Project::MSG_DEBUG); 
    97         if ($this->callee === null) { 
    98             $this->init(); 
    99         } 
     78        /** 
     79         *  If true, pass all properties to the new Phing project. 
     80         *  Defaults to true. Future use. 
     81         *  @param boolean new value 
     82         */ 
     83        function setInheritAll($inherit) { 
     84                $this->inheritAll = (boolean) $inherit; 
     85        } 
    10086 
    101         if ($this->subTarget === null) { 
    102             throw new BuildException("Attribute target is required.", $this->location); 
    103         } 
    104          
    105         $this->callee->setPhingfile($this->project->getProperty("phing.file")); 
    106         $this->callee->setTarget($this->subTarget); 
    107         $this->callee->setInheritAll($this->inheritAll); 
    108         $this->callee->setInheritRefs($this->inheritRefs); 
    109         $this->callee->main(); 
    110     } 
     87        /** 
     88         *  If true, pass all references to the new Phing project. 
     89         *  Defaults to false. Future use. 
     90         * 
     91         *  @param boolean new value 
     92         */ 
     93        function setInheritRefs($inheritRefs) { 
     94                $this->inheritRefs = (boolean) $inheritRefs; 
     95        } 
    11196 
    112     /** 
    113      * Alias for createProperty 
    114      * @see createProperty() 
    115      */ 
    116     function createParam() { 
    117         if ($this->callee === null) { 
    118             $this->init(); 
    119         } 
    120         return $this->callee->createProperty(); 
    121     } 
    122      
    123     /** 
    124      * Property to pass to the invoked target. 
    125      */ 
    126     function createProperty() { 
    127         if ($this->callee === null) { 
    128             $this->init(); 
    129         } 
    130         return $this->callee->createProperty(); 
    131     } 
     97        /** 
     98         * Alias for createProperty 
     99         * @see createProperty() 
     100         */ 
     101        function createParam() { 
     102                if ($this->callee === null) { 
     103                        $this->init(); 
     104                } 
     105                return $this->callee->createProperty(); 
     106        } 
    132107 
    133     /** 
    134      * Target to execute, required. 
    135      */ 
    136     function setTarget($target) { 
    137         $this->subTarget = (string) $target; 
    138     } 
     108        /** 
     109         * Property to pass to the invoked target. 
     110         */ 
     111        function createProperty() { 
     112                if ($this->callee === null) { 
     113                        $this->init(); 
     114                } 
     115                return $this->callee->createProperty(); 
     116        } 
     117 
     118        /** 
     119         * Target to execute, required. 
     120         */ 
     121        function setTarget($target) { 
     122                $this->subTarget = (string) $target; 
     123        } 
     124 
     125        /** 
     126         *  init this task by creating new instance of the phing task and 
     127         *  configuring it's by calling its own init method. 
     128         */ 
     129        function init() { 
     130                $this->callee = $this->project->createTask("phing"); 
     131                $this->callee->setOwningTarget($this->getOwningTarget()); 
     132                $this->callee->setTaskName($this->getTaskName()); 
     133                $this->callee->setHaltOnFailure(true); 
     134                $this->callee->setLocation($this->getLocation()); 
     135                $this->callee->init(); 
     136        } 
     137 
     138        /** 
     139         *  hand off the work to the phing task of ours, after setting it up 
     140         *  @throws BuildException on validation failure or if the target didn't 
     141         *  execute 
     142         */ 
     143        function main() { 
     144 
     145                $this->log("Running PhingCallTask for target '" . $this->subTarget . "'", Project::MSG_DEBUG); 
     146                if ($this->callee === null) { 
     147                        $this->init(); 
     148                } 
     149 
     150                if ($this->subTarget === null) { 
     151                        throw new BuildException("Attribute target is required.", $this->getLocation()); 
     152                } 
     153 
     154                $this->callee->setPhingfile($this->project->getProperty("phing.file")); 
     155                $this->callee->setTarget($this->subTarget); 
     156                $this->callee->setInheritAll($this->inheritAll); 
     157                $this->callee->setInheritRefs($this->inheritRefs); 
     158                $this->callee->main(); 
     159        } 
     160 
    139161}