Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK this is not the easiest thing to do with ant. First you need to know what you can change. This means all the names of your constants as well as the corresponding values. Are the constant names unique? If yes this sounds like a map structure to me. Then you need to regexreplace all your source files which contain one or more of these variables so that every constant is replaced with the actual value. This is not what ant is designed for but you can do it with a script def.</p> <p>I would do this with java like this : </p> <p>Store all constant/values into a map (if the constants are unique) else use a different structure.</p> <p>Sample code : </p> <pre><code>&lt;project name="test" default="build"&gt; &lt;property name="constants" value="constants.txt"/&gt; &lt;scriptdef name="replaceConstants" language="java"&gt; &lt;attribute name="constants" /&gt; &lt;attribute name="srcFile" /&gt; &lt;![CDATA[ import java.util.*; import java.util.regex.*; ArrayList constantNameList = new ArrayList(); ArrayList constantValueList = new ArrayList(); var constantFile = attributes.get("constants"); Pattern regex = Pattern.compile("(?&lt;=const)\\s+(\\b\\w+\\b).*?=\\s*(.*?)\\s*;"); Matcher regexMatcher = regex.matcher(constantFile); while (regexMatcher.find()) { constantNameList.add(regexMatcher.group(1)); constantValueList.add(regexMatcher.group(2)); } for(int i = 0; i &lt; constantNameList.size(); ++i) { //debugging System.out.print("key : "); System.out.print(constantNameList.get(i)); System.out.print(" value : "); System.out.println(constantValueList.get(i)); //do the actual replacement here } ]]&gt; &lt;/scriptdef&gt; &lt;target name="build"&gt; &lt;loadfile property="constants.file" srcFile="${constants}"/&gt; &lt;loadfile property="source.file" srcFile="sourceFile.txt"/&gt; &lt;echo message="${constants.file}"/&gt; &lt;replaceConstants constants="${constants.file}" srcFile="${source.file}"/&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p>You will need java 1.6 or later to run this as well as <a href="http://www.java2s.com/Code/Jar/ABC/bsh-2.0b5.jar.htm" rel="nofollow">http://www.java2s.com/Code/Jar/ABC/bsh-2.0b5.jar.htm</a></p> <p>This jar to run it.</p> <p>Output : </p> <pre><code>[replaceConstants] key : CONST_1 value : 0 [replaceConstants] key : CONST_LOLO value : -1 [replaceConstants] key : CONST_WHEE value : 2.55 [replaceConstants] key : OTHER_CONST value : "La string!" [replaceConstants] key : ITSAMEMARIO value : "O, HAI!" [replaceConstants] key : MAGE_WALL value : 15 </code></pre> <p>So what I did is stored all the constant names/value into two arrays. You need to iterate through the arrays and regex replace for each of your source files. The whole thing can be a macrodef which you can call multiple times.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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