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

public class FixCRLF
extends MatchingTask

Task to convert 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 (which I suspect is the standard on Macs.) 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.

Version:
$Revision: 1.18 $ $Name: $
Author:
Sam Ruby rubys@us.ibm.com, Peter B. West

Inner Class Summary
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".
 
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
fileset, useDefaultExcludes
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
FixCRLF()
          Defaults the properties based on the system type.
 
Method Summary
 void execute()
          Executes the task.
 void setCr(FixCRLF.AddAsisRemove attr)
          Deprecated. use setEol instead.
 void setDestdir(java.io.File destDir)
          Set the destination where the fixed files should be placed.
 void setEof(FixCRLF.AddAsisRemove attr)
          Specify how DOS EOF (control-z) charaters are to be handled
 void setEol(FixCRLF.CrLf attr)
          Specify how EndOfLine characters are to be handled
 void setJavafiles(boolean javafiles)
          Fixing Java source 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
createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, setDefaultexcludes, setExcludes, setExcludesfile, setIncludes, setIncludesfile, XsetIgnore, XsetItems
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixCRLF

public FixCRLF()
Defaults the properties based on the system type.
Method Detail

setSrcdir

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

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.

setJavafiles

public void setJavafiles(boolean javafiles)
Fixing Java source files?

setEol

public void setEol(FixCRLF.CrLf attr)
Specify how EndOfLine characters are to be handled
Parameters:
option - 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. use setEol instead.

Specify how carriage return (CR) characters are to be handled
Parameters:
option - 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:
option - 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,

setEof

public void setEof(FixCRLF.AddAsisRemove attr)
Specify how DOS EOF (control-z) charaters are to be handled
Parameters:
option - 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

execute

public void execute()
             throws BuildException
Executes the task.
Overrides:
execute in class Task
Following copied from class: org.apache.tools.ant.Task
Throws:
BuildException - if someting goes wrong with the build


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.