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. 安装infer整个过程

    日期:2015-06-26 孟起  15:43:25 大神.. 孟起  15:43:38 我是不是照着这个安装 HelloWorld  15:45:05 直接找二进制文件安卓就行 孟起  15:46: ...

  2. PowerPoint基础

    一.基础 默认后缀ppt,pptx office2003和以后的版本只支持ppt, 可以将pptx另存为ppt97-2003 二.修改PPT尺寸 三.新建幻灯片 四.字体与段落设置 五.主题与字体 六 ...

  3. 使用代码为textview设置drawableLeft

    xml中的textView中设置android:drawableLeft: <TextView android:id="@+id/bookTitle" android:lay ...

  4. struct 大小计算

    结构体是一种复合数据类型,通常编译器会自动的进行其成员变量的对齐,已提高数据存取的效率.在默认情况下,编译器为结构体的成员按照自然对齐(natural alignment)条方式分配存储空间,各个成员 ...

  5. 从零开始,搭建博客系统MVC5+EF6搭建框架(3),添加Nlog日志、缓存机制(MemoryCache、RedisCache)、创建控制器父类BaseController

    一.回顾系统进度以及本章概要 目前博客系统已经数据库创建.以及依赖注入Autofac集成,接下来就是日志和缓存集成,这里日志用的是Nlog,其实还有其他的日志框架如log4,这些博客园都有很多介绍,这 ...

  6. CSS垂直居中和水平居中

    前言 CSS居中一直是一个比较敏感的话题,为了以后开发的方便,楼主觉得确实需要总结一下了,总的来说,居中问题分为垂直居中和水平居中,实际上水平居中是很简单的,但垂直居中的方式和方法就千奇百怪了. 内联 ...

  7. CSS3+jQuery实现时钟插件

    查看效果:http://hovertree.com/texiao/hoverclock/demo4.htm 本插件使用方便,可以在博客园的页面中使用,请看本页面右侧:http://www.cnblog ...

  8. html5 前端图片处理(预览、压缩、缩放)

    现在手机图片是越来越大了,上传图片流量耗费巨大.同时预览也是一个问题,所以利用HTML5 file和canvas来解决这个问题. var upload = { _o: null,//对象id _aut ...

  9. DI和IOC

    DI和IOC是差不多的概念. 一个重要特征是接口依赖,是把对象关系推迟到运行时去确定. DI是一个初始化实例的过程,分为三种1.setter based 2.constructor based 3.i ...

  10. 让Visual Studio Code对jQuery支持智能提示!

    本人新手,对代码各种不熟悉,记不准确,总是打错,造成各种失误!! 其实这个方法应该适合大部分前端开发工具!! 园里子有前人写了一篇文章对智能提示的实现!不过很多新手看不懂吧. http://www.c ...