Search code examples
phing

How to collect output of a custom phing task in a phing property?


Background

I started with this open ended question https://stackoverflow.com/questions/36602830/list-differences-between-two-directories-from-point-of-view-of-one-directory-by

Then tried this to solve it using phing's native utilities, but got stuck - How to return a value from a phing target?

Now I am trying to write a custom Phing task, as per https://www.phing.info/docs/guide/trunk/ch06s06.html. I tried echoing the list of files in this, with an intention to somehow collect the same in a property when the task is called from the build xml -

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

But I found that an outputProperty attribute is not supported in the call from the build xml file.

Any pointers on how to do this, or to the other two questions would help a lot.


Solution

  • Oh it is simple. We can set a property within the custom task class like this -

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

    and it can be accessed in the build xml, after the task call, like this -

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