Ant datatype

Ant中,除了Property可以做为Task执行时使用的值以外,Ant也提供了很多的数据类型。

下面就对这些数据类型做简要的介绍:

PatternSet

PatternSet用于定义一个pattern集合,同时可以指定一个id属性,以供在其它地方引用它。Patterset可以定义在project下,也可以定义在target下。

使用patternset时,有两种方式:

·使用includes,includesfile,excludes,excludesfile属性

Attribute

Description

includes

指定要包括的文件名的pattern

includesfile

一个包括的文件的名称

excludes

指定要排除的文件名的pattern

excludesfile

一个要排除的文件名

多个pattern之间用以逗号或者空格作为分隔符。

·使用include,exclude|includesfile,excludesfile子元素

Include或者exclude元素有下列属性:

Attribute

Description

Required

name

the pattern to in/exclude.

Yes

if

Only use this pattern if the named property is set.

No

unless

Only use this pattern if the named property is not set.

No

<?xml version="1.0" encoding="UTF-8" ?>

<project default="main">

<!--define a ptattern set with includes attribute-->

<patternset id="java_files_pattern" includes="**/*.java,**/*.class">

</patternset>

<!--define a ptattern set with include subelement-->

<patternset id="java_files_pattern2">

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

<include name="**/*.class"/>

</patternset>

<target name="main">

<echo>java_files_pattern:</echo>

<echo>${toString:java_files_pattern}</echo>

<echo>java_files_pattern2</echo>

<echo>${toString:java_files_pattern2}</echo>

</target>

</project>

上面的代码段中使用了${toString:refid},Ant中有些数据类型(例如PatternSet)是支持toString方法的,使用${toString:refid}可以执行refid对应的toString方法。

测试结果如下:

main:

[echo] java_files_pattern:

[echo] patternSet{ includes: [**/*.java, **/*.class] excludes: [] }

[echo] java_files_pattern2

[echo] patternSet{ includes: [**/*.java, **/*.class] excludes: [] }

BUILD SUCCESSFUL

在实际的应用中,显式地使用PatternSet本身用的并不多见。因为FileSet隐式的包括了PatternSet,所以常见的用法都是在FileSet。另外所有隐含FileSet的数据类型,同样也等于隐含了PatternSet。

FileSet

大多数构建过程中,都会操作文件集合,包括编译、复制、删除、打包等操作。这类构建流程中,非常重要,因此Ant提供了一种FileSet的Datatype。

文件集是以一个单独的目录做为根目录的文件集合。默认情况下,由根目录指定的文件集合包含了整个目录树下的所有的文件,其中包括了所有子目录中的所有文件。

Attribute

Description

Required

dir

根目录

必须指定

两者之一

file

指定单一文件

defaultexcludes

参考patternset

No

includes

参考patternset

No

includesfile

参考patternset

No

excludes

参考patternset

No

excludesfile

参考patternset

No

casesensitive

是否大小写敏感。默认是true

No

followsymlinks

Shall 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

在使用FileSet时,要么是只有一个文件,指定file属性即可。要么是多个文件,指定一个dir即可。

另外,可以在<fileset />中内嵌<patternset /> 和<slector />

下面是官方给出的例子:

使用<patternset />的子元素:

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

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

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

</fileset>

使用内嵌<patternset/>:
<fileset dir="${server.src}" casesensitive="yes">
  <patternset id="non.test.sources">
    <include name="**/*.java"/>
    <exclude name="**/*Test*"/>
  </patternset>
</fileset>
使用selector:
<fileset dir="${server.src}" casesensitive="yes">
  <filename name="**/*.java"/>
  <not>
    <filename name="**/*Test*"/>
  </not>
</fileset>

Selector

Patterset 是根据文件名进行匹配的,有时你想要删除过期的文件或者向远程站点上传发生变化的文件。你想用什么办法删除文件而保留目录呢?selector可以对细化对文件的选择。

从上图也是可以看出selector分为两类:常用的选择器、选择器容器。

选择器容器中,可以有多个选择器。

