next up previous contents index
Next: PatternSet Up: Core Types Previous: Filter Chains and Filter   Contents   Index

FilterSet

FilterSets are groups of filters. Filters can be defined as token-value pairs or be read in from a file. FilterSets can appear inside tasks that support this feature or at the same level as <target> - i.e., as children of <project>.

FilterSets support the id and refid attributes. You can define a FilterSet with an id attribute and then refer to that definition from another FilterSet with a refid attribute. It is also possible to nest filtersets into filtersets to get a set union of the contained filters.

In addition, FilterSets can specify begintoken and/or endtoken attributes to define what to match.

Filtersets are used for doing replacements in tasks such as <copy>, etc.

Filterset Attribute Description Default Required begintoken The string marking the beginning of a token (eg., @DATE@). @ No endtoken The string marking the end of a token (eg., @DATE@). @ No

Filter Attribute Description Required token The token to replace (eg., @DATE@) Yes value The value to replace it with (eg., Thursday, April 26, 2001). Yes

Filtersfile Attribute Description Required file A properties file of name-value pairs from which to load the tokens. Yes

Examples You are copying the version.txt file to the dist directory from the build directory but wish to replace the token @DATE@ with today's date.

<copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt">
  <filterset>
    <filter token="DATE" value="${TODAY}"/>
  </filterset>
</copy>

You are copying the version.txt file to the dist directory from the build directory but wish to replace the token

<copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt">
  <filterset begintoken="%" endtoken="*">
    <filter token="DATE" value="${TODAY}"/>
  </filterset>
</copy>
Copy all the docs but change all dates and appropriate notices as stored in a file.
<copy toDir="${dist.dir}/docs">
  <fileset dir="${build.dir}/docs">
    <include name="**/*.html">
  </fileset>
  <filterset begintoken="%" endtoken="*">
    <filtersfile file="${user.dir}/dist.properties"/>
  </filterset>
</copy>
Define a FilterSet and reference it later.
<filterset id="myFilterSet" begintoken="%" endtoken="*">
  <filter token="DATE" value="${TODAY}"/>
</filterset>

<copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt">
  <filterset refid="myFilterSet"/>
</copy>


next up previous contents index
Next: PatternSet Up: Core Types Previous: Filter Chains and Filter   Contents   Index
Andrew Marlow 2003-07-08