Copies a file or resource collection to a new file or directory. By default, files are only copied if the source file is newer than the destination file, or when the destination file does not exist. However, you can explicitly overwrite files with theoverwrite
attribute.
Resource Collections are used to select a group of files to copy. To use a resource collection, the todir
attribute must be set.Note that some resources (for example the file resource) return absolute paths as names and the result of using them without using a nested mapper (or the flatten attribute) may not be what you expect.
Note: If you employ filters in your copy operation, you should limit the copy to text files. Binary files will be corrupted by the copy operation. This applies whether the filters are implicitly defined by the filter task or explicitly provided to the copy operation as filtersets. See encoding note.
字段摘要 | |
---|---|
String |
enablemultiplemappings
f true the task will process to all the mappings for a given source path. If false the task will only process the first file or directory. This attribute is only relevant if there is a mapper subelement. since Ant 1.6. |
String |
encoding
The encoding to assume when filter-copying the files. since Ant 1.5. |
String |
failonerror
If false, log a warning message, but do not stop the build, when the file to copy does not exist or one of the nested filesets points to a directory that doesn't exist or an error occurs while copying. |
String |
file
The file to copy. |
String |
filtering
Indicates whether token filtering using the global build-file filters should take place during the copy. Note: Nested <filterset> elements will always be used, even if this attribute is not specified, or its value is false (no , or off ). |
String |
flatten
Ignore the directory structure of the source files, and copy all files into the directory specified by the todir attribute. Note that you can achieve the same effect by using a flatten mapper. |
String |
force
Overwrite read-only destination files. since Ant 1.8.2 |
String |
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 1 second, or 2 seconds on DOS systems. This can also be useful if source and target files live on separate machines with clocks being out of sync. since Ant 1.6.2. |
String |
id
|
String |
idref
|
String |
includeEmptyDirs
Copy any empty directories included in the FileSet(s). |
String |
outputencoding
The encoding to use when writing the files. since Ant 1.6. |
String |
overwrite
Overwrite existing files even if the destination files are newer. |
String |
preservelastmodified
Give the copied files the same last modified time as the original source files. |
String |
todir
The directory to copy to. |
String |
tofile
The file to copy to. |
String |
verbose
Log the files that are being copied. |
方法摘要 | |
---|---|
|
toString
|
子事物摘要 | |
---|---|
|
XWorkerFileSets
|
|
fileset
A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors. |
|
filterchain
Consider the flexibility of Unix pipes. If you wanted, for example, to copy just those lines that contained the string blee from the first 10 lines of a text file 'foo' (you wouldn't want to filter a binary file) to a file 'bar', you would do something like: |
|
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 |
|
mapper
Some tasks take source files and create target files. Depending on the task, it may be quite obvious which name a target file will have (using javac, you know there will be |
字段详细信息 |
---|
f true the task will process to all the mappings for a given source path. If false the task will only process the first file or directory. This attribute is only relevant if there is a mapper subelement. since Ant 1.6.
The encoding to assume when filter-copying the files. since Ant 1.5.
If false, log a warning message, but do not stop the build, when the file to copy does not exist or one of the nested filesets points to a directory that doesn't exist or an error occurs while copying.
The file to copy.
Indicates whether token filtering using the global build-file filters should take place during the copy. Note: Nested<filterset>
elements will always be used, even if this attribute is not specified, or its value is false
(no
, or off
).
Ignore the directory structure of the source files, and copy all files into the directory specified by the todir
attribute. Note that you can achieve the same effect by using a flatten mapper.
Overwrite read-only destination files. since Ant 1.8.2
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 1 second, or 2 seconds on DOS systems. This can also be useful if source and target files live on separate machines with clocks being out of sync. since Ant 1.6.2.
Copy any empty directories included in the FileSet(s).
The encoding to use when writing the files. since Ant 1.6.
Overwrite existing files even if the destination files are newer.
Give the copied files the same last modified time as the original source files.
The directory to copy to.
The file to copy to.
Log the files that are being copied.
方法详细信息 |
---|
子事物详细信息 |
---|
A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors.
PatternSets can be specified as nested <patternset>
elements. In addition, FileSet holds an implicit PatternSet and supports the nested <include>
, <includesfile>
, <exclude>
and <excludesfile>
elements of PatternSet directly, as well as PatternSet's attributes.
Selectors are available as nested elements within the FileSet. If any of the selectors within the FileSet do not select the file, the file is not considered part of the FileSet. This makes a FileSet equivalent to an <and>
selector container.
Consider the flexibility of Unix pipes. If you wanted, for example, to copy just those lines that contained the string blee from the first 10 lines of a text file 'foo' (you wouldn't want to filter a binary file) to a file 'bar', you would do something like:
cat foo|head -n10|grep blee > bar
Apache Ant was not flexible enough. There was no way for the <copy>
task to do something similar. If you wanted the <copy>
task to get the first 10 lines, you would have had to create special attributes:
<copy file="foo" tofile="bar" head="10" contains="blee"/>
The obvious problem thus surfaced: Ant tasks would not be able to accommodate such data transformation attributes as they would be endless. The task would also not know in which order these attributes were to be interpreted. That is, must the task execute the contains attribute first and then the head attribute or vice-versa? What Ant tasks needed was a mechanism to allow pluggable filter (data transformer) chains. Ant would provide a few filters for which there have been repeated requests. Users with special filtering needs would be able to easily write their own and plug them in.
The solution was to refactor data transformation oriented tasks to support FilterChains. A FilterChain is a group of ordered FilterReaders. Users can define their own FilterReaders by just extending the java.io.FilterReader class. Such custom FilterReaders can be easily plugged in as nested elements of <filterchain>
by using <filterreader>
elements.
ant.apache.org/manual/Types/filterchain.html
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.
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 that the copy operations will typically corrupt binary files. When applying filters you should ensure that the set of files being filtered are all text files.
Some tasks take source files and create target files. Depending on the task, it may be quite obvious which name a target file will have (using javac, you know there will be .class
files for your .java
files) - in other cases you may want to specify the target files, either to help Apache Ant or to get an extra bit of functionality.
While source files are usually specified as filesets, you don't specify target files directly - instead, you tell Ant how to find the target file(s) for one source file. An instance of org.apache.tools.ant.util.FileNameMapper
is responsible for this. It constructs target file names based on rules that can be parameterized with from
and to
attributes - the exact meaning of which is implementation-dependent.