常用选择器:

  • <contains> - Select files that contain a particular text string
  • <date> - Select files that have been modified either before or after a particular date and time
  • <depend> - Select files that have been modified more recently than equivalent files elsewhere
  • <depth> - Select files that appear so many directories down in a directory tree
  • <different> - Select files that are different from those elsewhere
  • <filename> - Select files whose name matches a particular pattern. Equivalent to the include and exclude elements of a patternset.
  • <present> - Select files that either do or do not exist in some other location
  • <containsregexp> - Select files that match a regular expression
  • <size> - Select files that are larger or smaller than a particular number of bytes.
  • <type> - Select files that are either regular files or directories.
  • <modified> - Select files if the return value of the configured algorithm is different from that stored in a cache.
  • <signedselector> - Select files if they are signed, and optionally if they have a signature of a certain name.
  • <scriptselector> - Use a BSF or JSR 223 scripting language to create your own selector
  • <readable> - Select files if they are readable.
  • <writable> - Select files if they are writable.

常用选择器容器:

  • <and>
  • <contains>
  • <custom>
  • <date>
  • <depend>
  • <depth>
  • <filename>
  • <majority>
  • <none>
  • <not>
  • <or>
  • <present>
  • <selector>
  • <size>

有关selector的使用,可以参考官方文档:

http://ant.apache.org/manual/Types/selectors.html

FileList

FileList 是一个List,是一个有序集合。如果需要使用有序文件集合时,可以使用这个。

Attribute

Description

Required

dir

根目录

Yes

files

文件列表,使用空格或者逗号分隔

如果没有内嵌<file />,

就必须指定这个属性。

<filelist 
    id="docfiles" 
    dir="${doc.src}"
    files="foo.xml
           bar.xml"/> 
 
<filelist 
    id="docfiles" 
    dir="${doc.src}">
    <file name="foo.xml"/>
    <file name="bar.xml"/>
</filelist>

Path

Path用于指定路径,例如环境变量中的PATH、ClassPath。在定义path时,使用:或者;进行分隔。(备注:写build.xml时,可以使用:或者;。由Ant自动的根据操作系统转为相应的分隔符。)

<classpath> 与<path />的方法是一样的。<path />下可以有<pathelement />以及其它的资源集合(例如:fileset,filelist,dirset,path等)

<pathelement> 使用说明

Pathelement可以指定两种属性:

·location 用于指定一个文件或者目录。可以是相对路径,也可以是绝对路径。如果是相对路径,则是相对于project的basedir。

·path 由,或者;分隔的多个location。

<classpath>
      <pathelement path="${classpath}"/>
      <pathelement location="lib/helper.jar"/>
    </classpath>
<classpath>
      <pathelement path="${classpath}"/>
      <fileset dir="lib">
        <include name="**/*.jar"/>
      </fileset>
      <pathelement location="classes"/>
      <dirset dir="${build.dir}">
        <include name="apps/**/classes"/>
        <exclude name="apps/**/*Test*"/>
      </dirset>
      <filelist refid="third-party_jars"/>
    </classpath>

每个path,classpath也有2个属性:id,refid。

id用于被其它地方使用refid引用。

<project ... >
  <path id="project.class.path">
    <pathelement location="lib/"/>
    <pathelement path="${java.class.path}/"/>
    <pathelement path="${additional.path}"/>
  </path>
 
  <target ... >
    <rmic ...>
      <classpath refid="project.class.path"/>
    </rmic>
  </target>
 
  <target ... >
    <javac ...>
      <classpath refid="project.class.path"/>
    </javac>
  </target>
</project>

Regexp

Regexp代表一个正则表达式,可以指定id属性,供其它地方(task或者selector等)使用。

Attribute

Description

Required

pattern

regular expression pattern

Yes

