Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading a csv file in ant

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason why you are not using Java code to read and parse the file?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic