peterreilly    2004/01/09 09:36:16

  Modified:    src/etc/testcases/taskdefs/fixcrlf build.xml
               src/testcases/org/apache/tools/ant/taskdefs FixCrLfTest.java
               src/main/org/apache/tools/ant/taskdefs FixCRLF.java
               docs/manual/CoreTasks fixcrlf.html
  Added:       src/etc/testcases/taskdefs/fixcrlf/input fixlastfalse.lf
               src/etc/testcases/taskdefs/fixcrlf/expected fixlast.dos
                        fixlastfalse.mac
  Log:
  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
  
  Revision  Changes    Path
  1.10      +15 -0     ant/src/etc/testcases/taskdefs/fixcrlf/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/fixcrlf/build.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- build.xml 24 Jun 2003 08:32:43 -0000      1.9
  +++ build.xml 9 Jan 2004 17:36:15 -0000       1.10
  @@ -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"/>
  
  
  
  1.15      +14 -2     
ant/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java
  
  Index: FixCrLfTest.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- FixCrLfTest.java  24 Jun 2003 08:32:43 -0000      1.14
  +++ FixCrLfTest.java  9 Jan 2004 17:36:15 -0000       1.15
  @@ -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 void tearDown() { 
  -        executeTarget("cleanup");
  +        //executeTarget("cleanup");
       }
       
       public void test1() throws IOException { 
  @@ -200,6 +200,18 @@
           executeTarget("testCrCrLfSequence-mac");
           assertEqualContent(new 
File("src/etc/testcases/taskdefs/fixcrlf/expected/crcrlf.mac"),
                              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"));
       }
   
       /**
  
  
  
  1.56      +18 -7     ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  
  Index: FixCRLF.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- FixCRLF.java      14 Oct 2003 13:19:52 -0000      1.55
  +++ FixCRLF.java      9 Jan 2004 17:36:15 -0000       1.56
  @@ -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 @@
       private int ctrlz;
       private int tabs;
       private boolean javafiles = false;
  +    private boolean fixlast = true;
   
       private File srcDir;
       private File destDir = null;
  @@ -339,6 +340,14 @@
       }
   
       /**
  +     * 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.
        */
       public void execute() throws BuildException {
  @@ -515,11 +524,13 @@
   
                   } // 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())
   
  
  
  
  1.1                  
ant/src/etc/testcases/taskdefs/fixcrlf/input/fixlastfalse.lf
  
  Index: fixlastfalse.lf
  ===================================================================
  12345
  6789
  
  
  1.1                  
ant/src/etc/testcases/taskdefs/fixcrlf/expected/fixlast.dos
  
  Index: fixlast.dos
  ===================================================================
  12345
  6789
  
  
  
  1.1                  
ant/src/etc/testcases/taskdefs/fixcrlf/expected/fixlastfalse.mac
  
  Index: fixlastfalse.mac
  ===================================================================
  12345
6789
  
  
  1.15      +7 -2      ant/docs/manual/CoreTasks/fixcrlf.html
  
  Index: fixcrlf.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/fixcrlf.html,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- fixcrlf.html      10 Feb 2003 16:01:22 -0000      1.14
  +++ fixcrlf.html      9 Jan 2004 17:36:16 -0000       1.15
  @@ -219,6 +219,12 @@
       <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 @@
   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>
  -
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to