Ant之Fileset/Class FileSet

1 FileSet:

什么是FileSet,简单的将就是a group of files.可以进行Selector操作。就是说你可以选择将那些文件include进来或者exclude出去。

 

 

先看看其基本属性:

Attribute Description Required
dirthe root of the directory tree of this FileSet.Either dir or file must be specified
fileshortcut for specifying a single-file fileset
defaultexcludesindicates whether default excludes should be used or not (yes | no ); default excludes are used when omitted.No
includescomma- or space-separated list of patterns of files that must be included; all files are included when omitted.No
includesfilethe name of a file; each line of this file is taken to be an include pattern.No
excludescomma- or space-separated list of patterns of files that must be excluded; no files (except default excludes) are excluded when omitted.No
excludesfilethe name of a file; each line of this file is taken to be an exclude pattern.No
casesensitiveMust the include and exclude patterns be treated in a case sensitive way? Defaults to true.No
followsymlinksShall symbolic links be followed? Defaults to true. See the note below .No
erroronmissingdir Specify what happens if the base directory does not exist. If true a build error will happen, if false, the fileset will be ignored/empty. Defaults to true. Since Apache Ant 1.7.1 (default is true for backward compatibility reasons.) No

 

例子:

在前面例子的基础上进行修改,作用是将old下面的两个文件old1.txt 和old2.txt拷贝到new下面去。

    <target name="myTarget.check" depends="init">
        <copy todir="${basedir}/new">
                           <fileset dir="${basedir}/old">
                              <include name="old1.txt" />
                              <include name="old2.txt" />
                              <exclude name="old8.txt" />
                          </fileset>
                       </copy>
    </target>

输出结果:

myTarget.check:
     [copy] Copying 2 files to D:/HelloAntWorld/new

myTarget:

all:

BUILD SUCCESSFUL
Total time: 1 second

 

在fileset中也可以结合其他的了解和selector使用,如:

<fileset dir="${server.src}" casesensitive="yes">



<filename name="**/*.java"/>



<not>



<filename name="**/*Test*"/>



</not>



</fileset>







2 讲下classFileset







A classfileset is a specialised type of fileset which, given a set of "root" classes, will include all of the class files upon which the



root classes depend.







This type requires the jakarta-BCEL


library.



除了遵循fileset里面的属性还支持:
Attribute Description Required
rootclassA single root class nameNo

 

When more than one root class is required, multiple nested <root> elements may be used

Attribute Description Required
classnameThe fully qualified name of the root classYes

 

举个简单的例子:

<classfileset id="reqdClasses" dir="${classes.dir}">

<root classname="org.apache.tools.ant.Project"/>

</classfileset>

这个意思就是说将org/apache/tools/ant/projet下所有的class包含起来形成一个fileset。



这个目前我还没用到过,看到再补充。。。。。。



3 Pattern:什么是pattern,你可以理解为模式匹配,在unix或者数据库语句中都曾有过的。比如*。

'*' matches zero or more characters,

'?' matches one character.



一般pattern都是在相对路径下开始搜索的。按照一个目录一个一个进行匹配。

比如/?abc/*/*.java
, 匹配 /xabc/foobar/test.java
,

the first ?abc
is matched with xabc
,

then *
is matched with foobar
,

and finally *.java
is matched with test.java
.

使用**可以在多个层次上搜索。

When **
is used as the name of a directory in the pattern, it matches zero or more directories.

例如:

/test/**
匹配 /test/
下所有的文件和目录、

助于如果pattern以 /
or /结尾
, then **
s appended.

例如 mypackage/test/
将被解析为mypackage/test/**
.





FileSet上还有一些操作,先记下来由时间再看:

FileLists:

 

FileLists are explicitly named lists of files. Whereas FileSets act as filters, returning only those files that exist in the file system and match specified patterns, FileLists are useful for specifying files that may or may not exist. Multiple files are specified as a list of files, relative to the specified directory, with no support for wildcard expansion (filenames with wildcards will be included in the list unchanged). FileLists can appear inside tasks that support this feature or as stand-alone types.

Attribute Description Required
dirThe base directory of this FileList.Yes
filesThe list of file names. This is a list of file name separated by whitespace, or by commas. Yes, unless there is a nested file elem
<filelist  id="docfiles"  dir="${doc.src}" files="foo.xml,bar.xml"/> 

 Note that these files may not (yet) actually exist.



6 PropertySet:

propertyref

Selects properties from the current project to be included in the set.

Attribute Description Required
nameSelect the property with the given name.Exactly one of these.
prefixSelect the properties whose name starts with the given string.
regexSelect the properties that match the given regular expression. Similar to regexp type mappers , this requires a supported regular expression library.
builtinSelects a builtin set of properties. Valid values for this attribute are all for all Ant properties, system for the system properties and commandline for all properties specified on the command line when invoking Ant (plus a number of special internal Ant properties).
<propertyset id="properties-starting-with-foo">

<propertyref prefix="foo"/>

</propertyset>

<propertyset id="properties-starting-with-bar">

<propertyref prefix="bar"/>

</propertyset>

<propertyset id="my-set">

<propertyset refid="properties-starting-with-foo"/>

<propertyset refid="properties-starting-with-bar"/>





</propertyset>

collects all properties whose name starts with either "foo" or "bar" in the set named "my-set".



7 ZipFileSet:

A <zipfileset> is a special form of a <fileset > which can behave in 2 different ways :

  • When the src attribute is used - or a nested resource collection has been specified (since Apache Ant 1.7 ), the zipfileset is populated with zip entries found in the file src .
  • When the dir attribute is used, the zipfileset is populated with filesystem files found under dir .

转载一篇资料:

Sun java的申明:

http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html#-jar

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

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

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

打赏作者

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

抵扣说明:

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

余额充值