Browse Source

<fixcrlf> now supports an outputencoding attribute. Bugzilla report 39697.

Submitted by Stephen Goetze


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@417584 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 19 years ago
parent
commit
8d20a46835
7 changed files with 53 additions and 8 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +2
    -0
      WHATSNEW
  3. +13
    -5
      docs/manual/CoreTasks/fixcrlf.html
  4. +9
    -0
      src/etc/testcases/taskdefs/fixcrlf/build.xml
  5. +2
    -0
      src/etc/testcases/taskdefs/fixcrlf/expected/input.lf.ascii
  6. +22
    -3
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  7. +4
    -0
      src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java

+ 1
- 0
CONTRIBUTORS View File

@@ -219,6 +219,7 @@ Stephane Bailliez
stephan
Stephan Michels
Stephen Chin
Stephen Goetze
Steve Cohen
Steve Loughran
Steve Morin


+ 2
- 0
WHATSNEW View File

@@ -442,6 +442,8 @@ Other changes:
* <scriptdef>-created scripts have support for nested text. All text
passed to a scripted task can be accessed via self.text.

* <fixcrlf> now supports an outputencoding attribute. Bugzilla report 39697.

Changes from Ant 1.6.4 to Ant 1.6.5
===================================



+ 13
- 5
docs/manual/CoreTasks/fixcrlf.html View File

@@ -121,6 +121,13 @@
<td align="center">No; defaults to default JVM encoding.</td>
<td bgcolor="#CCCCCC">&nbsp;</td>
</tr>
<tr>
<td valign="top">outputencoding</td>
<td valign="top">The encoding to use when writing the files.
<b>Since Ant 1.7</b></td>
<td align="center">No; defaults to the value of the encoding attribute.</td>
<td bgcolor="#CCCCCC">&nbsp;</td>
</tr>
<tr>
<td valign="top">preservelastmodified</td>
<td valign="top">Whether to preserve the last modified
@@ -143,10 +150,11 @@
<li>unix: convert all EOLs to a single LF</li>
<li>dos: convert all EOLs to the pair CRLF</li>
</ul>
Default is based on the platform on which you are running
this task. For Unix platforms, the default is &quot;lf&quot;.
For DOS based systems (including Windows), the default is
&quot;crlf&quot;. For Mac OS, the default is &quot;cr&quot;.
Default is based on the platform on which you are running this task.
For Unix platforms (including Mac OS X), the default is &quot;lf&quot;.
For DOS-based systems (including Windows), the default is
&quot;crlf&quot;.
For Mac environments other than OS X, the default is &quot;cr&quot;.
<p>
This is the preferred method for specifying EOL. The
&quot;<i><b>cr</b></i>&quot; attribute (see below) is
@@ -298,7 +306,7 @@
DOS systems, and are removed if run on Unix systems.
You never know what editor a user will use to browse READMEs.</p>
<hr>
<p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2000-2006 The Apache Software Foundation. All rights
Reserved.</p>

</body>


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

@@ -117,6 +117,15 @@
file2="expected/input.lf.utf16" />
</target>

<target name="testOutputEncoding" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="input.crlf.utf16"
javafiles="false" eol="lf" encoding="UnicodeBig"
outputencoding="ascii" />
<assertequal file1="result/input.crlf.utf16"
file2="expected/input.lf.ascii" />
</target>

<target name="testLongLines" depends="init">
<fixcrlf srcdir="input" destdir="result"
includes="longlines.crlf"


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

@@ -0,0 +1,2 @@
Line1
Line2

+ 22
- 3
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -52,6 +52,7 @@ import org.apache.tools.ant.util.FileUtils;
* <li>tab
* <li>eof
* <li>encoding
* <li>targetencoding
* </ul>
* Of these arguments, only <b>sourcedir</b> is required.
* <p>
@@ -98,6 +99,11 @@ public class FixCRLF extends MatchingTask implements ChainableReader {
*/
private String encoding = null;

/**
* Encoding to use for output files
*/
private String outputEncoding = null;

/**
* Chain this task as a reader.
* @param rdr Reader to chain.
@@ -237,6 +243,15 @@ public class FixCRLF extends MatchingTask implements ChainableReader {
this.encoding = encoding;
}

/**
* Specifies the encoding that the files are
* to be written in--same as input encoding by default.
* @param outputEncoding String outputEncoding name.
*/
public void setOutputEncoding(String outputEncoding) {
this.outputEncoding = outputEncoding;
}

/**
* Specify whether a missing EOL will be added
* to the final line of a file.
@@ -288,12 +303,15 @@ public class FixCRLF extends MatchingTask implements ChainableReader {
}
}
// log options used
String enc = encoding == null ? "default" : encoding;
log("options:"
+ " eol=" + filter.getEol().getValue()
+ " tab=" + filter.getTab().getValue()
+ " eof=" + filter.getEof().getValue()
+ " tablength=" + filter.getTablength()
+ " encoding=" + (encoding == null ? "default" : encoding),
+ " encoding=" + enc
+ " outputencoding="
+ (outputEncoding == null ? enc : outputEncoding),
Project.MSG_VERBOSE);

DirectoryScanner ds = super.getDirectoryScanner(srcDir);
@@ -318,8 +336,9 @@ public class FixCRLF extends MatchingTask implements ChainableReader {
File tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null);
tmpFile.deleteOnExit();
try {
FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, false,
false, encoding, getProject());
FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, false, false,
encoding, outputEncoding == null ? encoding : outputEncoding,
getProject());

File destFile = new File(destD, file);



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

@@ -91,6 +91,10 @@ public class FixCrLfTest extends BuildFileTest {
executeTarget("testEncoding");
}

public void testOutputEncoding() throws IOException {
executeTarget("testOutputEncoding");
}

public void testLongLines() throws IOException {
executeTarget("testLongLines");
}


Loading…
Cancel
Save