How to return value from phing ad-hoc special task?

Is there a way to get the return value from a special phing task?

For example, I am trying to get the version number from a JSON string in a file as follows:

<target name="get-app-version"> <adhoc-task name="appversion" ><![CDATA[ class AppversionTask extends Task { private $version; public function getVersion() { return $this->version; } function main() { $manifest = file_get_contents("manifest.json"); $manifest_json = json_decode($manifest); $version = $manifest_json->version; $this->log("App version: " . $version); $this->version = $version; } } ]]></adhoc-task> <appversion output="version" /> <echo message="${version}" /> </target> 

I can find documentation on setting values, but not getting values. However, the adhoc typdef task seems to show the get syntax, so I'm wondering if there is a way to do this.

+6
source share
1 answer

I am not sure if I fully understand. It sounds, not installation

$this->version

you should call instead

$this->project->setProperty('version', $version);

This will add the "version" property to your project instance. You will not need to set an attribute for your task, if you do not say, you will want to change later what property name will be set in your project (from the "version" to some other property).

`

 <adhoc-task name="appversion" ><![CDATA[ class AppversionTask extends Task { function main() { $manifest = file_get_contents("manifest.json"); $manifest_json = json_decode($manifest); $version = $manifest_json->version; $this->log("App version: " . $version); $this->project->setProperty('version', $version); } } ]]></adhoc-task> <appversion /> <!-- The version property should now be set --> <echo message="${version}" /> 

`

+12
source

Source: https://habr.com/ru/post/945814/


All Articles