这个东西是干嘛的,简单的将就是一个映射,比如你在拷贝文件的时候需要将文件名后缀修改,这玩意可以解决这个问题。
org.apache.tools.ant.util.FileNameMapper
These instances are defined in <mapper>
elements with the following attributes:
Attribute | Description | Required |
type | specifies one of the built-in implementations. | Exactly one of these |
classname | specifies the implementation by class name. | |
classpath | the classpath to use when looking up classname . | No |
classpathref | the classpath to use, given as reference to a path defined elsewhere. | No |
from | the from attribute for the given implementation. | Depends on implementation. |
to | the to attribute for the given implementation. | Depends on implementation. |
讲个flatten的例子:
<mapper type="flatten"/>
<flattenmapper/>
Source file name | Target file name |
A.java | A.java |
foo/bar/B.java | B.java |
C.properties | C.properties |
Classes/dir/dir2/A.properties | A.properties |
什么意思呢,就是去掉文件的所在的目录,覆盖掉同名的文件,最后所有的东西都是唯一的。
merge
The target file name will always be the same, as defined by to
- from
will be ignored.
Examples:
<mapper type="merge" to="archive.tar"/>
<mergemapper to="archive.tar"/>
Source file name | Target file name |
A.java | archive.tar |
foo/bar/B.java | archive.tar |
C.properties | archive.tar |
Classes/dir/dir2/A.properties | archive.tar |
这个东西我理解得不是很清楚,不知道这个archiver.tar里面是不是包含所有的这些文件。
glob:
Both to
and from
are required and define patterns that may contain at most one *
.
<mapper type="glob" from="C*ies" to="Q*y"/>
<globmapper from="C*ies" to="Q*y"/>
Source file name | Target file name |
A.java | ignored |
foo/bar/B.java | ignored |
C.properties | Q.property |
Classes/dir/dir2/A.properties | Qlasses/dir/dir2/A.property |
这个东西有点像模式匹配,就是把你在source中根据from中所描述的规则找到的东西rename成to中的东西.
Package 与unpackage:
这两个东西是一段,功能基本可以看做是想反的。有点像我们上一节将的class fileset的那么点意思。
举个例子就明白了:
<mapper type="package" from="*Test.java" to="TEST-*Test.xml"/>
<packagemapper from="*Test.java" to="TEST-*Test.xml"/>
Source file name | Target file name |
org/apache/tools/ant/util/PackageMapperTest.java | TEST-org.apache.tools.ant.util.PackageMapperTest.xml |
org/apache/tools/ant/util/Helper.java | ignored |
什么意思呢,就是首先在source file中利用from的规则,因为第一条是匹配的,然后呢利用to中的规则将其根据整个目录的名称修改文件的名称。这里
org/apache/tools/ant/util/PackageMapper相当于*,因此首先加上
TEST- 然后将其改package后并加上Test.xml
unpackage有点相反的意思:
<mapper type="unpackage" from="TEST-*Test.xml" to="${test.src.dir}/*Test.java">
<unpackagemapper from="TEST-*Test.xml" to="${test.src.dir}/*Test.java">
Source file name | Target file name |
TEST-org.acme.AcmeTest.xml | ${test.src.dir}/org/acme/AcmeTest.java |
不过这里我有一点不明白,这个${test.src.dir}应该是根据实际环境被替换的。
以上所讲对应相关的一些属性还有好些,用的时候去这里搜索吧!http://ant.apache.org/manual/index.html