Methods Summary |
---|
public final java.io.Reader | chain(java.io.Reader rdr)Chain this task as a reader.
return filter.chain(rdr);
|
public void | execute()Executes the task.
// first off, make sure that we've got a srcdir and destdir
validate();
// log options used
String enc = encoding == null ? "default" : encoding;
log("options:"
+ " eol=" + filter.getEol().getValue()
+ " tab=" + filter.getTab().getValue()
+ " eof=" + filter.getEof().getValue()
+ " tablength=" + filter.getTablength()
+ " encoding=" + enc
+ " outputencoding="
+ (outputEncoding == null ? enc : outputEncoding),
Project.MSG_VERBOSE);
DirectoryScanner ds = super.getDirectoryScanner(srcDir);
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
processFile(files[i]);
}
|
private void | processFile(java.lang.String file)
File srcFile = new File(srcDir, file);
long lastModified = srcFile.lastModified();
File destD = destDir == null ? srcDir : destDir;
if (fcv == null) {
FilterChain fc = new FilterChain();
fc.add(filter);
fcv = new Vector(1);
fcv.add(fc);
}
File tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null);
tmpFile.deleteOnExit();
try {
FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, false, false,
encoding, outputEncoding == null ? encoding : outputEncoding,
getProject());
File destFile = new File(destD, file);
boolean destIsWrong = true;
if (destFile.exists()) {
// Compare the destination with the temp file
log("destFile exists", Project.MSG_DEBUG);
destIsWrong = !FILE_UTILS.contentEquals(destFile, tmpFile);
log(destFile + (destIsWrong ? " is being written"
: " is not written, as the contents are identical"),
Project.MSG_DEBUG);
}
if (destIsWrong) {
FILE_UTILS.rename(tmpFile, destFile);
if (preserveLastModified) {
log("preserved lastModified", Project.MSG_DEBUG);
FILE_UTILS.setFileLastModified(destFile, lastModified);
}
tmpFile = null;
}
} catch (IOException e) {
throw new BuildException(e);
}
|
public void | setCr(org.apache.tools.ant.taskdefs.FixCRLF$AddAsisRemove attr)Specify how carriage return (CR) characters are to be handled.
log("DEPRECATED: The cr attribute has been deprecated,",
Project.MSG_WARN);
log("Please use the eol attribute instead", Project.MSG_WARN);
String option = attr.getValue();
CrLf c = new CrLf();
if (option.equals("remove")) {
c.setValue("lf");
} else if (option.equals("asis")) {
c.setValue("asis");
} else {
// must be "add"
c.setValue("crlf");
}
setEol(c);
|
public void | setDestdir(java.io.File destDir)Set the destination where the fixed files should be placed.
Default is to replace the original file.
this.destDir = destDir;
|
public void | setEncoding(java.lang.String encoding)Specifies the encoding Ant expects the files to be
in--defaults to the platforms default encoding.
this.encoding = encoding;
|
public void | setEof(org.apache.tools.ant.taskdefs.FixCRLF$AddAsisRemove attr)Specify how DOS EOF (control-z) characters are to be handled.
filter.setEof(FixCrLfFilter.AddAsisRemove.newInstance(attr.getValue()));
|
public void | setEol(org.apache.tools.ant.taskdefs.FixCRLF$CrLf attr)Specify how EndOfLine characters are to be handled.
filter.setEol(FixCrLfFilter.CrLf.newInstance(attr.getValue()));
|
public void | setFile(java.io.File file)Set a single file to convert.
this.file = file;
|
public void | setFixlast(boolean fixlast)Specify whether a missing EOL will be added
to the final line of a file.
filter.setFixlast(fixlast);
|
public void | setJavafiles(boolean javafiles)Set to true if modifying Java source files.
filter.setJavafiles(javafiles);
|
public void | setOutputEncoding(java.lang.String outputEncoding)Specifies the encoding that the files are
to be written in--same as input encoding by default.
this.outputEncoding = outputEncoding;
|
public void | setPreserveLastModified(boolean preserve)Set whether to preserve the last modified time as the original files.
preserveLastModified = preserve;
|
public void | setSrcdir(java.io.File srcDir)Set the source dir to find the source text files.
this.srcDir = srcDir;
|
public void | setTab(org.apache.tools.ant.taskdefs.FixCRLF$AddAsisRemove attr)Specify how tab characters are to be handled.
filter.setTab(FixCrLfFilter.AddAsisRemove.newInstance(attr.getValue()));
|
public void | setTablength(int tlength)Specify tab length in characters.
try {
filter.setTablength(tlength);
} catch (IOException e) {
throw new BuildException(e);
}
|
private void | validate()
if (file != null) {
if (srcDir != null) {
throw new BuildException(ERROR_FILE_AND_SRCDIR);
}
//patch file into the fileset
fileset.setFile(file);
//set our parent dir
srcDir = file.getParentFile();
}
if (srcDir == null) {
throw new BuildException("srcdir attribute must be set!");
}
if (!srcDir.exists()) {
throw new BuildException("srcdir does not exist!");
}
if (!srcDir.isDirectory()) {
throw new BuildException("srcdir is not a directory!");
}
if (destDir != null) {
if (!destDir.exists()) {
throw new BuildException("destdir does not exist!");
}
if (!destDir.isDirectory()) {
throw new BuildException("destdir is not a directory!");
}
}
|