Search code examples
phpphing

Phing, call a command get its output into a property


I have a script that can lookup and output or write my current release # to a text file. Now the only problem is how do I get this version number into a PHING property.

Right now my PHING target builds build.zip and built.tar, I would like it to build build-1.0.0.zip or whatever the version script decides the current version is. How can I do this? Will I have to create my own "task"?


Solution

  • You might need to create your own task for this. The task may look something like...

    <?php
    require_once "phing/Task.php";
    
    class VersionNumberTask extends Task
    {
        private $versionprop;
    
        public function setVersionProp($versionprop)
        {
            $this->versionprop = $versionprop;
        }
    
        public function init()
        {
        }
    
        public function main()
        {
            // read the version text file in to a variable
            $version = file_get_contents("version.txt");
            $this->project->setProperty($this->versionprop, $version);
        }
    }
    

    Then you would define the task in your build xml

    <taskdef classname="VersionNumberTask" name="versiontask" />
    

    Then call the task

    <target name="dist">
        <versiontask versionprop="version.number"/>
    </target>
    

    At this point, you should be able to access the version number using ${version.number} throughout your build xml.

    Hope this helps!