Note that there are some explanatory texts on larger screens.

plurals
  1. POANT "replace" task not expanding properties in "replacetoken" tag
    primarykey
    data
    text
    <p>After build, I need to modify an HTML file that points the client to download the new app.</p> <p>I search for a token; replace it with a link and token:</p> <pre><code>&lt;replace file="index.html" &gt; &lt;!-- this searches for literal text ${MyTOKEN} --&gt; &lt;!-- does not "expand" ${MyTOKEN} before searching --&gt; &lt;replacetoken&gt;${MyTOKEN}&lt;/replacetoken&gt; &lt;replacevalue&gt;"some link" &lt;br&gt; ${MyTOKEN}&lt;/replacevalue&gt; &lt;/replace&gt; </code></pre> <hr> <p>This code CANNOT be moved into a template build script because the <code>replacetoken</code> and <code>replacevalue</code> tags take the text as literals - they do not <code>expandproperties</code> in my version of ANT.</p> <p>I would like to use properties to define the <code>"some link"</code> and <code>MyTOKEN</code> values.</p> <hr> <p>Workaround for using properties in <code>"some link"</code> is to use a <code>filterchain</code> and copy the file after the replacement:</p> <pre><code>&lt;copy file="index.html" tofile="index2.html" &gt; &lt;filterchain&gt; &lt;!-- this converts the ${xxx} properties into their values --&gt; &lt;expandproperties /&gt; &lt;/filterchain&gt; &lt;/copy&gt; </code></pre> <p>But that works AFTER the <code>replace</code> has been done - so it means I still need to hard-code the <code>MyTOKEN</code> values directly into the build script.</p> <ul> <li>I want to <strong>define my token outside</strong> of my build script, and <strong>reference it inside</strong> the build script. </li> <li>How do I do that?</li> </ul> <hr> <p><strong>Update:</strong> Should I create my own <code>replace</code> task using <code>copy</code>, <code>filterreader</code> and <code>filterchain</code>? I don't really understand that method properly, but it looks like the way.</p> <hr> <p><strong>Update expanding on accepted answer:</strong> I was originally using the <code>&lt;replacetoken&gt;</code> &amp; <code>&lt;replacevalue&gt;</code> method because I needed my value to span multiple lines.</p> <p>By using <code>token</code> &amp; <code>value</code>, I was unable to find a way to make line breaks.</p> <p>The solution to putting line breaks is to use <code>${line.separator}</code> as the line break. See docs on the <a href="http://ant.apache.org/manual/Tasks/echo.html" rel="nofollow">Echo Task</a>.</p> <p>As an extra, here is a page of some more useful (off topic) ANT properties: <a href="http://www.ghidinelli.com/2008/04/01/built-in-ant-properties" rel="nofollow">Built-in Ant Properties</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload