ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg 'Cosmo' Haun <GH...@cenquest.com>
Subject Replace enhancement
Date Wed, 06 Nov 2002 23:24:46 GMT

I've added some functionality to the Replace task via a new attribute 
that makes it easy to use meta-data stored in a property file to replace 
a token which appears in a collection of files where the values vary by 
filename.  Below are the additions to the Ant manual entry, followed by 
the diffs for the code and docs.

I've never submitted to an open-source project before (except by 
identifying bugs).  What is the process for deciding if this gets 
incorporated?

Thanks,
-cosmo

Parameters

Attribute: filevaluelist
Description:valid property file defining a mapping between filenames 
(property name) and values (property value). Values replace the token 
attribute according to filename. Filenames not listed inherent any value 
specified in the value attribute. 	
Required: No.

Examples

Using filevaluelist

<replace dir="." fileValueList="filename_date.txt"
          token="@DueDateHere@" value="TBD">
          <include name="*.htm?" />
</replace>


For all html files, replace token "@DueDateHere@" with the value 
specified for that file in filename_date.txt. Replace the token with 
"TBD" if the filename is not a property within filename_date.txt.

------------------------------------------------------------------------
diff output for Replace.java

101d100
<     private File fileValueList = null;
274c273
<
---
 >
327,331c326
<         if (token == null && fileValueList != null) {
<               String message = "A token must be specified when a 
fileValueList "
<                       + "is used.";
<             throw new BuildException(message, getLocation());
<         } else if (token == null && replacefilters.size() == 0) {
---
 >         if (token == null && replacefilters.size() == 0) {
439,450c434,439
<                                            StringUtils.LINE_SEP);
<                 if (fileValueList != null) {
<                       Properties props = getProperties(fileValueList);
<                       if (props.containsKey(src.getName())) {
<                               val = props.getProperty(src.getName());
<                       }
<                 }
<
<                               // for each found token, replace with 
value
<                               log("Replacing in " + 
src.getPath() + ": " + tok
<                                       + " --> " + val, Project. 
MSG_VERBOSE);
<                               newString = stringReplace(newString, 
tok, val);
---
 >                                            StringUtils.LINE_SEP);
 >
 >                 // for each found token, replace with value
 >                 log("Replacing in " + src.getPath() + ": " + 
token.getText()
 >                     + " --> " + value.getText(), Project.MSG_VERBOSE);
 >                 newString = stringReplace(newString, tok, val);
456c445
<
---
 >
558,566d546
<     }
<
<     /**
<      * Sets the name of a property file mapping filenames
<      * to values; optional.
<      * @param filename file to load
<      */
<     public void setFileValueList(File filename) {
<         fileValueList = filename;



diff output for Replace.html

42c42
<     <code>replacetoken</code> element or the replacefilterfile or the 
filevaluelist
---
 >     <code>replacetoken</code> element or the replacefilterfile
71,77c71
<     <tr>
<     <td valign="top">filevaluelist</td>
<     <td valign="top">valid property file defining a mapping between 
filenames (property name)
<     and values (property value).  Values replace the 
<code>token</code> attribute according to filename.  Filenames not listed
<     inherent any value specified in the <code>value</code> attribute.
<     <td valign="top" align="center">No.</td>
<   </tr><tr>
---
 >   <tr>
185,193d178
< <h4>Using filevaluelist</h4>
< <blockquote><pre>
< &lt;replace dir="." fileValueList="filename_date.txt"
<          token="@DueDateHere@" value="TBD"&gt;
<          &lt;include name="*.htm?" /&gt;
< &lt;/replace&gt;
< </pre></blockquote>
< <p>For all html files, replace token "@DueDateHere@" with the value 
specified for that file in <code>filename_date.txt</code>.
<   Replace the token with "TBD" if the filename is not a property 
within <code>filename_date.txt</code>.</p>

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message