Here is the new patch for the file Replace.java, it now throws
BuildException if the valueFile isn't found or it can't be read during
validation phase. If the file is found, it simply loads its content into
the 'value' variable.

I've also attached the documentation patch for replace.html.

Both patches are against 1.3.

Bojan
--- jakarta-ant-1.3/src/main/org/apache/tools/ant/taskdefs/Replace.java Fri Mar 
 2 23:46:37 2001
+++ jakarta-ant-1.3-binarix/src/main/org/apache/tools/ant/taskdefs/Replace.java 
Tue Apr 24 08:32:27 2001
@@ -98,6 +98,7 @@
     {
         private String token;
         private String value;
+        private String valueFile;
         private String property;
 
         public void validate() throws BuildException {
@@ -112,9 +113,9 @@
                 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.";
+            //value, valueFile and property are mutually exclusive attributes
+            if ((value != null) && (valueFile != null) && (property != null)) {
+                String message = "Either value, valueFile or property " + "can 
be specified, but a replacefilter " + "element cannot have more then one.";
                 throw new BuildException(message);
             }
 
@@ -132,6 +133,25 @@
                     throw new BuildException(message);
                 }
             }
+
+            if ((valueFile != null)) {
+              try{
+                FileReader fval=new FileReader(valueFile);
+                StringBuffer val=new StringBuffer();
+                int ch;
+
+                while ((ch=fval.read()) != -1)
+                  val.append((char)ch);
+
+                value=val.toString();
+              } catch (FileNotFoundException fnf) {
+                String message = "Value file " + valueFile + " not found.";
+                throw new BuildException(message);
+              } catch (IOException ioe) {
+                String message = "Couldn't read value file " + valueFile + 
"."; 
+                throw new BuildException(message);
+              }
+            }
         }
 
         public String getReplaceValue()
@@ -165,6 +185,14 @@
 
         public String getValue() {
             return value;
+        }
+
+        public void setValueFile(String valueFile) {
+            this.valueFile = valueFile;
+        }
+
+        public String getValueFile() {
+            return valueFile;
         }
 
         public void setProperty(String property) {
--- jakarta-ant-1.3/docs/manual/CoreTasks/replace.html  Fri Mar  2 23:46:34 2001
+++ jakarta-ant-1.3-binarix/docs/manual/CoreTasks/replace.html  Tue Apr 24 
09:07:56 2001
@@ -127,14 +127,18 @@
   <tr>
     <td valign="top">value</td>
     <td valign="top">The replacement string.</td>
-    <td align="center" rowspan="2">Either may be specified, but not both. Both 
can be omitted, if desired.</td>
+    <td align="center" rowspan="3">Either of the three (value, valueFile, 
property) can be specified but not in combination. All three can be omitted, if 
desired.</td>
+  </tr>
+  <tr>
+    <td valign="top">valueFile</td>
+    <td valign="top">The file that contains the replacement for the token.</td>
   </tr>
   <tr>
     <td valign="top">property</td>
     <td valign="top">Name of the property whose value is to serve as the 
replacement value.</td>
   </tr>
 </table>
-<p>If neither <i>value</i> nor <i>property</i> is used, the value provided 
using the <code>&lt;replace&gt;</code> attribute <i>value</i> and/or the 
<code>&lt;replacevalue&gt;</code> element is used. If no value was specified 
using either of these options, the token is replaced with an empty string.
+<p>If neither <i>value</i>, <i>valueFile</i> nor <i>property</i> is used, the 
value provided using the <code>&lt;replace&gt;</code> attribute <i>value</i> 
and/or the <code>&lt;replacevalue&gt;</code> element is used. If no value was 
specified using either of these options, the token is replaced with an empty 
string.
 </p>
 <h3>Examples</h3>
 <blockquote><pre>
@@ -149,10 +153,13 @@
     value=&quot;value2&quot;/&gt;
   &lt;replacefilter 
     token=&quot;@token3@&quot; 
+    valueFile=&quot;replacefiles/replacefile.txt&quot;/&gt;
+  &lt;replacefilter 
+    token=&quot;@token4@&quot; 
     property=&quot;property.key&quot;/&gt;
 &lt;/replace&gt;
 </pre></blockquote>
-<p>In file <code>configure.sh</code>, replace all instances of 
&quot;@token1@&quot; with &quot;defaultvalue&quot;, all instances of 
&quot;@token2@&quot; with &quot;value2&quot;, and all instances of 
&quot;@token3@&quot; with the value of the property &quot;property.key&quot;, 
as it appears in property file <code>src/name.properties</code>.</p>
+<p>In file <code>configure.sh</code>, replace all instances of 
&quot;@token1@&quot; with &quot;defaultvalue&quot;, all instances of 
&quot;@token2@&quot; with &quot;value2&quot;, all instances of 
&quot;@token3@&quot; with the content of the file 
<code>replacefiles/replacefile.txt</code> and all instances of 
&quot;@token4@&quot; with the value of the property &quot;property.key&quot;, 
as it appears in property file <code>src/name.properties</code>.</p>
 <p><b>Note:</b> It is possible to use either the 
<i>token</i>/<code>&lt;replacetoken&gt;</code> and 
<i>value</i>/<code>&lt;replacevalue&gt;</code> attributes/elements, the nested 
replacefilter elements, or both in the same operation.
 </p>
 <hr>

Reply via email to