Ant: DataType, antdatatype

Source: Internet
Author: User

Ant: DataType, antdatatype

  • DataType
    • Patternset
    • Fileset
    • Selector
    • Filelist
    • Path
    • Regexp

 

Ant datatype

In Ant, apart from the Property value that can be used for Task execution, Ant also provides many data types.

 

 

 

The following is a brief introduction to these data types:

 

 

PatternSet

PatternSet is used to define a pattern set and you can specify an id attribute for reference elsewhere. Patterset can be defined under a project or a target.

 

There are two ways to use patternset:

· Use the includes, includesfile, excludes, and excludesfile attributes.

Attribute

Description

Includes

Specifies the pattern of the file name to include

Includesfile

Name of an included file

Excludes

Specifies the pattern of the file name to be excluded

Excludesfile

Name of the file to be excluded

Multiple Patterns are separated by commas (,) or spaces.

 

· Use include, exclude | includesfile, excludesfile sub-element

 

The Include or exclude element has the following attributes:

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 isNotSet.

No

 

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

<Project default = "main">

 

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

<Patternset id = "java_files_pattern" shortdes = "**/*. 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} is used in the above Code segment. Some data types in Ant (such as PatternSet) support the toString method, and $ {toString: refid} can execute the toString method corresponding to refid.

The test results are as follows:

Main:

[Echo] java_files_pattern:

[Echo] patternSet {events des: [**/*. java, **/*. class] excludes: []}

[Echo] java_files_pattern2

[Echo] patternSet {events des: [**/*. java, **/*. class] excludes: []}

 

BUILD SUCCESSFUL

 

In practical applications, PatternSet is rarely used explicitly. Because FileSet includes the PatternSet implicitly, the common usage is in FileSet. In addition, all the data types of the hidden FileSet are also equivalent to the hidden PatternSet.

 

FileSet

During most construction processes, a file set is operated, including compiling, copying, deleting, and packaging. This type of building process is very important, so Ant provides a FileSet Datatype.

A file set is a file set that uses a separate directory as the root directory. By default, the file set specified by the root directory contains all the files under the entire directory tree, including all the files in all subdirectories.

 

Attribute

Description

Required

Dir

Root directory

Must be specified

One of the two

File

Specify a single file

Defaultexcludes

See patternset

No

Includes

See patternset

No

Includesfile

See patternset

No

Excludes

See patternset

No

Excludesfile

See patternset

No

Casesensitive

Case sensitive. The default value is 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.

Ults to true.

 Since Apache Ant 1.7.1 (default is true for backward compatibility reasons .)

No

 

When using FileSet, either only one file exists and the file attribute can be specified. You can either specify one dir for multiple files.

In addition, you can embed <patternset/> and <slector/>

 

The following is an official example:

Use the child element of <patternset/>:

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

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

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

</Fileset>

 

Use embedded <patternset/>:
<fileset dir="${server.src}" casesensitive="yes">
  <patternset id="non.test.sources">
    <include name="**/*.java"/>
    <exclude name="**/*Test*"/>
  </patternset>
</fileset>

 

Use selector:
<fileset dir="${server.src}" casesensitive="yes">
  <filename name="**/*.java"/>
  <not>
    <filename name="**/*Test*"/>
  </not>
</fileset>

 

 

Selector

Patterset is matched based on the file name. Sometimes you want to delete an expired file or upload a changed file to a remote site. What method do you want to delete the file and keep the directory? Selector can refine the selection of files.

 

It can also be seen that selector is divided into two types: Commonly Used selector and selector container.

There can be multiple selectors in the selector container.

 

Common selector:

  • <Contains>-Select files that contain a participant text string
  • <Date>-Select files that have been modified either before or after a participant date and time
  • <Depend>-Select files that have been modified more recently than equivalent files elsewhere
  • <Depth>-Select files that appear so far directories down in a directory tree
  • <Different>-Select files that are different from those elsewhere
  • <Filename>-Select files whose name matches a participant 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 participant 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.

 

 

Common selector containers:

  • <And>
  • <Contains>
  • <Custom>
  • <Date>
  • <Depend>
  • <Depth>
  • <Filename>
  • <Majority>
  • <None>
  • <Not>
  • <Or>
  • <Present>
  • <Selector>
  • <Size>

 

 

For details about how to use selector, refer to the official documentation:

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

 

 

FileList

FileList is a List and an ordered set. If you want to use an ordered file set, you can use this.

Attribute

Description

Required

Dir

Root directory

Yes

Files

File List, separated by spaces or commas

If <file/> is not embedded,

You must specify this attribute.

 

 

<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 is used to specify the PATH, such as Path and ClassPath in the environment variable. When defining a path, use: Or; to separate it. (Note: When writing build. xml, you can use: Or ;. It is automatically converted from Ant to the corresponding separator Based on the operating system .)

The <classpath> and <path/> methods are the same. <Path/> can contain <pathelement/> and other resource sets (such as fileset, filelist, dirset, and path)

 

<Pathelement>Instructions for use

 

Pathelement can specify two attributes:

· Location is used to specify a file or directory. It can be a relative path or an absolute path. If it is a relative path, it is relative to the basedir of the project.

· Path multiple locations separated by, or.

<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>

 

 

Each path and classpath also have two attributes: id and refid.

Id is referenced by refid elsewhere.

<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 represents a regular expression. You can specify the id attribute for other places (such as task or selector.

Attribute

Description

Required

Pattern

Regular expression pattern

Yes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.