Reputation: 5685
I am trying to customize my build by using a configuration file with ant. What I intend to do is that use config file which has the following pattern: file path, pattern to match, pattern to replace
I want it such that I just add things to the configuration file and the ant build script reads up these values and makes the required changes.
I already know how to do a regex find and replace in files. What I am looking for is a way to read the values from such a configration file.
Upvotes: 1
Views: 7521
Reputation: 3321
There are various ways to read information from a file in Ant.
The generic one is the LoadFile Ant Task. I would however recommend the loadProperties Task. You could use this task to read properties such as: toReplace=string_to_replace with=replacement_string and then use the properties "toReplace" and "with" in your regexes.
Upvotes: 1
Reputation: 76
I would use the filterset feature in ant. You can create a parameterized version of the config file with strings you want replace using the pattern @replace_me@. Then define a properties file to define the replacement values. You can
<copy toDir="${dist.dir}/docs">
<fileset file="config.xml"/>
<filterset>
<filtersfile file="path/to.properties"/>
</filterset>
</copy>
Then the properties file is simply name=value lines.
You have lots of flexibility in specifying both the fileset and the filterset, see the Ant docs for these.
Upvotes: 0
Reputation: 6871
If I understand you correctly, you want to generate a set of configuration files for various environments.
The solution I'm currently using is a Groovy script called by an Ant task. Since Ant won't let you redefine a property that was already set, it's quite tricky to use it to generate several files with different values.
If you want to explore this, just take a look at Groovy and especially the Template Engine.
Upvotes: 0