You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2002/05/10 17:14:58 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional ReplaceRegExp.java
bodewig 02/05/10 08:14:58
Modified: . Tag: ANT_15_BRANCH WHATSNEW
src/main/org/apache/tools/ant/taskdefs/optional Tag:
ANT_15_BRANCH ReplaceRegExp.java
Log:
Fix <fileset> support in <replaceregexp>.
Reported by: Olivier Gattaz <og...@adonix.fr>
Revision Changes Path
No revision
No revision
1.263.2.13 +2 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.263.2.12
retrieving revision 1.263.2.13
diff -u -r1.263.2.12 -r1.263.2.13
--- WHATSNEW 10 May 2002 13:38:57 -0000 1.263.2.12
+++ WHATSNEW 10 May 2002 15:14:58 -0000 1.263.2.13
@@ -38,6 +38,8 @@
* the refid attribute for <property>s nested into <ant> or <param>s
nested into <antcall> didn't work.
+* <replaceregexp> didn't work for nested <fileset>s.
+
Other changes:
--------------
No revision
No revision
1.9.2.1 +18 -14 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
Index: ReplaceRegExp.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -r1.9 -r1.9.2.1
--- ReplaceRegExp.java 14 Apr 2002 11:16:16 -0000 1.9
+++ ReplaceRegExp.java 10 May 2002 15:14:58 -0000 1.9.2.1
@@ -186,7 +186,8 @@
public void setReplace(String replace) {
if (subs != null) {
- throw new BuildException("Only one substitution expression is allowed");
+ throw new BuildException("Only one substitution expression is "
+ + "allowed");
}
subs = new Substitution();
@@ -226,7 +227,8 @@
public Substitution createSubstitution() {
if (subs != null) {
- throw new BuildException("Only one substitution expression is allowed");
+ throw new BuildException("Only one substitution expression is "
+ + "allowed");
}
subs = new Substitution();
@@ -252,7 +254,7 @@
/** Perform the replace on the entire file */
protected void doReplace(File f, int options)
throws IOException {
- File parentDir = new File(new File(f.getAbsolutePath()).getParent());
+ File parentDir = fileUtils.getParentFile(f);
File temp = fileUtils.createTempFile("replace", ".txt", parentDir);
FileReader r = null;
@@ -268,7 +270,8 @@
boolean changes = false;
- log("Replacing pattern '" + regex.getPattern(project) + "' with '" + subs.getExpression(project) +
+ log("Replacing pattern '" + regex.getPattern(project) +
+ "' with '" + subs.getExpression(project) +
"' in '" + f.getPath() + "'" +
(byline ? " by line" : "") +
(flags.length() > 0 ? " with flags: '" + flags + "'" : "") +
@@ -330,7 +333,6 @@
}
} catch (Exception e) {
}
- ;
try {
if (w != null) {
@@ -338,7 +340,6 @@
}
} catch (Exception e) {
}
- ;
}
}
@@ -353,7 +354,8 @@
}
if (file != null && filesets.size() > 0) {
- throw new BuildException("You cannot supply the 'file' attribute and filesets at the same time.");
+ throw new BuildException("You cannot supply the 'file' attribute "
+ + "and filesets at the same time.");
}
int options = 0;
@@ -378,12 +380,13 @@
try {
doReplace(file, options);
} catch (IOException e) {
- log("An error occurred processing file: '" + file.getAbsolutePath() + "': " + e.toString(),
+ log("An error occurred processing file: '"
+ + file.getAbsolutePath() + "': " + e.toString(),
Project.MSG_ERR);
}
} else if (file != null) {
- log("The following file is missing: '" + file.getAbsolutePath() + "'",
- Project.MSG_ERR);
+ log("The following file is missing: '"
+ + file.getAbsolutePath() + "'", Project.MSG_ERR);
}
int sz = filesets.size();
@@ -395,18 +398,19 @@
String files[] = ds.getIncludedFiles();
for (int j = 0; j < files.length; j++) {
- File f = new File(files[j]);
+ File f = new File(fs.getDir(getProject()), files[j]);
if (f.exists()) {
try {
doReplace(f, options);
} catch (Exception e) {
- log("An error occurred processing file: '" + f.getAbsolutePath() + "': " + e.toString(),
+ log("An error occurred processing file: '"
+ + f.getAbsolutePath() + "': " + e.toString(),
Project.MSG_ERR);
}
} else {
- log("The following file is missing: '" + file.getAbsolutePath() + "'",
- Project.MSG_ERR);
+ log("The following file is missing: '"
+ + f.getAbsolutePath() + "'", Project.MSG_ERR);
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>