如何在phing属性中收集自定义phing任务的输出?

时间:2016-04-15 08:00:46

标签: phing

背景

我从这个开放式问题https://stackoverflow.com/questions/36602830/list-differences-between-two-directories-from-point-of-view-of-one-directory-by

开始

然后尝试使用phing的原生实用程序解决它,但卡住了 - How to return a value from a phing target?

现在我正在尝试根据https://www.phing.info/docs/guide/trunk/ch06s06.html编写自定义Phing任务。我尝试回显这里的文件列表,打算在从构建xml调用任务时以某种方式在属性中收集相同内容 -

<addedfiles message="Hello World" outputProperty="output"/>

但我发现build xml文件的调用不支持outputProperty属性。

有关如何执行此操作或其他两个问题的任何指示都会有很大帮助。

2 个答案:

答案 0 :(得分:0)

哦,很简单。我们可以在自定义任务类中设置一个属性,如下所示 -

$this->getProject()->setNewProperty('output', "hello world");

并且可以在任务调用之后在构建xml中访问它,如下所示 -

<addedfiles message="Hello World" />
<echo>See ${output}</echo>

答案 1 :(得分:0)

您可以改善您的解决方案

private $outputProperty;

public function setOutputProperty($str)
{
    $this->outputProperty = $str;
}

然后,当你捕获输出

$this->getProject()->setNewProperty($this->outputProperty, "hello world");