2

我正在通过 phingcall 命令调用目标。我想从被调用目标传回一个状态变量,或者至少从调用目标更改现有值。目标:如果子目标失败,我想在我的主目标控制逻辑中分支,我用一个属性表示。下面的代码不起作用。知道如何使它发挥作用或实现我的目标的替代方法吗?

谢谢,于尔根

<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>

这里的问题是

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

回声

   bOk should now be 0: 1
4

2 回答 2

3

即使在#phing IRC 的大力帮助下,我也无法解决问题。我决定编写一个自定义任务来说明目标之间的数据传递:

<?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
            );
        }
    }
}
?>

这对我的问题很有效。也许其他人也觉得这很有用。

于 2011-07-22T19:03:48.280 回答
2

以下是使用 ExecTask 捕获输出的方法。

<?xml version="1.0" encoding="UTF-8"?>
<project name="example" default="check-composer">

    <!-- set a property to contain the output -->
    <property name="whichComposer" value="" />

    <!-- check if composer (getcomposer.org) is installed globally -->
    <target name="check-composer">
        <!-- put the output of "which" in our property -->
        <exec command="which composer" outputProperty="whichComposer" />

        <!-- act on what we found out -->
        <if>
            <contains string="${whichComposer}" substring="composer" />
            <then>
                <echo>Composer installed at ${whichComposer}</echo>
            </then>
            <else>
                <echo message="better install composer. ${whichComposer}"/>
            </else>
        </if>
    </target>

</project>
于 2012-09-14T21:04:33.703 回答