@@ -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