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. 1Z0-053 争议题目解析577

    1Z0-053 争议题目解析577 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 577.What methods are available to recover lost co ...

  2. iOS_MJRefrash的详解以及使用

    MJRefresh Github 效果动态图来这里看吧 该博客Demo下载地址 一. MJRefresh的类解释. 1.MJRefreshComponent              所有刷新控件的基 ...

  3. springMVC学习笔记(二)-----注解和非注解入门小程序

    最近一直在做一个电商的项目,周末加班,忙的都没有时间更新博客了.终于在上周五上线了,可以轻松几天了.闲话不扯淡了,继续谈谈springMvc的学习. 现在,用到SpringMvc的大部分使用全注解配置 ...

  4. pushState、replaceState、onpopstate 实现Ajax页面的前进后退刷新

    使用Ajax可以异步获取数据,可以更高效地渲染页面. 但也存在这一些问题: 再刷新页面,页面就会变成初始的状态 浏览器的前进后退功能无效 对搜索引擎的爬虫抓取不友好 1. 早前会使用浏览器的 hash ...

  5. WCF学习系列四--【WCF Interview Questions – Part 4 翻译系列】

    WCF Interview Questions – Part 4   This WCF service tutorial is part-4 in series of WCF Interview Qu ...

  6. 【工业串口和网络软件通讯平台(SuperIO)教程】六.二次开发导出数据驱动

    SuperIO相关资料下载:http://pan.baidu.com/s/1pJ7lZWf 1.1    导出数据接口的作用 在数据集成系统项目中,要么是自已集成其他厂家的设备,要么是其他厂家集成自己 ...

  7. 如何配置Log4Net使用Oracle数据库记录日志

    最近在做一个项目的时候,需要增加一个日志的功能,需要使用Log4Net记录日志,把数据插入到Oracle数据库,经过好久的研究终于成功了.把方法记录下来,以备以后查询. 直接写实现方法,分两步完成: ...

  8. javascript创建对象的几种模式

    在js中有几种模式可以创建对象,通过对象操作所包含的属性与方法. 一般来说,构造函数名称的第一个字母为大写字母,非构造函数名称的第一个字母为小写字母,当然,构造函数与一般函数唯一的区别只是调用的方式不 ...

  9. css制作漂亮彩带导航条菜单

    点击这里查看效果:http://keleyi.com/keleyi/phtml/divcss/17.htm 效果图: 以下是源代码: <!DOCTYPE html PUBLIC "-/ ...

  10. Pro HTML5 Programming(Second Edition)2.Canvas API(2)

    1.在页面中加入canvas元素 eg: <!DOCTYPE html> <html lang="en"> <head> <meta ch ...