Apache Ant Tasks - Concat



Description

Concat task concatenate one or more resources to a single file or to console. The destination file is created if it does not exist unless the resource list is empty and ignoreempty flag is true.

Properties

Sr.No Attributes & Description
1

Destfile

The destination file for the concatenated stream. If not specified the console will be used instead.

2

Append

Specifies whether or not the file specified by destfile should be appended.

3

Overwrite

Specifies whether or not the file specified by destfile should be written to even if it is newer than all source files.

4

ForceReadonly

Overwrite read-only destination files.

5

Encoding

Specifies the encoding for the input files.

6

Outputencoding

The encoding to use when writing the output file.

7

Fixlastline

Specifies whether or not to check if each file concatenated is terminated by a new line. If this attribute is yes a new line will be appended to the stream if the file did not end in a new line.

8

EOL

Specifies what the end of line character are for use by the fixlastline attribute.

9

Binary

If this attribute is set to true, the task concatenates the files in a byte by byte fashion. If this attribute is false, concat will not normally work for binary files due to character encoding issues. If this option is set to true, the destfile attribute must be set, and the task cannot used nested text. Also the attributes encoding, outputencoding, filelastline cannot be used.

10

Filterbeforeconcat

If this attribute is set to true, the task applies the filterchain to each input after applying fixlastline. If this attribute is false, concat will apply the filterchain only once to the already concatenated inputs. Filtering of header and footer is not affected by this setting.

11

Ignoreempty

Specifies whether or not the file specified by destfile should be created if the source resource list is empty.

12

Resourcename

Specifies the name reported if this task is exposed as a resource.

Example

Usage

Create build.xml with the following content −

<?xml version="1.0"?>
<project name="TutorialPoint" default="info">
   <target name="info">
      <concat>
         <fileset dir="messages" includes="*test*"/>
      </concat>
   </target>
</project>

Above script will read messages folder and concatenates contents of file having test in their name and show them on console.

Output

Let's create a test.txt with content as "Welcome to tutorialspoint.com" in messages folder. Now running Ant on the above build file produces the following output −

F:\tutorialspoint\ant>ant
Buildfile: F:\tutorialspoint\ant\build.xml

info:
   [concat] Welcome to tutorialspoint.com

BUILD SUCCESSFUL
Total time: 0 seconds
Advertisements