📅  最后修改于: 2020-12-26 13:37:52             🧑  作者: Mango
Apache Ant提供了丰富的类型集,下面提供了其中的一些类型。我们可以使用它们来处理数据,文件,路径等,也可以用作服务。
Type | Description |
---|---|
ClassFileSet | It is used to create Jar with all required classes. |
DirSet | It groups the directories. |
FileList | A list of files. |
FileSet | A group of files. |
FileMapper | It helps to map source and target file. |
FilterSet | A group of filters. |
PatternSet | A group of patterns that are referenced by ids. |
Selectors | A FileSet element, helps to select elements |
TarFileSet | It is a special form of a FileSet. |
ZipFileSet | A set of zip files. |
ClassFileSet是FileSet的一种特殊类型,它包括根类所依赖的所有类文件。它用于创建具有特定应用程序所有必需类的JAR。
由ID值声明ClassFileSet,然后将其用作参考。
DirSet是一组目录。它支持
Attribute | Description | Required |
---|---|---|
dir | It holds root of the directory tree of this DirSet | Yes |
includes | A list of patterns of directories. | No |
includesfile | Name of a file which is to be included. | No |
excludes | A list of patterns of directories that must be excluded. | No |
excludesfile | Name of a file which is to be excluded. | No |
casesensitive | It is used to specify whether case-sensitivity should be applied or not. | No |
follosymlinks | It holds a symbolic link to be followed. | No |
erroronmissingdir | It specifies what happens if the base directory does not exist. | No |
本示例将在$ {build.dir}的apps子目录中找到的所有目录名称类分组,并排除名称中具有test的目录。
FileList是文件列表(集合)。它可以与
Attribute | Description | Required |
---|---|---|
dir | It is used to hold base directory of this list. | Yes |
files | List of file names | Yes |
FileSet是来自单个根目录的一组文件。它根据Ant指定的模式集收集文件。
文件集具有以下属性。
Attribute | Description | Required |
---|---|---|
dir | It holds root directory the FileSet. | Either dir or file must be specified. |
file | For specifying a single-file fileset. | Either dir or file must be specified. |
includes | A list of patterns of files that must be included. | No |
includesfile | A file name. | No |
excludes | A list of patterns of files that must be excluded. | No |
excludesfiles | A File name pattern. | No |
casesensitive | Both the include and exclude patterns are casesensitive. | No |
followsymlinks | The symbolic links should be followed. | No |
让我们看一个示例,将文件从一个目录复制到另一个目录。
// build.xml
上面的代码会将所有Java文件从dir2复制到dir1。
有时在执行任务后,源文件和输出都不同,因此无法映射。 Apache Ant使用FileMapper映射源文件和创建的目标文件。 org.apache.tools.ant.util.FileNameMapper类和
映射器具有以下属性。
Attribute | Description | Required |
---|---|---|
type | specifies one of the built-in implementations. | No |
classname | specifies the implementation by class name. | Exactly one of these. |
classpath | the classpath to use when looking up classname. | No |
classpathref | Apache Ant? User Manual | No |
from | the from attribute for the given implementation. | Depends on implementation |
to | the to attribute for the given implementation. | Depends on implementation |
所有内置的映射器均区分大小写。
FilterSet是一组过滤器,由两个主要操作(任务)复制和移动使用。它使用id和refid属性,id用于定义FilterSet,refid用于引用另一个FilterSet。
也可以将FilterSet嵌套到FilterSet中,以获取所包含过滤器的集合并集。
它具有以下提供的各种属性。
Attribute | Description | Default | Required |
---|---|---|---|
begintoken | It is a string marking the beginning of a token. | @ | No |
endtoken | It is a string marking the end of a token. | @ | No |
filtersfile | It specifies a single filtersfile. | None | No |
recurse | Used for searched more tokens. | true | No |
onmissingfiltersfile | It Indicates behavior when a nonexistent filtersfile is specified. | fail | No |
在这里,我们将abc.txt文件从构建目录复制到dist目录,但希望将令牌@ DATE @替换为今天的日期。