Using Patternset With Fileset In Phing

7th January 2009 - 2 minutes read time

When a project gets complicated then so to can the build.xml file associated with it. You might find it necessary to have multiple different filesets, each of which do something different, but all of which have the same core files that they use. Multiple filesets are useful if you want to create a version of your project with all of the testing files in place so that it can be tested by external developers.

Creating multiple filesets can create problems, one of which is maintenance. Confusion can also occur even if you have a single large fileset where lots of different rules for including and excluding files are defined.

This is where the patternset element comes in. You can create a set of reusable file lists that can be used by more than one fileset, but which also makes maintenance a little easier.

The following snippet shows two patternset elements that show include files and exclude files.

  1. <patternset id="inc_files">
  2. <include name="**/*.php" />
  3. <include name="something/**" />
  4. </patternset>
  5.  
  6. <patternset id="exc_files">
  7. <exclude name="**/*_test.php" />
  8. <exclude name="myProject_build/**" />
  9. </patternset>

This is then used by the fileset element in the following way.

  1. <fileset dir="./" id="myProjectFiles">
  2. <patternset refid="inc_files" />
  3. <patternset refid="exc_files" />
  4. </fileset>

Notice that the pattern set definition contains the id attribute, whereas the patternset within the fileset contains a refid attribute. The refid attribute must contain the name of a patternset, defined by using the id attribute.

You can also add in exclude and include elements into the fileset, along with any patternset elements.

  1. <fileset dir="./" id="myProjectFiles">
  2. <patternset refid="inc_files" />
  3. <patternset refid="exc_files" />
  4. <include name="**/bla*.php" />
  5. </fileset>

Automated Build With Phing

Comments

Permalink
thanks! better than the phing docs

smeo (Tue, 08/27/2013 - 14:05)

Add new comment

The content of this field is kept private and will not be shown publicly.