Ant :DataType的更多相关文章

  1. Ant :Property

     Property Ant 内置的Property 系统属性 Ant附加的属性 自定义Property Ant :Property properties是由key-value组成的集合,就是Java中 ...

  2. Ant:build.xml 结构

     Ant build.xml 结构 project target task data property datatype v\:* {behavior:url(#default#VML);} o\:* ...

  3. Ant:Ant 入门

    背景 自从有了 Maven 以后,Ant 视乎就不流行了,不过 Ant 还是有其应用场景的,Ant 的思想比较简洁,如下: 一个 project 包含多个 target(类似成员方法). 一个 tar ...

  4. Luogu P1463 [HAOI2007]反素数ant:数学 + dfs【反素数】

    题目链接:https://www.luogu.org/problemnew/show/P1463 题意: 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x ...

  5. CORS基础要点:关于dataType、contentType、withCredentials

    事实上,面试时我喜欢问跨域,因为多数开发者都知道它并且常用,而我希望能从面试者的回答中知道他在这个问题的深入程度,进一步看看面试者研究问题的思维方式及钻研精神,然而确实难到了很多人,当然这也不是面试通 ...

  6. 我的套路(windows):Jenkins+Jmeter+Ant持续集成

    前期准备: 1.Jdk1.6或以上:http://www.oracle.com/technetwork/java/javase/downloads/index.html 命令行输入:java -ver ...

  7. 在Android开发中使用Ant 一:环境的搭建及入门

    配置Ant环境 下载Ant:http://ant.apache.org/bindownload.cgi 在windows上应该选择zip压缩包,将zip压缩包解压到一个目录. 打开系统环境变量,在系统 ...

  8. 转:Ant使用指南

    一.概述 ant 是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发.在实际软件开发中,有很多地方可以用到ant. 开发环境: System:Windo ...

  9. jenkins+ant+jmeter自动化环境搭建(一)

                        写在最前面: jmeter:测试接口的工具,支持java语言: ant:Apache Ant是一个Java库和命令行工具,其任务是将构建文件中描述的进程作为相互 ...

随机推荐

  1. vmware网卡设置详解

    转载请注明出处!本文连接及作者.不得用于商业用途! http://hi.baidu.com/quantumcloud/blog/item/9156a6c584996c179c163d5b.html B ...

  2. Oracle启动报错ORA-03113解决

    环境:RHEL6.4 + Oracle 11.2.0.4 步骤摘要:1.启动报错ORA-031132.查看alert日志查找原因3.根据实际情况采取合理的措施,这里我们先增加闪回区大小,把库启动起来4 ...

  3. mysql权限管理

    经常遇到有网友在QQ群或者论坛上问关于mysql权限的问题,今天抽空总结一下关于这几年使用MYSQL的时候关于MYSQL数据库的权限管理的经验,也希望能对使用mysql的网友有所帮助! 一.MYSQL ...

  4. VMware Workstation 10.0 正式版官方简体中文下载(附序列号)

    虚拟机界数一数二的王者软件VMWare Workstation 今日推出了最新的VMware Workstation 10.0 版本.该版本最大的更新是加入了简体中文语言,这意味着未来神马汉化包.中文 ...

  5. deployment与Web应用程序部署

    定义用于支持 Web 应用程序部署的配置设置. <deployment retail="true|false" /> retail属性:设置一个值,该值指定是否以发布模 ...

  6. C#基础-文件夹复制与删除

    代码来源:http://blog.163.com/u_tommy_520/blog/static/20406104420147493933662/ 最近做MVC网站时刚好用到,用以提供一个完整的文件夹 ...

  7. centos安装禅道的步骤

    1.下载 XAMPP 套件: https://sourceforge.net/projects/xampp/files/XAMPP%20Linux/stats/timeline  下载的文件是 xam ...

  8. MyBatis的mapper

    在前面的学习中,我们还在写一些接口啊,实现类啊,是不是感觉好low的... 其实,我们是可以不用写接口的实现类的,今天就带着大家一起学习一下,当然,我是回顾的. 看下面的结构,是不是没实现类呢! 源码 ...

  9. 魔术方法__sleep 和 __wakeup

    感觉序列化和反序列化用得倒是比较少了,而json_encode和json_decode用得相对多,都是转化成串,进行入库.传输等.json更方便,但是序列化和反序列化结合这两个魔术方法使用倒还行< ...

  10. js 之 continue break return 用法及注意事项

    1,continue continue有两种用法: 1,continue; 这种用法必须包含在循环里,否则报错,例子: for(var i=0;i<10;i++){ if(i%2===0){ c ...