diff --git a/WHATSNEW b/WHATSNEW index 26c91161a..1dcb86f94 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -293,6 +293,10 @@ Other changes: * now supports a source attribute to enable javadoc to handle assertions present in JDK 1.4 source code. +* supports a new replacefilterfile attribute that + automatically turns all properties of a given file into + replacefilters. + Changes from Ant 1.4 to Ant 1.4.1 =========================================== diff --git a/docs/manual/CoreTasks/replace.html b/docs/manual/CoreTasks/replace.html index c49040c65..f89b08c8d 100644 --- a/docs/manual/CoreTasks/replace.html +++ b/docs/manual/CoreTasks/replace.html @@ -38,8 +38,9 @@ must use a nested <replacetoken> element.

token the token which must be replaced. - Yes, unless a nested replacetoken - element is used. + Yes, unless a nested + replacetoken element or the replacefilterfile + attribute is used. value @@ -60,6 +61,13 @@ must use a nested <replacetoken> element.

valid property file from which properties specified using nested <replacefilter> elements are drawn. Yes only if property attribute of <replacefilter> is used. + + replacefilterfile + valid property file. Each property will be + treated as a replacefilter where token is the name of + the property and value is the properties value. + No. + includes comma separated list of patterns of files that must be @@ -169,7 +177,7 @@ token]]></replacevalue>

Note: It is possible to use either the token/<replacetoken> and value/<replacevalue> attributes/elements, the nested replacefilter elements, or both in the same operation.


-

Copyright © 2001 Apache Software Foundation. All rights +

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/taskdefs/Rename.java b/src/main/org/apache/tools/ant/taskdefs/Rename.java index 5d9d0e1e6..fedec9e5f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rename.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rename.java @@ -65,7 +65,8 @@ import java.io.File; * * @author haas@softwired.ch * - * @deprecated The rename task is deprecated. Use move instead. + * @deprecated The rename task is deprecated since Ant 1.2. Use move instead. + * @since Ant 1.1 */ public class Rename extends Task { @@ -91,7 +92,7 @@ public class Rename extends Task { } /** - * Sets wheter an existing file should be replaced. + * Sets whether an existing file should be replaced. * @param replace on, if an existing file should be replaced. */ public void setReplace(String replace) { @@ -120,7 +121,7 @@ public class Rename extends Task { throw new BuildException("Unable to remove existing file " + dest); } - } + } if (!src.renameTo(dest)) { throw new BuildException("Unable to rename " + src + " to " + dest); diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java index 509be5625..e3cc21208 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Replace.java +++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java @@ -58,6 +58,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.StringUtils; import java.io.File; import java.io.FileInputStream; @@ -84,6 +85,8 @@ import java.util.Vector; * @author Stefano Mazzocchi stefano@apache.org * @author Erik Langenbach * + * @since Ant 1.1 + * * @ant.task category="filesystem" */ public class Replace extends MatchingTask { @@ -132,32 +135,39 @@ public class Replace extends MatchingTask { public void validate() throws BuildException { //Validate mandatory attributes if (token == null) { - String message = "token is a mandatory attribute " + "of replacefilter."; + String message = "token is a mandatory attribute " + + "of replacefilter."; throw new BuildException(message); } if ("".equals(token)) { - String message ="The token attribute must not be an empty string."; + String message = "The token attribute must not be an empty " + + "string."; throw new BuildException(message); } //value and property are mutually exclusive attributes if ((value != null) && (property != null)) { - String message = "Either value or property " + "can be specified, but a replacefilter " + "element cannot have both."; + String message = "Either value or property " + + "can be specified, but a replacefilter " + + "element cannot have both."; throw new BuildException(message); } if ((property != null)) { //the property attribute must have access to a property file if (propertyFile == null) { - String message = "The replacefilter's property attribute " + "can only be used with the replacetask's " + "propertyFile attribute."; + String message = "The replacefilter's property attribute " + + "can only be used with the replacetask's " + + "propertyFile attribute."; throw new BuildException(message); } //Make sure property exists in property file if (properties == null || - properties.getProperty(property) == null) { - String message = "property \"" + property + "\" was not found in " + propertyFile.getPath(); + properties.getProperty(property) == null) { + String message = "property \"" + property + + "\" was not found in " + propertyFile.getPath(); throw new BuildException(message); } } @@ -210,44 +220,55 @@ public class Replace extends MatchingTask { */ public void execute() throws BuildException { - if (replaceFilterFile != null) { - Properties properties = getProperties(replaceFilterFile); - Enumeration enum = properties.keys(); - while(enum.hasMoreElements()){ - String token = enum.nextElement().toString(); - Replacefilter replaceFilter = createReplacefilter(); - replaceFilter.setToken(token); - replaceFilter.setValue(properties.getProperty(token)); - } - } - - validateAttributes(); - - if (propertyFile != null) { - properties = getProperties(propertyFile); - } - - validateReplacefilters(); - fileCount = 0; - replaceCount = 0; + Vector savedFilters = (Vector) replacefilters.clone(); + Properties savedProperties = + properties == null ? null : (Properties) properties.clone(); - if (src != null) { - processFile(src); - } - - if (dir != null) { - DirectoryScanner ds = super.getDirectoryScanner(dir); - String[] srcs = ds.getIncludedFiles(); - - for(int i=0; i " + value.getText(), Project.MSG_VERBOSE); + log("Replacing in " + src.getPath() + ": " + token.getText() + + " --> " + value.getText(), Project.MSG_VERBOSE); newString = stringReplace(newString, tok, val); } @@ -397,7 +426,8 @@ public class Replace extends MatchingTask { } } catch (IOException ioe) { throw new BuildException("IOException in " + src + " - " + - ioe.getClass().getName() + ":" + ioe.getMessage(), ioe, location); + ioe.getClass().getName() + ":" + + ioe.getMessage(), ioe, location); } finally { if (reader != null) { try { @@ -423,8 +453,10 @@ public class Replace extends MatchingTask { Replacefilter filter = (Replacefilter) replacefilters.elementAt(i); //for each found token, replace with value - log("Replacing in " + filename + ": " + filter.getToken() + " --> " + filter.getReplaceValue(), Project.MSG_VERBOSE); - newString = stringReplace(newString, filter.getToken(), filter.getReplaceValue()); + log("Replacing in " + filename + ": " + filter.getToken() + + " --> " + filter.getReplaceValue(), Project.MSG_VERBOSE); + newString = stringReplace(newString, filter.getToken(), + filter.getReplaceValue()); } return newString; @@ -441,7 +473,8 @@ public class Replace extends MatchingTask { /** * Request a summary * - * @param summary true if you would like a summary logged of the replace operation + * @param summary true if you would like a summary logged of the + * replace operation */ public void setSummary(boolean summary) { this.summary = summary;