I'm trying to figure out the easiest way to read in a CSV (comma delimited) file in Ant.
I know I can 1) use the load file task to read the whole file into a property 2) use Ant-Contrib's loop to split it into lines (based on the new line character) 3) use reg exps to parse it into the fields per line
This seems like a common operation though, so I'm wondering if anyone knows of a better way. Like a task that takes care of two or more of these steps.
(The build file I am working on is a generic one which is why I am reading in CSV information. I do recognize this complexity shouldn't be in a "normal" build script.)
I need to call an existing Ant macrodef that we wrote with the results. The current code calls this macrodef with a bunch of properties. I want to externalize these properties into a CSV.
We do have a number of Ant tasks and I am comfortable with creating more. And I do have custom Java Ant tasks that call built in targets. I don't know how (or if it is possible) to call a custom macrodef from Java though.
Between the two of these, it seems easier to read the file in Ant. I do know a way to do it. I just imagine there might be a better way.
I know I can 1) use the load file task to read the whole file into a property 2) use Ant-Contrib's loop to split it into lines (based on the new line character - need to use UNIX escape sequence
for this so Ant didn't treat "\n" as to characters when passing it to the tokenizer) 3) write a custom task (using split) to set properties with the parsed values for each line blanking out any unused ones
This doesn't feel awkward. Steps 1 & 2 are done with Ant library code. And step 3 is reusable within our project if I have to do this again.