org.apache.tools.ant.taskdefs

Class FixCRLF

public class FixCRLF extends MatchingTask implements ChainableReader

Converts text source files to local OS formatting conventions, as well as repair text files damaged by misconfigured or misguided editors or file transfer programs.

This task can take the following arguments:

Of these arguments, only sourcedir is required.

When this task executes, it will scan the srcdir based on the include and exclude properties.

This version generalises the handling of EOL characters, and allows for CR-only line endings (the standard on Mac systems prior to OS X). Tab handling has also been generalised to accommodate any tabwidth from 2 to 80, inclusive. Importantly, it will leave untouched any literal TAB characters embedded within string or character constants.

Warning: do not run on binary files. Caution: run with care on carefully formatted files. This may sound obvious, but if you don't specify asis, presume that your files are going to be modified. If "tabs" is "add" or "remove", whitespace characters may be added or removed as necessary. Similarly, for CR's - in fact "eol"="crlf" or cr="add" can result in cr characters being removed in one special case accommodated, i.e., CRCRLF is regarded as a single EOL to handle cases where other programs have converted CRLF into CRCRLF.

Since: Ant 1.1

UNKNOWN: category="filesystem"

Nested Class Summary
static classFixCRLF.AddAsisRemove
Enumerated attribute with the values "asis", "add" and "remove".
static classFixCRLF.CrLf
Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
protected classFixCRLF.OneLiner
Deprecated, the functionality has been moved to filters.FixCrLfFilter.
Field Summary
static StringERROR_FILE_AND_SRCDIR
error string for using srcdir and file
Method Summary
Readerchain(Reader rdr)
Chain this task as a reader.
voidexecute()
Executes the task.
voidsetCr(FixCRLF.AddAsisRemove attr)
Specify how carriage return (CR) characters are to be handled.
voidsetDestdir(File destDir)
Set the destination where the fixed files should be placed.
voidsetEncoding(String encoding)
Specifies the encoding Ant expects the files to be in--defaults to the platforms default encoding.
voidsetEof(FixCRLF.AddAsisRemove attr)
Specify how DOS EOF (control-z) characters are to be handled.
voidsetEol(FixCRLF.CrLf attr)
Specify how EndOfLine characters are to be handled.
voidsetFile(File file)
Set a single file to convert.
voidsetFixlast(boolean fixlast)
Specify whether a missing EOL will be added to the final line of a file.
voidsetJavafiles(boolean javafiles)
Set to true if modifying Java source files.
voidsetOutputEncoding(String outputEncoding)
Specifies the encoding that the files are to be written in--same as input encoding by default.
voidsetPreserveLastModified(boolean preserve)
Set whether to preserve the last modified time as the original files.
voidsetSrcdir(File srcDir)
Set the source dir to find the source text files.
voidsetTab(FixCRLF.AddAsisRemove attr)
Specify how tab characters are to be handled.
voidsetTablength(int tlength)
Specify tab length in characters.

Field Detail

ERROR_FILE_AND_SRCDIR

public static final String ERROR_FILE_AND_SRCDIR
error string for using srcdir and file

Method Detail

chain

public final Reader chain(Reader rdr)
Chain this task as a reader.

Parameters: rdr Reader to chain.

Returns: a Reader.

Since: Ant 1.7?

execute

public void execute()
Executes the task.

Throws: BuildException on error.

setCr

public void setCr(FixCRLF.AddAsisRemove attr)

Deprecated: since 1.4.x. Use {@link #setEol setEol} instead.

Specify how carriage return (CR) characters are to be handled.

Parameters: attr valid values:

setDestdir

public void setDestdir(File destDir)
Set the destination where the fixed files should be placed. Default is to replace the original file.

Parameters: destDir the destination directory.

setEncoding

public void setEncoding(String encoding)
Specifies the encoding Ant expects the files to be in--defaults to the platforms default encoding.

Parameters: encoding String encoding name.

setEof

public void setEof(FixCRLF.AddAsisRemove attr)
Specify how DOS EOF (control-z) characters are to be handled.

Parameters: attr valid values:

setEol

public void setEol(FixCRLF.CrLf attr)
Specify how EndOfLine characters are to be handled.

Parameters: attr valid values:

setFile

public void setFile(File file)
Set a single file to convert.

Parameters: file the file to convert.

Since: Ant 1.6.3

setFixlast

public void setFixlast(boolean fixlast)
Specify whether a missing EOL will be added to the final line of a file.

Parameters: fixlast whether to fix the last line.

setJavafiles

public void setJavafiles(boolean javafiles)
Set to true if modifying Java source files.

Parameters: javafiles whether modifying Java files.

setOutputEncoding

public void setOutputEncoding(String outputEncoding)
Specifies the encoding that the files are to be written in--same as input encoding by default.

Parameters: outputEncoding String outputEncoding name.

setPreserveLastModified

public void setPreserveLastModified(boolean preserve)
Set whether to preserve the last modified time as the original files.

Parameters: preserve true if timestamps should be preserved.

Since: Ant 1.6.3

setSrcdir

public void setSrcdir(File srcDir)
Set the source dir to find the source text files.

Parameters: srcDir the source directory.

setTab

public void setTab(FixCRLF.AddAsisRemove attr)
Specify how tab characters are to be handled.

Parameters: attr valid values:

setTablength

public void setTablength(int tlength)
Specify tab length in characters.

Parameters: tlength specify the length of tab in spaces.

Throws: BuildException on error.