Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class FixCRLF

extends MatchingTask
implements ChainableReader
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.filters.ChainableReader
Imports
java.io.BufferedReader, .File, .FileReader, .IOException, .InputStreamReader, .Reader, java.nio.file.Files, java.util.Enumeration, .NoSuchElementException, .Vector, org.apache.tools.ant.BuildException, .DirectoryScanner, .Project, org.apache.tools.ant.filters.ChainableReader, .FixCrLfFilter, org.apache.tools.ant.types.EnumeratedAttribute, .FilterChain, org.apache.tools.ant.util.FileUtils

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
FixCRLF.AddAsisRemove

Enumerated attribute with the values "asis", "add" and "remove".

public static class
FixCRLF.CrLf

Enumerated attribute with the values "asis", "cr", "lf", "crlf", "mac", "unix" and "dos.

protected class
FixCRLF.OneLiner

Deprecated since 1.7.0.
Deprecated, the functionality has been moved to filters.FixCrLfFilter.

Field Summary

Modifier and TypeField and Description
private File
private String
encoding

Encoding to assume for the files

public static final String
ERROR_FILE_AND_SRCDIR

error string for using srcdir and file

private Vector<FilterChain>
private File
private static final FileUtils
private FixCrLfFilter
private static final String
private String
outputEncoding

Encoding to use for output files

private boolean
private File
Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
fileset

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final Reader

Returns:

a Reader.
chain
(final Reader
Reader to chain.
rdr
)

Implements org.apache.tools.ant.filters.ChainableReader.chain.

Chain this task as a reader.
public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Executes the task.
private void
public void
setCr(FixCRLF.AddAsisRemove
valid values:
  • add: ensure that there is a CR before every LF
  • asis: leave CR characters alone
  • remove: remove all CR characters
attr
)

Deprecated since 1.4.x. Use setEol instead.
Specify how carriage return (CR) characters are to be handled.
public void
setDestdir(File
the destination directory.
destDir
)

Set the destination where the fixed files should be placed.

public void
setEncoding(String
String encoding name.
encoding
)

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

public void
setEof(FixCRLF.AddAsisRemove
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
attr
)

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

public void
setEol(FixCRLF.CrLf
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
attr
)

Specify how EndOfLine characters are to be handled.

public void
setFile(File
the file to convert.
file
)

Set a single file to convert.

public void
setFixlast(boolean
whether to fix the last line.
fixlast
)

Specify whether a missing EOL will be added to the final line of a file.

public void
setJavafiles(boolean
whether modifying Java files.
javafiles
)

Set to true if modifying Java source files.

public void
setOutputEncoding(String
String outputEncoding name.
outputEncoding
)

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

public void
setPreserveLastModified(boolean
true if timestamps should be preserved.
preserve
)

Set whether to preserve the last modified time as the original files.

public void
setSrcdir(File
the source directory.
srcDir
)

Set the source dir to find the source text files.

public void
setTab(FixCRLF.AddAsisRemove
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
attr
)

Specify how tab characters are to be handled.

public void
setTablength(int
specify the length of tab in spaces.
tlength
)

Specify tab length in characters.

private void
Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
addaddAndaddContainsaddContainsRegexpaddCustomaddDateaddDependaddDepthaddDifferentaddFilenameaddMajorityaddModifiedaddNoneaddNotaddOraddPresentaddSelectoraddSizeaddTypeappendSelectorcreateExcludecreateExcludesFilecreateIncludecreateIncludesFilecreatePatternSetgetDirectoryScannergetImplicitFileSetgetSelectorshasSelectorsselectorCountselectorElementssetCaseSensitivesetDefaultexcludessetExcludessetExcludesfilesetFollowSymlinkssetIncludessetIncludesfilesetProjectXsetIgnoreXsetItems

Field Detail

destDirback to summary
private File destDir
encodingback to summary
private String encoding

Encoding to assume for the files

ERROR_FILE_AND_SRCDIRback to summary
public static final String ERROR_FILE_AND_SRCDIR

error string for using srcdir and file

fcvback to summary
private Vector<FilterChain> fcv
fileback to summary
private File file
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
filterback to summary
private FixCrLfFilter filter
FIXCRLF_ERRORback to summary
private static final String FIXCRLF_ERROR
outputEncodingback to summary
private String outputEncoding

