Concepts and Types - TypesFilterSetFilterSetFilterSets are groups of filters. Filters can be defined as token-valuepairs 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., aschildren 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 FilterSetwith a refid attribute. It is also possible to nestfiltersets into filtersets to get a set union of the containedfilters. In addition, FilterSets can specifybegintoken and/or endtoken attributes to define what to match. Filtersets are used for doing replacements in tasks such as <copy> , etc. If you specify multiple values for the same token, the last one defined within a filterset will be used. Note: When a filterset is used in an operation, the files are processed in text mode and the filters applied line by line. This means thatthe copy operations will typically corrupt binary files. When applying filtersyou should ensure that the set of files being filtered are all text files. 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 | filtersfile | Specify a single filtersfile. | none | No | recurse | Indicates whether the replacement text of tokens should be searched for more tokens. Since Ant 1.6.3 | true | No | onmissingfiltersfile | Indicate behavior when a nonexistent filtersfile is specified. One of "fail", "warn", "ignore". Since Ant 1.7 | "fail" | 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 | ExamplesYou 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 %DATE* with today's date. <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> |