• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Apache Ant - Doubt

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Got an issue with Apache ant. I wonder why nobody else in the whole world has faced this issue.

Using Ant, I would want to read a file (its not a property file) which contains the values as -

dirname1{space}dirname2{space}flag
dirname1{space}dirname2{space}flag
dirname1{space}dirname2{space}flag

I want to read it line by line and get individual dir names in the ant code. There is no option even in ant contrib to do a simple file read line by line either using <for> or <foreach>. Even if I try writing a custom task, it would still be a issue as the vars are all immutable and i am not sure how many lines are there in my file.

Any suggestions please ?

Cheers !
Dilish
 
Bartender
Posts: 21737
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, while the general idea is fairly common, your specific need is unusual.

Ant isn't a programming or scripting language system. Its omission of iterative constructs was deliberate, though there are several ways of giving it that ability, including via the use of JavaScript.

For what it's worth, since your data format is so distinct, I'd personally do a custom ant task, just because they're simple to do and it would make the project overall more elegant.

I'm not sure why the variability of the number of lines would matter to a custom task, since it would normally pick them up via a readline loop. Nor do I understand what "immutable" means here, since Ant properties are supposed to be immutable. And, without actually RTFMing, I'm pretty sure an Ant task can define properties. After all, the builtin ones do.
 
Dilish Kuruppath
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks tim for the reply!

I was just able to write a good custom task to achieve it. The reason for the skepticism was my odd requirement to return back the values in the same variables for every line read and then to process it - as the vars are immutable, the need to change its values for every new line read.. hence was not possible

The solution I found was quite simple and decent here. Did it in the same lines as the for loop is written - i.e. wrote a custom task to read each line and set it to macroinstance and made it to execute :-)

public void execute()
{
// some validations
// perform the iterations
doTheTasks();

}
private void doTheTasks() {
errorCount = 0;
taskCount = 0;

// Create a macro attribute
if (macroDef.getAttributes().isEmpty()) {
MacroDef.Attribute Asource= new MacroDef.Attribute();
Asource.setName(source);
macroDef.addConfiguredAttribute(Asource);

MacroDef.Attribute Adest= new MacroDef.Attribute();
Adest.setName(dest);
macroDef.addConfiguredAttribute(Adest);
}

// Try reading the file
if (filename != null) {
// read file line by line and process
}// end if
}// end doTheTasks
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!