Browse Source

<fixcrlf> now deals with CR only line-ends and arbitrary tab lengths.

It should work independant of the size of the file as well.

Additionally it can treat tabs inside character constants in source
files differently.

Documentation will follow - also it will now update the timestamp of
files, even if the file doesn't change. This will be fixed before the
final release but shouldn't stop us from starting the beta cycle.

PR: 1053
Submitted by:   Peter B. West <pbwest@powerup.com.au>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269449 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
a794b2b204
23 changed files with 1217 additions and 189 deletions
  1. +5
    -0
      WHATSNEW
  2. +5
    -4
      build.xml
  3. +100
    -0
      src/etc/testcases/taskdefs/fixcrlf/build.xml
  4. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk1.java
  5. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk2.java
  6. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk3.java
  7. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk4.java
  8. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk5.java
  9. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk6.java
  10. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk7.java
  11. +13
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk8.java
  12. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/Junk9.java
  13. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk1.java
  14. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk2.java
  15. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk3.java
  16. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk4.java
  17. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk5.java
  18. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk6.java
  19. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk7.java
  20. +12
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk8.java
  21. +13
    -0
      src/etc/testcases/taskdefs/fixcrlf/input/Junk9.java
  22. +728
    -185
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  23. +161
    -0
      src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java

+ 5
- 0
WHATSNEW View File

@@ -138,6 +138,9 @@ Other changes:
* Two new supported compilers for javac: kjc for kopi and gcj for the * Two new supported compilers for javac: kjc for kopi and gcj for the
gcc frontend. gcc frontend.


* <fixrlf> can now with CR only line-ends and can use an arbitraty
between 2 and 80.

Fixed bugs: Fixed bugs:
----------- -----------


@@ -211,6 +214,8 @@ Fixed bugs:
* directory based tasks and fileset could miss some included files in * directory based tasks and fileset could miss some included files in
directories that have been excluded directories that have been excluded


* <fixcrl> failed for large files.

Changes from Ant 1.2 to Ant 1.3 Changes from Ant 1.2 to Ant 1.3
=========================================== ===========================================




+ 5
- 4
build.xml View File

@@ -228,6 +228,7 @@
<exclude name="${optional.package}/jdepend/*" unless="jdepend.present" /> <exclude name="${optional.package}/jdepend/*" unless="jdepend.present" />
<exclude name="${optional.package}/sitraka/**" unless="jakarta.oro.present"/> <exclude name="${optional.package}/sitraka/**" unless="jakarta.oro.present"/>
<exclude name="${optional.package}/metamata/MAudit*" unless="jakarta.oro.present"/> <exclude name="${optional.package}/metamata/MAudit*" unless="jakarta.oro.present"/>
<exclude name="${optional.package}/metamata/**" unless="jdk1.2+" />
</javac> </javac>
<copy todir="${build.classes}"> <copy todir="${build.classes}">
@@ -304,8 +305,8 @@
<fileset dir="${script.dir}/" /> <fileset dir="${script.dir}/" />
</copy> </copy>


<fixcrlf srcdir="${dist.bin}" cr="add" includes="*.bat" />
<fixcrlf srcdir="${dist.bin}" cr="remove">
<fixcrlf srcdir="${dist.bin}" eol="crlf" includes="*.bat" />
<fixcrlf srcdir="${dist.bin}" eol="lf">
<include name="ant" /> <include name="ant" />
<include name="antRun" /> <include name="antRun" />
</fixcrlf> </fixcrlf>
@@ -433,8 +434,8 @@
</fileset> </fileset>
</copy> </copy>


<fixcrlf srcdir="${src.dist.dir}" cr="add" includes="*.bat" />
<fixcrlf srcdir="${src.dist.dir}" cr="remove">
<fixcrlf srcdir="${src.dist.dir}" eol="crlf" includes="*.bat" />
<fixcrlf srcdir="${src.dist.dir}" eol="lf">
<include name="**/*.sh" /> <include name="**/*.sh" />
<include name="**/ant" /> <include name="**/ant" />
<include name="**/antRun" /> <include name="**/antRun" />


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

@@ -0,0 +1,100 @@
<?xml version="1.0"?>
<project default="cleanup" basedir=".">
<target name="init">
<mkdir dir="result" />
</target>

