Browse Source

stylecheck changes

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275823 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
494e5affe7
1 changed files with 30 additions and 4 deletions
  1. +30
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java

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

@@ -181,6 +181,7 @@ public class ReplaceRegExp extends Task {
/** /**
* file for which the regular expression should be replaced; * file for which the regular expression should be replaced;
* required unless a nested fileset is supplied. * required unless a nested fileset is supplied.
* @param file The file for which the reg exp should be replaced.
*/ */
public void setFile(File file) { public void setFile(File file) {
this.file = file; this.file = file;
@@ -190,6 +191,7 @@ public class ReplaceRegExp extends Task {
/** /**
* the regular expression pattern to match in the file(s); * the regular expression pattern to match in the file(s);
* required if no nested <regexp> is used * required if no nested <regexp> is used
* @param match the match attribute.
*/ */
public void setMatch(String match) { public void setMatch(String match) {
if (regex != null) { if (regex != null) {
@@ -205,6 +207,7 @@ public class ReplaceRegExp extends Task {
* The substitution pattern to place in the file(s) in place * The substitution pattern to place in the file(s) in place
* of the regular expression. * of the regular expression.
* Required if no nested <substitution> is used * Required if no nested <substitution> is used
* @param replace the replace attribute
*/ */


public void setReplace(String replace) { public void setReplace(String replace) {
@@ -230,6 +233,7 @@ public class ReplaceRegExp extends Task {
* "." to match any character, including a newline, which normally, * "." to match any character, including a newline, which normally,
* it would not match. * it would not match.
*</ul> *</ul>
* @param flags the flags attribute
*/ */
public void setFlags(String flags) { public void setFlags(String flags) {
this.flags = flags; this.flags = flags;
@@ -242,6 +246,7 @@ public class ReplaceRegExp extends Task {
* want to only replace the first occurrence of a regular expression on * want to only replace the first occurrence of a regular expression on
* each line, which is not easy to do when processing the file as a whole. * each line, which is not easy to do when processing the file as a whole.
* Defaults to <i>false</i>.</td> * Defaults to <i>false</i>.</td>
* @param byline the byline attribute as a string
* @deprecated - use setByLine(boolean) * @deprecated - use setByLine(boolean)
*/ */
public void setByLine(String byline) { public void setByLine(String byline) {
@@ -259,6 +264,7 @@ public class ReplaceRegExp extends Task {
* want to only replace the first occurrence of a regular expression on * want to only replace the first occurrence of a regular expression on
* each line, which is not easy to do when processing the file as a whole. * each line, which is not easy to do when processing the file as a whole.
* Defaults to <i>false</i>.</td> * Defaults to <i>false</i>.</td>
* @param byline the byline attribute
*/ */
public void setByLine(boolean byline) { public void setByLine(boolean byline) {
this.byline = byline; this.byline = byline;
@@ -268,6 +274,7 @@ public class ReplaceRegExp extends Task {
/** /**
* Specifies the encoding Ant expects the files to be in - * Specifies the encoding Ant expects the files to be in -
* defaults to the platforms default encoding. * defaults to the platforms default encoding.
* @param encoding the encoding attribute
* *
* @since Ant 1.6 * @since Ant 1.6
*/ */
@@ -277,6 +284,7 @@ public class ReplaceRegExp extends Task {


/** /**
* list files to apply the replacement to * list files to apply the replacement to
* @param set the fileset element
*/ */
public void addFileset(FileSet set) { public void addFileset(FileSet set) {
filesets.addElement(set); filesets.addElement(set);
@@ -287,6 +295,7 @@ public class ReplaceRegExp extends Task {
* A regular expression. * A regular expression.
* You can use this element to refer to a previously * You can use this element to refer to a previously
* defined regular expression datatype instance * defined regular expression datatype instance
* @return the regular expression object to be configured as an element
*/ */
public RegularExpression createRegexp() { public RegularExpression createRegexp() {
if (regex != null) { if (regex != null) {
@@ -301,6 +310,7 @@ public class ReplaceRegExp extends Task {
/** /**
* A substitution pattern. You can use this element to refer to a previously * A substitution pattern. You can use this element to refer to a previously
* defined substitution pattern datatype instance. * defined substitution pattern datatype instance.
* @return the substitution pattern object to be configured as an element
*/ */
public Substitution createSubstitution() { public Substitution createSubstitution() {
if (subs != null) { if (subs != null) {
@@ -313,6 +323,16 @@ public class ReplaceRegExp extends Task {
} }




/**
* Invoke a regular expression (r) on a string (input) using
* substitutions (s) for a matching regex.
*
* @param r a regular expression
* @param s a Substitution
* @param input the string to do the replacement on
* @param options The options for the regular expression
* @return the replacement result
*/
protected String doReplace(RegularExpression r, protected String doReplace(RegularExpression r,
Substitution s, Substitution s,
String input, String input,
@@ -321,7 +341,7 @@ public class ReplaceRegExp extends Task {
Regexp regexp = r.getRegexp(getProject()); Regexp regexp = r.getRegexp(getProject());


if (regexp.matches(input, options)) { if (regexp.matches(input, options)) {
log("Found match; substituting",Project.MSG_DEBUG);
log("Found match; substituting", Project.MSG_DEBUG);
res = regexp.substitute(input, s.getExpression(getProject()), res = regexp.substitute(input, s.getExpression(getProject()),
options); options);
} }
@@ -330,7 +350,13 @@ public class ReplaceRegExp extends Task {
} }




/** Perform the replace on the entire file */
/**
* Perform the replacement on a file
*
* @param f the file to perform the relacement on
* @param options the regular expressions options
* @exception IOException if an error occurs
*/
protected void doReplace(File f, int options) protected void doReplace(File f, int options)
throws IOException { throws IOException {
File temp = fileUtils.createTempFile("replace", ".txt", null); File temp = fileUtils.createTempFile("replace", ".txt", null);
@@ -455,7 +481,7 @@ public class ReplaceRegExp extends Task {
w = null; w = null;


if (changes) { if (changes) {
log("File has changed; saving the updated file",Project.MSG_VERBOSE);
log("File has changed; saving the updated file", Project.MSG_VERBOSE);
try { try {
fileUtils.rename(temp, f); fileUtils.rename(temp, f);
temp = null; temp = null;
@@ -464,7 +490,7 @@ public class ReplaceRegExp extends Task {
+ temp, getLocation()); + temp, getLocation());
} }
} else { } else {
log("No change made",Project.MSG_DEBUG);
log("No change made", Project.MSG_DEBUG);
} }
} finally { } finally {
try { try {


Loading…
Cancel
Save