| Author |
reading a csv file in ant
|
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
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.)
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Roger Chung-Wee
Ranch Hand
Joined: Sep 29, 2002
Posts: 1683
|
|
|
Any reason why you are not using Java code to read and parse the file?
|
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
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.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
For what it's worth, I went with: 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.
|
 |
 |
|
|
subject: reading a csv file in ant
|
|
|