org.apache.tools.ant.taskdefs

## Class FixCRLF

- java.lang.Object
- - org.apache.tools.ant.ProjectComponent
  - - org.apache.tools.ant.Task
    - - org.apache.tools.ant.taskdefs.MatchingTask
      - - org.apache.tools.ant.taskdefs.FixCRLF

All Implemented Interfaces:
  java.lang.Cloneable, ChainableReader, SelectorContainer

    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:

- srcdir
- destdir
- include
- exclude
- cr
- eol
- tab
- eof
- encoding
- targetencoding

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

### Nested Class Summary

Nested Classes
`static class` `FixCRLF.AddAsisRemove` Enumerated attribute with the values "asis", "add" and "remove".
`static class` `FixCRLF.CrLf` Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
`protected class` `FixCRLF.OneLiner` Deprecated. since 1.7.0.

### Field Summary

Fields
`static java.lang.String` `ERROR_FILE_AND_SRCDIR` error string for using srcdir and file

### Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask

`fileset`

### Fields inherited from class org.apache.tools.ant.Task

`target, taskName, taskType, wrapper`

### Fields inherited from class org.apache.tools.ant.ProjectComponent

`description, location, project`

### Constructor Summary

Constructors
Constructor and Description
`FixCRLF()`

### Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods
`java.io.Reader` `chain(java.io.Reader rdr)` Chain this task as a reader.
`void` `execute()` Executes the task.
`void` `setCr(FixCRLF.AddAsisRemove attr)` Deprecated. since 1.4.x. Use `setEol` instead.
`void` `setDestdir(java.io.File destDir)` Set the destination where the fixed files should be placed.
`void` `setEncoding(java.lang.String encoding)` Specifies the encoding Ant expects the files to be in--defaults to the platforms default encoding.
`void` `setEof(FixCRLF.AddAsisRemove attr)` Specify how DOS EOF (control-z) characters are to be handled.
`void` `setEol(FixCRLF.CrLf attr)` Specify how EndOfLine characters are to be handled.
`void` `setFile(java.io.File file)` Set a single file to convert.
`void` `setFixlast(boolean fixlast)` Specify whether a missing EOL will be added to the final line of a file.
`void` `setJavafiles(boolean javafiles)` Set to true if modifying Java source files.
`void` `setOutputEncoding(java.lang.String outputEncoding)` Specifies the encoding that the files are to be written in--same as input encoding by default.
`void` `setPreserveLastModified(boolean preserve)` Set whether to preserve the last modified time as the original files.
`void` `setSrcdir(java.io.File srcDir)` Set the source dir to find the source text files.
`void` `setTab(FixCRLF.AddAsisRemove attr)` Specify how tab characters are to be handled.
`void` `setTablength(int tlength)` Specify tab length in characters.

### Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask

`add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems`

### Methods inherited from class org.apache.tools.ant.Task

`bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType`

### Methods inherited from class org.apache.tools.ant.ProjectComponent

`clone, getDescription, getLocation, getProject, setDescription, setLocation`

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### ERROR_FILE_AND_SRCDIR

    public static final java.lang.String ERROR_FILE_AND_SRCDIR

error string for using srcdir and file

See Also:
  Constant Field Values

### Constructor Detail

#### FixCRLF

    public FixCRLF()

### Method Detail

#### chain

    public final java.io.Reader chain(java.io.Reader rdr)

Chain this task as a reader.

Specified by:
  `chain` in interface `ChainableReader`
Parameters:
  `rdr` - Reader to chain.
Returns:
  a Reader.
Since:
  Ant 1.7?

#### setSrcdir

    public void setSrcdir(java.io.File srcDir)

Set the source dir to find the source text files.

Parameters:
  `srcDir` - the source directory.

#### setDestdir

    public void setDestdir(java.io.File destDir)

Set the destination where the fixed files should be placed. Default is to replace the original file.

Parameters:
  `destDir` - the destination directory.

#### setJavafiles

    public void setJavafiles(boolean javafiles)

Set to true if modifying Java source files.

Parameters:
  `javafiles` - whether modifying Java files.

#### setFile

    public void setFile(java.io.File file)

Set a single file to convert.

Parameters:
  `file` - the file to convert.
Since:
  Ant 1.6.3

#### setEol

    public void setEol(FixCRLF.CrLf attr)

Specify how EndOfLine characters are to be handled.

Parameters:
  `attr` - valid values:
  - asis: leave line endings alone
  - cr: convert line endings to CR
  - lf: convert line endings to LF
  - crlf: convert line endings to CRLF

#### setCr

    public void setCr(FixCRLF.AddAsisRemove attr)

Deprecated. since 1.4.x. Use `setEol` instead.
Specify how carriage return (CR) characters are to be handled.

Parameters:
  `attr` - valid values:
  - add: ensure that there is a CR before every LF
  - asis: leave CR characters alone
  - remove: remove all CR characters

#### setTab

    public void setTab(FixCRLF.AddAsisRemove attr)

Specify how tab characters are to be handled.

Parameters:
  `attr` - valid values:
  - add: convert sequences of spaces which span a tab stop to tabs
  - asis: leave tab and space characters alone
  - remove: convert tabs to spaces

#### setTablength

    public void setTablength(int tlength)
                      throws BuildException

Specify tab length in characters.

Parameters:
  `tlength` - specify the length of tab in spaces.
Throws:
  `BuildException` - on error.

#### setEof

    public void setEof(FixCRLF.AddAsisRemove attr)

Specify how DOS EOF (control-z) characters are to be handled.

Parameters:
  `attr` - valid values:
  - add: ensure that there is an eof at the end of the file
  - asis: leave eof characters alone
  - remove: remove any eof character found at the end

#### setEncoding

    public void setEncoding(java.lang.String encoding)

Specifies the encoding Ant expects the files to be in--defaults to the platforms default encoding.

Parameters:
  `encoding` - String encoding name.

#### setOutputEncoding

    public void setOutputEncoding(java.lang.String outputEncoding)

Specifies the encoding that the files are to be written in--same as input encoding by default.

Parameters:
  `outputEncoding` - String outputEncoding name.

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

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

#### execute

    public void execute()
                 throws BuildException

Executes the task.

Overrides:
  `execute` in class `Task`
Throws:
  `BuildException` - on error.