Encoding to use for output files

preserveLastModifiedback to summary
private boolean preserveLastModified
srcDirback to summary
private File srcDir

Constructor Detail

FixCRLFback to summary
public FixCRLF()

Method Detail

chainback to summary
public final Reader chain(final Reader rdr)

Implements org.apache.tools.ant.filters.ChainableReader.chain.

Chain this task as a reader.

Parameters
rdr:Reader

Reader to chain.

Returns:Reader

a Reader.

Annotations
@Override
Since
Ant 1.7?
executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Executes the task.

Annotations
@Override
Exceptions
BuildException:
on error.
processFileback to summary
private void processFile(String file) throws BuildException
setCrback to summary
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:FixCRLF.AddAsisRemove

valid values:

  • add: ensure that there is a CR before every LF
  • asis: leave CR characters alone
  • remove: remove all CR characters
Annotations
@Deprecated
setDestdirback to summary
public void setDestdir(File destDir)

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

Parameters
destDir:File

the destination directory.

setEncodingback to summary
public void setEncoding(String encoding)

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

Parameters
encoding:String

String encoding name.

setEofback to summary
public void setEof(FixCRLF.AddAsisRemove attr)

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

Parameters
attr:FixCRLF.AddAsisRemove

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
setEolback to summary
public void setEol(FixCRLF.CrLf attr)

Specify how EndOfLine characters are to be handled.

Parameters
attr:FixCRLF.CrLf

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
setFileback to summary
public void setFile(File file)

Set a single file to convert.

Parameters
file:File

the file to convert.

Since
Ant 1.6.3
setFixlastback to summary
public void setFixlast(boolean fixlast)

Specify whether a missing EOL will be added to the final line of a file.

Parameters
fixlast:boolean

whether to fix the last line.

setJavafilesback to summary
public void setJavafiles(boolean javafiles)

Set to true if modifying Java source files.

Parameters
javafiles:boolean

whether modifying Java files.

setOutputEncodingback to summary
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

String outputEncoding name.

setPreserveLastModifiedback to summary
public void setPreserveLastModified(boolean preserve)

Set whether to preserve the last modified time as the original files.

Parameters
preserve:boolean

true if timestamps should be preserved.

Since
Ant 1.6.3
setSrcdirback to summary
public void setSrcdir(File srcDir)

Set the source dir to find the source text files.

Parameters
srcDir:File

the source directory.

setTabback to summary
public void setTab(FixCRLF.AddAsisRemove attr)

Specify how tab characters are to be handled.

Parameters
attr:FixCRLF.AddAsisRemove

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
setTablengthback to summary
public void setTablength(int tlength) throws BuildException

Specify tab length in characters.

Parameters
tlength:int

specify the length of tab in spaces.

Exceptions
BuildException:
on error.
validateback to summary
private void validate() throws BuildException
org.apache.tools.ant.taskdefs back to summary

public Class FixCRLF.AddAsisRemove

extends EnumeratedAttribute
Class Inheritance

Enumerated attribute with the values "asis", "add" and "remove".

Field Summary

Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]
getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement..
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Constructor Detail

AddAsisRemoveback to summary
public AddAsisRemove()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement..

Returns:String[]

an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

Annotations
@Override
org.apache.tools.ant.taskdefs back to summary

public Class FixCRLF.CrLf

extends EnumeratedAttribute
Class Inheritance

Enumerated attribute with the values "asis", "cr", "lf", "crlf", "mac", "unix" and "dos.

Field Summary

Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public
CrLf()

Method Summary

Modifier and TypeMethod and Description
public String[]
getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Constructor Detail

CrLfback to summary
public CrLf()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.

Returns:String[]

an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

Annotations
@Override
See Also
.
org.apache.tools.ant.taskdefs back to summary

protected Class FixCRLF.OneLiner

extends Object
implements Enumeration<Object>
Class Inheritance
All Implemented Interfaces
java.util.Enumeration
Annotations
@Deprecated

Deprecated

since 1.7.0.

Deprecated, the functionality has been moved to filters.FixCrLfFilter.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private static final char
private StringBuffer
private StringBuffer
private static final int
private StringBuffer
private static final int
private static final int
private static final int
private boolean
private BufferedReader
private File
private int
private static final int

