Ant FileMapper

这个东西是干嘛的,简单的将就是一个映射,比如你在拷贝文件的时候需要将文件名后缀修改,这玩意可以解决这个问题。

org.apache.tools.ant.util.FileNameMapper

 

These instances are defined in <mapper> elements with the following attributes:

Attribute Description Required
typespecifies one of the built-in implementations.Exactly one of these
classnamespecifies the implementation by class name.
classpaththe classpath to use when looking up classname .No
classpathrefthe classpath to use, given as reference to a path defined elsewhere.No
fromthe from attribute for the given implementation.Depends on implementation.
tothe 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

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值