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-ffa450edef68master
| @@ -219,6 +219,12 @@ supports all attributes of <code><fileset></code> | |||||
| <td valign="top">The encoding of the files</td> | <td valign="top">The encoding of the files</td> | ||||
| <td align="center">No - defaults to default JVM encoding</td> | <td align="center">No - defaults to default JVM encoding</td> | ||||
| </tr> | </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> | </table> | ||||
| <h3>Examples</h3> | <h3>Examples</h3> | ||||
| <pre> <fixcrlf srcdir="${src}" | <pre> <fixcrlf srcdir="${src}" | ||||
| @@ -271,9 +277,8 @@ EOF characters are left alone if run on | |||||
| DOS systems, and are removed if run on Unix systems. | DOS systems, and are removed if run on Unix systems. | ||||
| You never know what editor a user will use to browse README's.</p> | You never know what editor a user will use to browse README's.</p> | ||||
| <hr> | <hr> | ||||
| <p align="center">Copyright © 2000-2003 Apache Software Foundation. All rights | |||||
| <p align="center">Copyright © 2000-2004 Apache Software Foundation. All rights | |||||
| Reserved.</p> | Reserved.</p> | ||||
| </body> | </body> | ||||
| </html> | </html> | ||||
| @@ -142,6 +142,21 @@ | |||||
| /> | /> | ||||
| </target> | </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 --> | <!-- Bugzilla Report 20840 --> | ||||
| <target name="createParentDirs" depends="init"> | <target name="createParentDirs" depends="init"> | ||||
| <fixcrlf srcdir="." destdir="result" includes="input/Junk1.java"/> | <fixcrlf srcdir="." destdir="result" includes="input/Junk1.java"/> | ||||
| @@ -0,0 +1,2 @@ | |||||
| 12345 | |||||
| 6789 | |||||
| @@ -0,0 +1 @@ | |||||
| 12345 6789 | |||||
| @@ -0,0 +1,2 @@ | |||||
| 12345 | |||||
| 6789 | |||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * 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 ctrlz; | ||||
| private int tabs; | private int tabs; | ||||
| private boolean javafiles = false; | private boolean javafiles = false; | ||||
| private boolean fixlast = true; | |||||
| private File srcDir; | private File srcDir; | ||||
| private File destDir = null; | private File destDir = null; | ||||
| @@ -338,6 +339,14 @@ public class FixCRLF extends MatchingTask { | |||||
| this.encoding = encoding; | 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. | * Executes the task. | ||||
| */ | */ | ||||
| @@ -515,11 +524,13 @@ public class FixCRLF extends MatchingTask { | |||||
| } // end of else (tabs != ASIS) | } // 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()) | } // end of while (lines.hasNext()) | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| @@ -76,7 +76,7 @@ public class FixCrLfTest extends BuildFileTest { | |||||
| } | } | ||||
| public void tearDown() { | public void tearDown() { | ||||
| executeTarget("cleanup"); | |||||
| //executeTarget("cleanup"); | |||||
| } | } | ||||
| public void test1() throws IOException { | public void test1() throws IOException { | ||||
| @@ -202,6 +202,18 @@ public class FixCrLfTest extends BuildFileTest { | |||||
| new File("src/etc/testcases/taskdefs/fixcrlf/result/crcrlf")); | 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 | * Bugzilla Report 20840 | ||||
| * | * | ||||