Browse Source

Add encoding attribute to <replaceregexp>

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273939 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
6e99aad0bf
3 changed files with 33 additions and 3 deletions
  1. +4
    -0
      WHATSNEW
  2. +5
    -0
      docs/manual/OptionalTasks/replaceregexp.html
  3. +24
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java

+ 4
- 0
WHATSNEW View File

@@ -196,6 +196,10 @@ Other changes:
You can put in it all the strings described by p4 help usage. Refer to
the docs for more information.

* <replaceregexp> now has an optional encoding attribute to support
replacing in files that are in a different encoding than the
platform's default.

Changes from Ant 1.5.1Beta1 to 1.5.1
====================================



+ 5
- 0
docs/manual/OptionalTasks/replaceregexp.html View File

@@ -81,6 +81,11 @@ We <b>strongly</b> recommend that you use Jakarta Oro.
Defaults to <i>false</i>.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">encoding</td>
<td valign="top">The encoding of the file. <em>since Ant 1.6</em></td>
<td align="center">No - defaults to default JVM encoding</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;replaceregexp file=&quot;${src}/build.properties&quot;


+ 24
- 3
src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,10 +56,13 @@ package org.apache.tools.ant.taskdefs.optional;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
@@ -153,6 +156,10 @@ public class ReplaceRegExp extends Task {

private FileUtils fileUtils = FileUtils.newFileUtils();

/**
* Encoding to assume for the files
*/
private String encoding = null;

/** Default Constructor */
public ReplaceRegExp() {
@@ -240,6 +247,16 @@ public class ReplaceRegExp extends Task {
}


/**
* Specifies the encoding Ant expects the files to be in -
* defaults to the platforms default encoding.
*
* @since Ant 1.6
*/
public void setEncoding(String encoding) {
this.encoding = encoding;
}

/**
* list files to apply the replacement to
*/
@@ -300,11 +317,15 @@ public class ReplaceRegExp extends Task {
File parentDir = fileUtils.getParentFile(f);
File temp = fileUtils.createTempFile("replace", ".txt", parentDir);

FileReader r = null;
Reader r = null;
FileWriter w = null;

try {
r = new FileReader(f);
if (encoding == null) {
r = new FileReader(f);
} else {
r = new InputStreamReader(new FileInputStream(f), encoding);
}
w = new FileWriter(temp);

BufferedReader br = new BufferedReader(r);


Loading…
Cancel
Save