net.groboclown.ant.v1
Class Concat

java.lang.Object
  |
  +--org.apache.tools.ant.Task
        |
        +--net.groboclown.ant.v1.Concat

public class Concat
extends org.apache.tools.ant.Task

Concatenates one or more files together. The concatenation joins a collection of files into a single file, in order of the collection's appearance. If the output file already exists, then several options may be used: "append" joins the collection to the end of the file, "overwrite" eliminates the existing contents and replaces it with the collection, and "error" generates a build error when the output file exists.

For filtering, you can set either the global filter (which is by default "no"), or on a file-by-file basis. If the individual's filtering is not set, then it uses the global filtering setting.

Note that filtering should only be applied to non-binary files, since it reads in the file line-by-ine, and outputs the file in the operating system's default CR-LF format.

Parameters

Attribute Description Required
outfile The filename to send the concatenated files to. If the file already exists, then the appropriate action is dicated by the whenexists attribute. Yes
whenexists Behavior when the output file already exists. Applicable values are "overwrite", "append", and "error". Defaults to "overwrite&qupt;. No
filtering "yes" or "no". Indicates whether token filtering should take place during the copy. Defaults to "no". No

Since FileSets do not dictate the file order, you must specify each concatenated file in order. Each file is contained in an addfile tag:

Parameters

Attribute Description Required
name The name of the file to insert into the output file. Yes
filtering "yes" or "no". Indicates whether token filtering should take place during the inclusion. Defaults to the concat filtering setting when not specified. No

Examples

      <concat outfile="out.txt">
          <addfile name="1.txt" />
          <addfile name="2.txt" />
      </concat>
 
Concatenate the files "1.txt" and "2.txt" into the file "out.txt". If "out.txt" already exists, then it is replaced by the concatenated text.

      <concat outfile="1.txt" whenexists="append">
          <addfile name="2.txt" />
      </concat>
 
Copies "2.txt" into the file "1.txt". If "1.txt" already exists, then it appends the contents of "2.txt" to the end of "1.txt".

      <concat outfile="out.txt" whenexists="error" filtering="yes" >
          <addfile name="1.txt" filtering="no" />
          <addfile name="2.txt" />
          <addfile name="3.txt" filtering="yes" />
      </concat>
 
Creates a file "out.txt" which contains the contents of "1.txt", followed immediately by the contents of "2.txt", which is followed immediately by the contents of "3.txt". If the file "out.txt" already exists, then a build error is generated. The file "1.txt" does not have any filtering applied to it, while "2.txt" and "3.txt" have filtering.

Author:
Matt Albrecht <@a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net

Inner Class Summary
private static class Concat.ErrorOperation
           
static class Concat.FileOrder
           
private static class Concat.OpenOperation
           
private static class Concat.Operation
          An enumeration...
 
Field Summary
private static Concat.Operation APPEND
           
private static Concat.Operation ERROR
           
protected  Vector fileOrder
           
protected  boolean filtering
           
protected  Concat.Operation operation
           
private static String OPERATION_LIST
           
private static Concat.Operation[] OPERATIONS
           
protected  String operationType
           
protected  File outfile
           
private static Concat.Operation OVERWRITE
           
 
Fields inherited from class org.apache.tools.ant.Task
description, location, project, target, taskName, taskType, wrapper
 
Constructor Summary
Concat()
           
 
Method Summary
 void appendFile(BufferedWriter out, File next, boolean filter)
          Append the given file to the stream.
 Concat.FileOrder createAddFile()
          Create a new file entry.
 void execute()
          Execute the task.
 String replace(String s, Hashtable tokens)
          Does replacement on the given string using the given token table.
 void setFiltering(boolean filtering)
          Sets filtering.
 void setOutfile(File outfile)
          Sets the Outfile attribute of the Cat object
 void setWhenExists(String operation)
           
protected  void validateAttributes()
          Ensure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes.
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getProject, getRuntimeConfigurableWrapper, getTaskName, init, log, log, maybeConfigure, setDescription, setLocation, setOwningTarget, setProject, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

outfile

protected File outfile

fileOrder

protected Vector fileOrder

filtering

protected boolean filtering

operation

protected Concat.Operation operation

operationType

protected String operationType

ERROR

private static final Concat.Operation ERROR

OVERWRITE

private static final Concat.Operation OVERWRITE

APPEND

private static final Concat.Operation APPEND

OPERATION_LIST

private static final String OPERATION_LIST

OPERATIONS

private static final Concat.Operation[] OPERATIONS
Constructor Detail

Concat

public Concat()
Method Detail

setOutfile

public void setOutfile(File outfile)
Sets the Outfile attribute of the Cat object
Parameters:
outfile - The new Outfile value
Since:
 

setWhenExists

public void setWhenExists(String operation)

createAddFile

public Concat.FileOrder createAddFile()
Create a new file entry.

setFiltering

public void setFiltering(boolean filtering)
Sets filtering.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Execute the task.
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - Description of Exception
Since:
 

appendFile

public void appendFile(BufferedWriter out,
                       File next,
                       boolean filter)
                throws IOException
Append the given file to the stream.

validateAttributes

protected void validateAttributes()
                           throws org.apache.tools.ant.BuildException
Ensure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes.

replace

public String replace(String s,
                      Hashtable tokens)
Does replacement on the given string using the given token table. Pulled from ant.Project - too bad it's private under Project.


Written under the LGPL