Using Patternset With Fileset In Phing

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.

<patternset id="inc_files">
 <include name="**/*.php" />
 <include name="something/**" />
</patternset>
 
<patternset id="exc_files">
 <exclude name="**/*_test.php" />
 <exclude name="myProject_build/**" />
</patternset>

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

<fileset dir="./" id="myProjectFiles">
 <patternset refid="inc_files" />
 <patternset refid="exc_files" />
</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.

<fileset dir="./" id="myProjectFiles">
 <patternset refid="inc_files" />
 <patternset refid="exc_files" />
 <include name="**/bla*.php" />
</fileset>

Automated Build With Phing

Comments

thanks! better than the phing docs
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
3 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.