From f5921264e53af4c642939f5dc1e617363edd7865 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Fri, 9 Jan 2004 17:36:16 +0000 Subject: [PATCH] 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 --- docs/manual/CoreTasks/fixcrlf.html | 9 ++++++-- src/etc/testcases/taskdefs/fixcrlf/build.xml | 15 ++++++++++++ .../taskdefs/fixcrlf/expected/fixlast.dos | 2 ++ .../fixcrlf/expected/fixlastfalse.mac | 1 + .../taskdefs/fixcrlf/input/fixlastfalse.lf | 2 ++ .../apache/tools/ant/taskdefs/FixCRLF.java | 23 ++++++++++++++----- .../tools/ant/taskdefs/FixCrLfTest.java | 16 +++++++++++-- 7 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos create mode 100644 src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac create mode 100644 src/etc/testcases/taskdefs/fixcrlf/input/fixlastfalse.lf diff --git a/docs/manual/CoreTasks/fixcrlf.html b/docs/manual/CoreTasks/fixcrlf.html index dfa478ed6..a0b79942a 100644 --- a/docs/manual/CoreTasks/fixcrlf.html +++ b/docs/manual/CoreTasks/fixcrlf.html @@ -219,6 +219,12 @@ supports all attributes of <fileset> The encoding of the files No - defaults to default JVM encoding + + fixlast + Whether to add a missing EOL to the last line + of a processed file. (Since ant 1.6.1) + No - default is true +

Examples

  <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.
 You never know what editor a user will use to browse README's.


-

Copyright © 2000-2003 Apache Software Foundation. All rights +

Copyright © 2000-2004 Apache Software Foundation. All rights Reserved.

- diff --git a/src/etc/testcases/taskdefs/fixcrlf/build.xml b/src/etc/testcases/taskdefs/fixcrlf/build.xml index 2e5df163e..cdca01d55 100644 --- a/src/etc/testcases/taskdefs/fixcrlf/build.xml +++ b/src/etc/testcases/taskdefs/fixcrlf/build.xml @@ -142,6 +142,21 @@ /> + + + + + + + + diff --git a/src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos b/src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos new file mode 100644 index 000000000..319d4fc09 --- /dev/null +++ b/src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos @@ -0,0 +1,2 @@ +12345 +6789 diff --git a/src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac b/src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac new file mode 100644 index 000000000..6f7d6bf74 --- /dev/null +++ b/src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac @@ -0,0 +1 @@ +12345 6789 \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/fixcrlf/input/fixlastfalse.lf b/src/etc/testcases/taskdefs/fixcrlf/input/fixlastfalse.lf new file mode 100644 index 000000000..330ca6ff0 --- /dev/null +++ b/src/etc/testcases/taskdefs/fixcrlf/input/fixlastfalse.lf @@ -0,0 +1,2 @@ +12345 +6789 \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java index 2e83dc556..40fe4f6c5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java +++ b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java @@ -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()) diff --git a/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java b/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java index 7cc7ec1ad..e52ae6faf 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java @@ -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 *