Search code examples
return-valuetargetphing

Return value when internally calling target with phing/phingcall


I am calling a target by means of phingcall command. I want to pass back a status variable from the called target or at least change the existing value from the calling target. Goal: I want to branch in my main target controlling logic if the sub target fails which I indicate with a property. The code below does not work. Any idea how to make it work or an altertive approach for my goal?

Thanks, Juergen

<target name="main">
    <echo>target a</echo>
    <echo>${bOk}</echo>
    <exec command="echo 1" outputProperty="bOk" />
    <echo>bOk is 1: ${bOk}</echo>
    <phingcall inheritRefs="true" target="sub">
    </phingcall>
    <echo>bOk should now be 0: ${bOk}</echo>
</target>

<target name="sub">
    <echo>target b</echo>
    <echo>bOk is 1: ${bOk}</echo>
    <exec command="echo 0" outputProperty="bOk" />
    <echo>bOk now is 0: ${bOk}</echo>
</target>

The problem here is that

   <echo>bOk should now be 0: ${bOk}</echo>

echos

   bOk should now be 0: 1

Solution

  • Even with the great help of #phing IRC I couldn't solve the problem. I decided to write a custom task to account for data passing between targets:

    <?php
    
    require_once "phing/Task.php";
    
    class rvGlobalTask extends Task {
    
        private static $bOk = 1;
        private $sMode = null;
        private $bValue = null;
        private $outputProperty = null;
    
        public function setSMode( $sMode ) {
            $this->sMode = $sMode;
        }
        public function setBValue( $bValue ) {
            $this->bValue = $bValue;
        }
        public function setOutputProperty( $outputProperty ) {
            $this->outputProperty = $outputProperty;
        }
    
        public function main() {
            if ( $this->sMode == "set" ) {
                rvGlobalTask::$bOk = $this->bValue;
            } else {
                $this->project->setProperty(
                    $this->outputProperty,
                    rvGlobalTask::$bOk
                );
            }
        }
    }
    ?>
    

    This works fine for my problem. Perhaps someone else finds this useful as well.