<target name="cleanup">
<delete dir="result" />
</target>

<target name="test1" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk1.java"
javafiles="true"
tab="add"
eol="crlf"
eof="asis"
/>
</target>

<target name="test2" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk2.java"
javafiles="true"
tab="add"
cr="add"
eol="crlf"
eof="asis"
/>
</target>

<target name="test3" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk3.java"
javafiles="true"
tab="remove"
eol="lf"
eof="asis"
/>
</target>

<target name="test4" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk4.java"
javafiles="true"
tab="remove"
eol="lf"
eof="asis"
/>
</target>

<target name="test5" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk5.java"
tab="remove"
eol="lf"
eof="asis"
/>
</target>

<target name="test6" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk6.java"
tab="add"
cr="remove"
eol="crlf"
eof="asis"
/>
</target>

<target name="test7" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk7.java"
tab="add"
cr="add"
eof="asis"
/>
</target>

<target name="test8" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk8.java"
javafiles="true"
tab="add"
cr="add"
eof="add"
/>
</target>

<target name="test9" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="Junk9.java"
javafiles="true"
tab="remove"
cr="remove"
eof="remove"
/>
</target>

</project>

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk1.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk2.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk3.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk4.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk5.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk6.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk7.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 13
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk8.java View File

@@ -0,0 +1,13 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}


+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/expected/Junk9.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk1.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk2.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk3.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk4.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk5.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk6.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk7.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 12
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk8.java View File

@@ -0,0 +1,12 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}

+ 13
- 0
src/etc/testcases/taskdefs/fixcrlf/input/Junk9.java View File

@@ -0,0 +1,13 @@
public class Junk1 {
public boolean mybool;
public static void main (String[] args) {
System.out.println("I have a tab");
// Here is a comment with an embedded tab
if (mybool) { /* Here is a multi-line
(with embedded' 'tab)
Comment */char mychar = ' '; //<-tab-> <-
} // end of if (mybool)
} // end of main ()
}


+ 728
- 185
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
File diff suppressed because it is too large
View File


+ 161
- 0
src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java View File

@@ -0,0 +1,161 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/

package org.apache.tools.ant.taskdefs;

import java.io.*;

import junit.framework.AssertionFailedError;

/**
* @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class FixCrLfTest extends TaskdefsTest {

public FixCrLfTest(String name) {
super(name);
}

public void setUp() {
configureProject("src/etc/testcases/taskdefs/fixcrlf/build.xml");
}
public void tearDown() {
executeTarget("cleanup");
}
public void test1() throws IOException {
executeTarget("test1");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk1.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk1.java"));
}
public void test2() throws IOException {
executeTarget("test2");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk2.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk2.java"));
}
public void test3() throws IOException {
executeTarget("test3");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk3.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk3.java"));
}
public void test4() throws IOException {
executeTarget("test4");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk4.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk4.java"));
}
public void test5() throws IOException {
executeTarget("test5");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk5.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk5.java"));
}
public void test6() throws IOException {
executeTarget("test6");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk6.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk6.java"));
}
public void test7() throws IOException {
executeTarget("test7");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk7.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk7.java"));
}
public void test8() throws IOException {
executeTarget("test8");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk8.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk8.java"));
}
public void test9() throws IOException {
executeTarget("test9");
assertEqualContent(new File("src/etc/testcases/taskdefs/fixcrlf/expected/Junk9.java"),
new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk9.java"));
}
public void assertEqualContent(File expect, File result)
throws AssertionFailedError, IOException {
if (!result.exists()) {
fail("Expected file "+result+" doesn\'t exist");
}

InputStream inExpect = null;
InputStream inResult = null;
try {
inExpect = new BufferedInputStream(new FileInputStream(expect));
inResult = new BufferedInputStream(new FileInputStream(result));

int expectedByte = inExpect.read();
while (expectedByte != -1) {
assertEquals(expectedByte, inResult.read());
expectedByte = inExpect.read();
}
assertEquals("End of file", -1, inResult.read());
} finally {
if (inResult != null) {
inResult.close();
}
if (inExpect != null) {
inExpect.close();
}
}
}

}

Loading…
Cancel
Save