Constructor Summary

AccessConstructor and Description
public
OneLiner(File
the file to read.
srcFile
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close the reader.

public String

Returns:

the eof string.
getEofStr
()

get the eof string.

public int

Returns:

the state.
getState
()

get the state.

public boolean

Returns:

true if there is more elements.
hasMoreElements
()

Implements java.util.Enumeration.hasMoreElements.

Tests if this enumeration contains more elements.
public Object

Returns:

the next element.
nextElement
()

Implements java.util.Enumeration.nextElement.

get the next element.
protected void
nextLine()

Move to the next line.

public void
setState(int
the value to use.
state
)

Set the state.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CTRLZback to summary
private static final char CTRLZ
eofStrback to summary
private StringBuffer eofStr
eolStrback to summary
private StringBuffer eolStr
INBUFLENback to summary
private static final int INBUFLEN
lineback to summary
private StringBuffer line
LINEBUFLENback to summary
private static final int LINEBUFLEN
LOOKINGback to summary
private static final int LOOKING
NOTJAVAback to summary
private static final int NOTJAVA
reachedEofback to summary
private boolean reachedEof
readerback to summary
private BufferedReader reader
srcFileback to summary
private File srcFile
stateback to summary
private int state
UNDEFback to summary
private static final int UNDEF

Constructor Detail

OneLinerback to summary
public OneLiner(File srcFile) throws BuildException

Constructor.

Parameters
srcFile:File

the file to read.

Exceptions
BuildException:
if there is an error.

Method Detail

closeback to summary
public void close() throws IOException

Close the reader.

Exceptions
IOException:
if there is an error.
getEofStrback to summary
public String getEofStr()

get the eof string.

Returns:String

the eof string.

getStateback to summary
public int getState()

get the state.

Returns:int

the state.

hasMoreElementsback to summary
public boolean hasMoreElements()

Implements java.util.Enumeration.hasMoreElements.

Doc from java.util.Enumeration.hasMoreElements.

Tests if this enumeration contains more elements.

Returns:boolean

true if there is more elements.

Annotations
@Override
nextElementback to summary
public Object nextElement() throws NoSuchElementException

Implements java.util.Enumeration.nextElement.

get the next element.

Returns:Object

the next element.

Annotations
@Override
Exceptions
NoSuchElementException:
if there is no more.
nextLineback to summary
protected void nextLine() throws BuildException

Move to the next line.

Exceptions
BuildException:
if there is an error.
setStateback to summary
public void setState(int state)

Set the state.

Parameters
state:int

the value to use.

org.apache.tools.ant.taskdefs back to summary

pack-priv Class FixCRLF.OneLiner.BufferLine

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private String
private String
private int
private int

Constructor Summary

AccessConstructor and Description
public
BufferLine(String line, String eolStr)

Method Summary

Modifier and TypeMethod and Description
public char
getChar(int i)

public int
public String
public int
public String
public int
public int
public char
public char
public int
public int
public int
public void
setColumn(int col)

public void
setLookahead(int lookahead)

public void
setNext(int next)

public void
setState(int state)

public String
substring(int begin)

public String
substring(int begin, int end)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

columnback to summary
private int column
eolStrback to summary
private String eolStr
lineback to summary
private String line
lookaheadback to summary
private int lookahead
nextback to summary
private int next

Constructor Detail

BufferLineback to summary
public BufferLine(String line, String eolStr) throws BuildException

Method Detail

getCharback to summary
public char getChar(int i)
getColumnback to summary
public int getColumn()
getEolback to summary
public String getEol()
getEolLengthback to summary
public int getEolLength()
getLineStringback to summary
public String getLineString()
getLookaheadback to summary
public int getLookahead()
getNextback to summary
public int getNext()
getNextCharback to summary
public char getNextChar()
getNextCharIncback to summary
public char getNextCharInc()
getStateback to summary
public int getState()
incColumnback to summary
public int incColumn()
lengthback to summary
public int length()
setColumnback to summary
public void setColumn(int col)
setLookaheadback to summary
public void setLookahead(int lookahead)
setNextback to summary
public void setNext(int next)
setStateback to summary
public void setState(int state)
substringback to summary
public String substring(int begin)
substringback to summary
public String substring(int begin, int end)