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. 实现tap的多种方式

    一.tap.js 这是一个比较轻量的插件tap.js,142行代码,支持模块化开发. 1)handleEvent addEventListener方法中的第二个参数,我原先并没有注意到其实可以传一个对 ...

  2. ng1和ng2的部分对比----angular2系列(四)

    前言: angular2相比angular1做了革命性的改变.对于开发者来说,我们知道它框架的实现上改变极大.我们看到代码也能发现它写法上变化很大,似乎完全是另一个东西. 但是当我们真正去写下去的时候 ...

  3. hibernate笔记--cascade级联以及inverse属性

    cascade : 不管是单向多对一还是一对多,或者是双向的一对多关系,在一的一端映射文件中有一个set标签,在多的一端有many-to-one标签,拿前几篇笔记里讲的Grade和Student举例, ...

  4. Android之自定义ViewPager实现图片的无线轮播

    PS:以前也写过关于图片轮播这一块的博客.不过写的很烂,并且很多情况没有考虑到(没有支持无线轮播,和手势点击事件).因此这里写一篇补上.也是当时太年轻了. 注:图片请放大后再看.否则看不清楚. 学习内 ...

  5. Mybatis-update - 数据库死锁 - 获取数据库连接池等待

    最近学习测试mybatis,单个增删改查都没问题,最后使用mvn test的时候发现了几个问题: update失败,原因是数据库死锁 select等待,原因是connection连接池被用光了,需要等 ...

  6. Net设计模式实例之桥接模式( Bridge Pattern)

    一.桥接模式简介(Brief Introduction) 桥接模式(Bridge Pattern),将抽象部分与它的实现部分分离,使的抽象和实现都可以独立地变化. Decouple an abstra ...

  7. Python_Day_03 list,dic,tuple方法总结

    编程语言中最长见的几种数据类型,字典,列表,等.同样在Python中也有这些数据类型,只是有些表现形式不同.同时在Python中又多了一种叫做元组(tuple)的东西. list(列表) 初始化列表 ...

  8. 谈一谈.net析构函数对垃圾回收的影响

    之前忘了说了 代码都是在Release模式下运行的,现在补充上. 这里说析构函数,其实并不准确,应该叫Finalize函数,Finalize函数形式上和c++的析构函数很像 ,都是(~ClassNam ...

  9. 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    [源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...

  10. Java中2+2==5解读

    先来看一段程序,如下: package basic; import java.lang.reflect.Field; public class TestField { public static vo ...