Search code examples
phing

phing get files in a directory and create a list of them for a xml file?


I'm triyng to create a generic phing script that will build a joomla plugin.

Each joomla plugin must hava an .xml file that is used by joomla system to install the plugin. In this xml file we need to define what files and folders our zip archive has like this:

<files>
   <folder>folder1</folder>
   <filename plugin="nameofplugin">nameofplugin.php</filename>
   <filename>index.html</filename>
</files>

Now, because I'm lazy and I don't want to do this thing always myself I want to have the phing script do this for me.

I have all the plugin files moved to a specific folder like this:

-pluginFolder

--folder1

--nameofplugin.php

--index.php

I see that I can use foreach like this:

<foreach param="dirname" absparam="absname" target="subtask">
        <fileset dir="${destination.dir}">
            <type type="file" />
            <depth max="0" min="0" />
        </fileset>
    </foreach>

<target name="subtask">
    <echo msg="<file>: ${dirname}" />
</target>

now here in the subtask I fail to figure out how to do merge all the files to a single variable so that I can then use replacetokens for example?

Any ideas about this? Should I build my own phing class that does this? Or is there an easy way to achieve this with what phing has to offer out of the box?


Solution

  • Ok, I managed to achieve what I wanted. I created a new phing task and made the replacement in there.

    You can see how it works on the base of this joomla plugin: https://github.com/compojoom/CUpdater

    The build.xml file is here:

    https://github.com/compojoom/CUpdater/blob/master/builds/plugin.xml

    and the task is here:

    https://github.com/compojoom/CUpdater/blob/master/builds/phingext/listjpackagefilestask.php