Search code examples
phing

how to iterate (loop) through directories in phing?


I want to create phing task for some plugins so the directory structure is something like

root
  - plugin1
    - index.php
  - plugin2
    - index.php

etc..

I want to run same tasks on each subdirectory - for example

  1. generate doc for plugin1
  2. run unit tests for plugin1
  3. deploy plugin1 somewhere
  4. generate doc for plugnin2 ...

Is this possible? I need something like

<foreach param="filename" absparam="absfilename" target="subtask">
  <fileset dir=".">
    <include name="*.php"/>
  </fileset>
</foreach>

but for directories.

Or do I have to write build.xml for each plugin standalone?

Thanks a lot.


Solution

  • Finally I discovered selectors which can solve my request:

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

    and call some task to do stuff

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