zoukankan      html  css  js  c++  java
  • Ant高级-path和fileset

    一 <path/> 和 <classpath/>

    你可以用":"和";"作为分隔符,指定类似PATH和CLASSPATH的引用。Ant会把分隔符转换为当前系统所用的分隔符。

    当需要指定类似路径的值时,可以使用嵌套元素。一般的形式是

    <classpath>

    <pathelement path="{classpath}"/>

    <pathelement location="lib/helper.jar"/>

    </classpath>

    location属性指定了相对于project基目录的一个文件和目录,而path属性接受逗号或分号分隔的一个位置列表。path属性一般用作预定义的路径,其他情况下,应该用多个location属性。

    为简洁起见,classpath标签支持自己的path和location属性。所以:

    <classpath>

    <pathelement path="{classpath}"/>

    </classpath>

    可以被简写作:

    <classpath path="{classpath}"/>

    也可通过<fileset>元素指定路径。构成一个fileset的多个文件加入path-like structure的顺序是未定的。

    <classpath>

    <pathelement path="{classpath}"/>

    <fileset dir="lib">

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

    </fileset>

    <pathelement location="classes"/>

    </classpath>

    上面的例子构造了一个路径值包括:{classpath}的路径,跟着lib目录下的所有jar文件,接着是classes目录。

    如果你想在多个task中使用相同的path-like structure,你可以用<path>元素定义他们(与target同级),然后通过id属性引用。

    path-like structure可能包括对另一个path-like structurede的引用(通过嵌套<path>元素):

    <path id="base.path">

    <pathelement path="{classpath}"/>

    <fileset dir="lib">

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

    </fileset>

    <pathelement location="classes"/>

    </path>

    <path id="tests.path">

    <path refid="base.path"/>

    <pathelement location="testclasses"/>

    </path>

    前面所提的关于<classpath>的简洁写法对于<path>也是有效的,如:

    <path id="tests.path">

    <path refid="base.path"/>

    <pathelement location="testclasses"/>

    </path>

    可写成:

    <path id="base.path" path="{classpath}"/>

    二 fileset

    1)FileSet是一组文件,这些文件可以在基目录树下找到且与指定的PatternSets和Selectors匹配。FileSet的结构类似于如下:

    <fileset dir="${server.src}">
    <patternset/>
    <Selector/>
    </fileset>

    2)patternset一般用作FileSet的子元素,用来帮助筛选文件。可以包含如下的子元素:include,exclude,includes,excludes,includesfile,excludesfile.

    FileSet中隐式地包含了一个patternset元素,所以可以在FileSet中直接包含patterset中的元素,例如<include>, <includesfile>, <exclude> and <excludesfile> 。

    如下的patternset包含std子目录下的java文件,如果professional定义的话还包含prof下的java文件,但是不包含名字中包含Test的文件。
    <patternset id="sources">
    <include name="std/**/*.java"/>
    <include name="prof/**/*.java" if="professional"/>
    <exclude name="**/*Test*"/>
    </patternset>

    3)Selector一般用作FileSet的子元素,用来帮助筛选文件。

    常用的核心的selector有:
    <contains> - 用来选择包含指定字符串的文件
    <date> - 用来选择在某个特定时间前或后修改的文件
    <depend> - Select files that have been modified more recently than equivalent files elsewhere
    <depth> - 用来选择指定目录深度的文件
    <different> - Select files that are different from those elsewhere
    <filename> - 用来选择文件名匹配特定模式的文件。等价于include和exclude的patternset。
    <present> - 用来选择在某个位置存在或不存在的文件
    <containsregexp> - 用来选择匹配指定正则表达式的文件
    <size> - 用来选择比指定size大或小的文件
    <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> - 选择有readable属性的文件
    <writable> - 选择有writable属性的文件

    例如选择包含script的所有的html文件
    <fileset dir="${doc.path}" includes="**/*.html">
    <contains text="script" casesensitive="no"/>
    </fileset>

    例如选择所有在January1,2001前修改的JAR文件
    <fileset dir="${jar.path}" includes="**/*.jar">
    <date datetime="01/01/2001 12:00 AM" when="before"/>
    </fileset>

    例如选择所有满足正则表达式的txt文件
    <fileset dir="${doc.path}" includes="*.txt">
    <containsregexp expression="[4-6].[0-9]"/>
    </fileset>

    如下的selector与patternset等价:
    <fileset dir="${server.src}" casesensitive="yes">
    <filename name="**/*.java"/>
    <not>
    <filename name="**/*Test*"/>
    </not>
    </fileset>
    等价于
    <fileset dir="${server.src}" casesensitive="yes">
    <filename name="**/*.java"/>
    <filename name="**/*Test*" negate="true"/>
    </fileset>
    等价于
    <fileset dir="${server.src}" casesensitive="yes">
    <include name="**/*.java"/>
    <exclude name="**/*Test*"/>
    </fileset>


    selector容器可以包含其他的selector,常用的selector容器有:
    <and>
    <contains>
    <custom>
    <date>
    <depend>
    <depth>
    <filename>
    <majority>
    <none>
    <not>
    <or>
    <present>
    <selector>
    <size>


    例如选择比4096bytes大且从上个millenium没有更新的JAR文件
    <fileset dir="${dist}" includes="**/*.jar">
    <and>
    <size value="4" units="Ki" when="more"/>
    <date datetime="01/01/2001 12:00 AM" when="before"/>
    </and>
    </fileset>

    完!

  • 相关阅读:
    【递归】斐波那契数列第n个数
    二分查找【循环和递归】
    递归:正序、逆序输出一个正整数的各位数字
    Ubuntu x86-64汇编(5) 控制指令
    Ubuntu x86-64汇编(4) 数值操作指令
    Ubuntu x86-64汇编(3) 数值操作指令
    给X240换上了三键触摸板
    Ubuntu x86-64汇编(2)
    Ubuntu x86-64汇编(1)
    X240 Ubuntu18.04安装流水帐
  • 原文地址:https://www.cnblogs.com/daxiong225/p/9601764.html
Copyright © 2011-2022 走看看