The IzPack selector for the FileSet concept has been adapted from the Apache Ant Selector core type. The functionality has been reduced to the satisfy the needs of IzPack.
Selectors are a mechanism whereby the files that make up a fileset can be selected using more criteria than the file name provided by the <include> and <exclude> tags.
A selector is an element of FileSet, and appears within it. It can also be defined outside of any target by using the <selector> tag and then used as a reference.
Different selectors have different attributes. Some selectors can contain other selectors, and these are called Selector Containers.
Core selectors can be used within a fileset and can be contained within Selector Containers.
The core selectors are:
The <contains> tag in a FileSet limits the files defined by that fileset to only those which contain the string specified by the text attribute.
Attribute | Description | Required |
text | Specifies the text that every file must contain | Yes |
casesensitive | Whether to pay attention to case when looking for the string in the text attribute. Default is true. | No |
ignorewhitespace | Whether to eliminate whitespace before checking for the string in the text attribute. Default is false. | No |
Here is an example of how to use the Contains Selector:
<fileset dir="${doc.path}" includes="**/*.html"> <contains text="script" casesensitive="no"/> </fileset> |
Selects all the HTML files that contain the string script.
The <date> tag in a FileSet will put a limit on the files specified by the include tag, so that tags whose last modified date does not meet the date limits specified by the selector will not end up being selected.
Attribute | Description | Required |
---|---|---|
datetime | Specifies the date and time to test for. Should be in the format MM/DD/YYYY HH:MM AM_or_PM, or an alternative pattern specified via the pattern attribute. | At least one of the two. |
millis | The number of milliseconds since 1970 that should be tested for. It is usually much easier to use the datetime attribute. | |
when | Indicates how to interpret the date, whether the files to be selected are those whose last modified times should be before, after, or equal to the specified value. Acceptable values for this attribute are:
| No |
granularity | The number of milliseconds leeway to use when comparing file modification times. This is needed because not every file system supports tracking the last modified time to the millisecond level. Default is 0 milliseconds, or 2 seconds on DOS systems. | No |
pattern | The SimpleDateFormat-compatible pattern to use when interpreting the datetime attribute. | No |
checkdirs | Indicates whether or not to check dates on directories. | No, defaults to false |
Here is an example of how to use the Date Selector:
<fileset dir="${jar.path}" includes="**/*.jar"> <date datetime="01/01/2001 12:00 AM" when="before"/> </fileset> |
Selects all JAR files which were last modified before midnight January 1, 2001.
The <depend> tag selects files whose last modified date is later than another, equivalent file in another location.
The <depend> tag supports the use of a contained <mapper> element to define the location of the file to be compared against. If no <mapper> element is specified, the identity type mapper is used.
The <depend> selector is case-sensitive.
Attribute | Description | Required |
---|---|---|
targetdir | The base directory to look for the files to compare against. The precise location depends on a combination of this attribute and the <mapper> element, if any. | Yes |
granularity | The number of milliseconds leeway to give before deciding a file is out of date. This is needed because not every file system supports tracking the last modified time to the millisecond level. Default is 0 milliseconds, or 2 seconds on DOS systems. | No |
Here is an example of how to use the Depend Selector:
<fileset dir="${ant.1.5}/src/main" includes="**/*.java"> <depend targetdir="${ant.1.4.1}/src/main"/> </fileset> |
Selects all the Java source files which were modified in the 1.5 release.
The <depth> tag selects files based on how far down they are stored in the directory structure in relation to the base directory of the fileset.
Attribute | Description | Required |
---|---|---|
min | The minimum number of directory levels below the base directory that a file must be in order to be selected. Default is 0. | At least one of the two. |
max | The maximum number of directory levels below the base directory that a file can be and still be selected. Default is no limit. |
Here is an example of how to use the Depth Selector:
<fileset dir="${doc.path}" includes="**/*"> <depth max="1"/> </fileset> |
Selects all files in the base directory and one directory below that.
The<different>tag selects files who are deemed to be 'different' from another, equivalent file in another location. The rules for determining difference between two files are as follows:
This is a useful selector to work with programs and tasks that don't handle dependency checking properly; Even if a predecessor task always creates its output files, followup tasks can be driven off copies made with a different selector, so their dependencies are driven on the absolute state of the files, not just a timestamp. For example: anything fetched from a web site, or the output of some program. To reduce the amount of checking, when using this task inside a <copy> task, set the preservelastmodified to propagate the timestamp from source file to destination file.
The <different> tag supports the use of a contained <mapper> element to define the location of the file to be compared against. If no <mapper> element is specified, the identity type mapper is used.
Attribute | Description | Required |
---|---|---|
targetdir | The base directory to look for the files to compare against. The precise location depends on a combination of this attribute and the <mapper> element, if any. | Yes |
ignoreFileTimes | Whether to use file times in the comparison or not. Default is true (time differences are ignored). | No |
ignoreContents | Whether to do a byte per byte compare. Default is false (contents are compared). | No |
granularity | The number of milliseconds leeway to give before deciding a file is out of date. This is needed because not every file system supports tracking the last modified time to the millisecond level. Default is 0 milliseconds, or 2 seconds on DOS systems. | No |
Here is an example of how to use the Different Selector:
<fileset dir="${ant.1.5}/src/main" includes="**/*.java"> <different targetdir="${ant.1.4.1}/src/main" ignoreFileTimes="true"/> </fileset> |
Compares all the Java source files between the 1.4.1 and the 1.5 release and selects those who are different, disregarding file times.
The <filename> tag acts like the <include> and <exclude> tags within a fileset. By using a selector instead, however, one can combine it with all the other selectors using whatever selector container is desired.
The <filename> selector is case-sensitive.
Attribute | Description | Required |
---|---|---|
name | The name of files to select. The name parameter can contain standard wildcard characters. | Yes |
casesensitive | Whether to pay attention to case when looking at file names. Default is "true". | No |
negate | Whether to reverse the effects of this filename selection, therefore emulating an exclude rather than include tag. Default is "false". | No |
Here is an example of how to use the Filename Selector:
<fileset dir="${doc.path}" includes="**/*"> <filename name="**/*.css"/> </fileset> |
Selects all the cascading style sheet files.
The <present> tag selects files that have an equivalent file in another directory tree.
The <present> tag supports the use of a contained <mapper> element to define the location of the file to be tested against. If no <mapper> element is specified, the identity type mapper is used.
The <present> selector is case-sensitive.
Attribute | Description | Required |
---|---|---|
targetdir | The base directory to look for the files to compare against. The precise location depends on a combination of this attribute and the <mapper> element, if any. | Yes |
present | Whether we are requiring that a file is present in the src directory tree only, or in both the src and the target directory tree. Valid values are:
| No |
Here is an example of how to use the Present Selector:
<fileset dir="${ant.1.5}/src/main" includes="**/*.java"> <present present="srconly" targetdir="${ant.1.4.1}/src/main"/> </fileset> |
Selects all the Java source files which are new in the 1.5 release.
The <containsregexp> tag in a FileSet limits the files defined by that fileset to only those which contain a match to the regular expression specified by the expression attribute.
Attribute | Description | Required |
---|---|---|
expression | Specifies the regular expression that must match true in every file | Yes |
Here is an example of how to use the regular expression Selector:
<fileset dir="${doc.path}" includes="*.txt"> <containsregexp expression="[4-6]\.[0-9]"/> </fileset> |
Selects all the text files that match the regular expression (have a 4,5 or 6 followed by a period and a number from 0 to 9).
The <size> tag in a FileSet will put a limit on the files specified by the include tag, so that tags which do not meet the size limits specified by the selector will not end up being selected.
Attribute | Description | Required |
---|---|---|
value | The size of the file which should be tested for. | Yes |
units | The units that the value attribute is expressed in. When using the standard single letter SI designations, such as "k","M", or "G", multiples of 1000 are used. If you want to use power of 2 units, use the IEC standard: "Ki" for 1024, "Mi" for 1048576, and so on. The default is no units which means the value attribute expresses the exact number of bytes. | No |
when | Indicates how to interpret the size, whether the files to be selected should be larger, smaller, or equal to that value. Acceptable values for this attribute are:
| No |
Here is an example of how to use the Size Selector:
<fileset dir="${jar.path}"> <patternset> <include name="**/*.jar"/> </patternset> <size value="4" units="Ki" when="more"/> </fileset> |
Selects all JAR files that are larger than 4096 bytes.
The <type> tag selects files of a certain type: directory or regular.
Attribute | Description | Required |
---|---|---|
type | The type of file which should be tested for. Acceptable values are:
| Yes |
Here is an example of how to use the Type Selector to select only directories in \${src}:
<fileset dir="${src}"> <type type="dir"/> </fileset> |
The Type Selector can be used in conjunction with other selectors. For example, to select files that also exist in a template directory, but avoid selecting empty directories, use:
<fileset dir="${src}"> <and> <present targetdir="template"/> <type type="file"/> </and> </fileset> |
To create more complex selections, a variety of selectors that contain other selectors are available for your use. They combine the selections of their child selectors in various ways.
The selector containers are:
All selector containers can contain any other selector, including other containers, as an element. Using containers, the selector tags can be arbitrarily deep. Here is a complete list of allowable selector elements within a container:
The <and> tag selects files that are selected by all of the elements it contains. It returns as soon as it finds a selector that does not select the file, so it is not guaranteed to check every selector.
Here is an example of how to use the And Selector:
<fileset dir="${dist}" includes="**/*.jar"> <and> <size value="4" units="Ki" when="more"/> <date datetime="01/01/2001 12:00 AM" when="before"/> </and> </fileset> |
Selects all the JAR file larger than 4096 bytes which haven't been update since the last millenium.
The <majority> tag selects files provided that a majority of the contained elements also select it. Ties are dealt with as specified by the allowtie attribute.
Attribute | Description | Required |
allowtie | Whether files should be selected if there are an even number of selectors selecting them as are not selecting them. Default is true. | No |
Here is an example of how to use the Majority Selector:
<fileset dir="${docs}" includes="**/*.html"> <majority> <contains text="project" casesensitive="false"/> <contains text="taskdef" casesensitive="false"/> <contains text="IntrospectionHelper" casesensitive="true"/> </majority> </fileset> |
Selects all the HTML files which contain at least two of the three phrases "project", "taskdef", and "IntrospectionHelper" (this last phrase must match case exactly).
The <none> tag selects files that are not selected by any of the elements it contains. It returns as soon as it finds a selector that selects the file, so it is not guaranteed to check every selector.
Here is an example of how to use the None Selector:
<fileset dir="${src}" includes="**/*.java"> <none> <present targetdir="${dest}"/> <present targetdir="${dest}"> <mapper type="glob" from="*.java" to="*.class"/> </present> </none> </fileset> |
Selects only Java files which do not have equivalent java or class files in the dest directory.
The <or> tag selects files that are selected by any one of the elements it contains. It returns as soon as it finds a selector that selects the file, so it is not guaranteed to check every selector.
Here is an example of how to use the Or Selector:
<fileset dir="${basedir}"> <or> <depth max="0"/> <filename name="*.png"/> <filename name="*.gif"/> <filename name="*.jpg"/> </or> </fileset> |
Selects all the files in the top directory along with all the image files below it.
The <not> tag reverses the meaning of the single selector it contains.
Here is an example of how to use the Not Selector:
<fileset dir="${src}" includes="**/*.java"> <not> <contains text="test"/> </not> </fileset> |
Selects all the files in the src directory that do not contain the string "test".