Browse Source

Produce a summary, on request, of the actions taken by the replace

task

PR:	956


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269409 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
6ed54839c9
2 changed files with 32 additions and 2 deletions
  1. +8
    -0
      docs/manual/CoreTasks/replace.html
  2. +24
    -2
      src/main/org/apache/tools/ant/taskdefs/Replace.java

+ 8
- 0
docs/manual/CoreTasks/replace.html View File

@@ -42,6 +42,14 @@ must use a nested <code>&lt;replacetoken&gt;</code> element.</p>
(&quot;&quot;) is used.</td> (&quot;&quot;) is used.</td>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
</tr> </tr>
<tr>
<td valign="top">summary</td>
<td valign="top">Indicates whether a summary of the replace operation
should be produced, detailing how many token occurrences
and files were processed
</td>
<td valign="top" align="center">No, by default no summary is produced</td>
</tr>
<tr> <tr>
<td valign="top">propertyFile</td> <td valign="top">propertyFile</td>
<td valign="top">valid property file from which properties specified using nested <code>&lt;replacefilter&gt;</code> elements are drawn.</td> <td valign="top">valid property file from which properties specified using nested <code>&lt;replacefilter&gt;</code> elements are drawn.</td>


+ 24
- 2
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -78,7 +78,11 @@ public class Replace extends MatchingTask {
private Vector replacefilters = new Vector(); private Vector replacefilters = new Vector();


private File dir = null; private File dir = null;

private int fileCount;
private int replaceCount;
private boolean summary = false;
//Inner class //Inner class
public class NestedString { public class NestedString {


@@ -187,13 +191,15 @@ public class Replace extends MatchingTask {
} }


validateReplacefilters(); validateReplacefilters();
fileCount = 0;
replaceCount = 0;


if (src != null) { if (src != null) {
processFile(src); processFile(src);
} }


if (dir != null) { if (dir != null) {
DirectoryScanner ds = super.getDirectoryScanner(dir);
DirectoryScanner ds = super.getDirectoryScanner(dir);
String[] srcs = ds.getIncludedFiles(); String[] srcs = ds.getIncludedFiles();


for(int i=0; i<srcs.length; i++) { for(int i=0; i<srcs.length; i++) {
@@ -201,6 +207,10 @@ public class Replace extends MatchingTask {
processFile(file); processFile(file);
} }
} }
if (summary) {
log("Replaced " + replaceCount + " occurrences in " + fileCount + " files.", Project.MSG_INFO);
}
} }
/** /**
@@ -337,6 +347,7 @@ public class Replace extends MatchingTask {
// If there were changes, move the new one to the old one; // If there were changes, move the new one to the old one;
// otherwise, delete the new one // otherwise, delete the new one
if (changes) { if (changes) {
++fileCount;
src.delete(); src.delete();
temp.renameTo(src); temp.renameTo(src);
} else { } else {
@@ -370,6 +381,16 @@ public class Replace extends MatchingTask {
this.src = file; this.src = file;
} }


/**
* Request a summary
*
* @param summary true if you would like a summary logged of the replace operation
*/
public void setSummary(boolean summary) {
this.summary = summary;
}
/** /**
* Set the source files path when using matching tasks. * Set the source files path when using matching tasks.
*/ */
@@ -445,6 +466,7 @@ public class Replace extends MatchingTask {
// search again // search again
start = found + str1.length(); start = found + str1.length();
found = str.indexOf(str1,start); found = str.indexOf(str1,start);
++replaceCount;
} }


// write the remaining characters // write the remaining characters


Loading…
Cancel
Save