Browse Source

fix for CRLF adds extraneous character at the end of File

if a file does not end in an eol, fixcrlf will add an eol
this patch adds an attribute to fixcrlf to stop this behaviour
PR:  23262
Obtained from: gudnabrsam at yahoo dot com


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275886 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
f5921264e5
7 changed files with 58 additions and 10 deletions
  1. +7
    -2
      docs/manual/CoreTasks/fixcrlf.html
  2. +15
    -0
      src/etc/testcases/taskdefs/fixcrlf/build.xml
  3. +2
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos
  4. +1
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac
  5. +2
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/fixlastfalse.lf
  6. +17
    -6
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  7. +14
    -2
      src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java

+ 7
- 2
docs/manual/CoreTasks/fixcrlf.html View File

@@ -219,6 +219,12 @@ supports all attributes of <code>&lt;fileset&gt;</code>
<td valign="top">The encoding of the files</td>
<td align="center">No - defaults to default JVM encoding</td>
</tr>
<tr>
<td valign="top">fixlast</td>
<td valign="top">Whether to add a missing EOL to the last line
of a processed file. (Since ant 1.6.1)</td>
<td align="center">No - default is <i>true</i></td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;fixcrlf srcdir=&quot;${src}&quot;
@@ -271,9 +277,8 @@ EOF characters are left alone if run on
DOS systems, and are removed if run on Unix systems.
You never know what editor a user will use to browse README's.</p>
<hr>
<p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2000-2004 Apache Software Foundation. All rights
Reserved.</p>

</body>
</html>


+ 15
- 0
src/etc/testcases/taskdefs/fixcrlf/build.xml View File

@@ -142,6 +142,21 @@
/>
</target>

<target name="testFixlastDos" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="fixlastfalse.lf"
eol="crlf"
/>
</target>

<target name="testFixlastFalseMac" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="fixlastfalse.lf"
eol="cr"
fixlast="false"
/>
</target>

<!-- Bugzilla Report 20840 -->
<target name="createParentDirs" depends="init">
<fixcrlf srcdir="." destdir="result" includes="input/Junk1.java"/>


+ 2
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos View File

@@ -0,0 +1,2 @@
12345
6789

+ 1
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac View File

@@ -0,0 +1 @@
12345 6789

+ 2
- 0
src/etc/testcases/taskdefs/fixcrlf/input/fixlastfalse.lf View File

@@ -0,0 +1,2 @@
12345
6789

+ 17
- 6
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* Copyright (c) 2000-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -154,6 +154,7 @@ public class FixCRLF extends MatchingTask {
private int ctrlz;
private int tabs;
private boolean javafiles = false;
private boolean fixlast = true;

private File srcDir;
private File destDir = null;
@@ -338,6 +339,14 @@ public class FixCRLF extends MatchingTask {
this.encoding = encoding;
}

/**
* Specify whether a missing EOL will be added
* to the final line of a file.
*/
public void setFixlast(boolean fixlast) {
this.fixlast = fixlast;
}

/**
* Executes the task.
*/
@@ -515,11 +524,13 @@ public class FixCRLF extends MatchingTask {

} // end of else (tabs != ASIS)

try {
outWriter.write(eolstr);
} catch (IOException e) {
throw new BuildException(e);
} // end of try-catch
if (!("".equals(line.getEol())) || fixlast) {
try {
outWriter.write(eolstr);
} catch (IOException e) {
throw new BuildException(e);
} // end of try-catch
} //end if non-blank original eol or fixlast

} // end of while (lines.hasNext())



+ 14
- 2
src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* Copyright (c) 2001-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -76,7 +76,7 @@ public class FixCrLfTest extends BuildFileTest {
}
public void tearDown() {
executeTarget("cleanup");
//executeTarget("cleanup");
}
public void test1() throws IOException {
@@ -202,6 +202,18 @@ public class FixCrLfTest extends BuildFileTest {
new File("src/etc/testcases/taskdefs/fixcrlf/result/crcrlf"));
}

public void testFixlastDos() throws IOException {
executeTarget("testFixlastDos");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/fixlastfalse.lf"));
}

public void testFixlastFalseMac() throws IOException {
executeTarget("testFixlastFalseMac");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/fixlastfalse.lf"));
}

/**
* Bugzilla Report 20840
*


Loading…
Cancel
Save