You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Paul Taylor <pa...@fastmail.fm> on 2008/07/02 01:20:27 UTC
How do I call antcall once per line of file using line value as parameter?
Hi, sure simple enough, but cant work out to iterate through lines of
file, i,e how do I implement the for loop in pseudo code below
<target name="Maintask">
<file name="inputfile"/>
for line in file
<antcall target="subtask"><param name="param1
value="nextlineoffile"/></antcall>
rof
</target>
<target name=Subtask">
<dosomething param="${param1}"/>
</target>
thanks Paul
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: How do I call antcall once per line of file using line value as
parameter?
Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
-----Original Message-----
From: samcollins [mailto:samirn@gmail.com]
Sent: Wednesday, January 14, 2009 8:37 PM
To: user@ant.apache.org
Subject: Re: How do I call antcall once per line of file using line value as parameter?
/*
Hey,
I have a question on this. If I want to grab the value of the param "x" of
the antcontrib for look inside a javascript tag. Is it possible?
*/
The value of the param attribute can be accessed via @{...}, example
from the antcontrib manual =
<for list="a,b,c,d,e" param="letter">
<sequential>
<echo>Letter @{letter}</echo>
</sequential>
</for>
so for your example it should work like that =
<ac:for param="x">
<tokens>
<file file="${input.file}" />
</tokens>
<sequential>
<echo>Foo => @{x}</echo>
...
</sequential>
</ac:for>
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value as
parameter?
Posted by samcollins <sa...@gmail.com>.
Hey,
I have a question on this. If I want to grab the value of the param "x" of
the antcontrib for look inside a javascript tag. Is it possible?
Thanks,
Sam
Gilbert Rebhan wrote:
>
>
> Hi, Matt
>
>
> Matt Benson schrieb:
>> Trying to catch up on this thread. Are you saying you
>> want to do something for each line of a file? No
>> problem. The ResourceCollection API was designed to
>> return an Iterator partly with the aim of maintaining
>> compatibility with antcontrib's for and foreach tasks.
>> Simply use the <tokens> ResourceCollection:
>>
>> <ac:for param="x">
>> <tokens>
>> <file file="${input.file}" />
>> </tokens>
>> <sequential>
>> ....
>> </sequential>
>> </ac:for>
>
> That's nice to know.
> After all i'm not up to date, as we still use ant 1.6.5
> in production.
>
> I push for an update to ant 1.7.x all the time, hope i'll
> get my update soon :-)
>
> I see 1.7.1 is nearly out ...
>
> Regards, Gilbert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-do-I-call-antcall-once-per-line-of-file-using-line-value-as-parameter--tp18227353p21463511.html
Sent from the Ant - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value
as parameter?
Posted by Gilbert Rebhan <an...@schillbaer.de>.
Hi, Matt
Matt Benson schrieb:
> Trying to catch up on this thread. Are you saying you
> want to do something for each line of a file? No
> problem. The ResourceCollection API was designed to
> return an Iterator partly with the aim of maintaining
> compatibility with antcontrib's for and foreach tasks.
> Simply use the <tokens> ResourceCollection:
>
> <ac:for param="x">
> <tokens>
> <file file="${input.file}" />
> </tokens>
> <sequential>
> ....
> </sequential>
> </ac:for>
That's nice to know.
After all i'm not up to date, as we still use ant 1.6.5
in production.
I push for an update to ant 1.7.x all the time, hope i'll
get my update soon :-)
I see 1.7.1 is nearly out ...
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value as parameter?
Posted by Matt Benson <gu...@yahoo.com>.
Trying to catch up on this thread. Are you saying you
want to do something for each line of a file? No
problem. The ResourceCollection API was designed to
return an Iterator partly with the aim of maintaining
compatibility with antcontrib's for and foreach tasks.
Simply use the <tokens> ResourceCollection:
<ac:for param="x">
<tokens>
<file file="${input.file}" />
</tokens>
<sequential>
....
</sequential>
</ac:for>
HTH,
Matt
--- Gilbert Rebhan <an...@schillbaer.de> wrote:
> Paul Taylor schrieb:
> > I dont understand Ruby so this wouldnt be an
> option for me. It just
> > seems that this is such a common problem that it
> shoulg go into ant proper
>
> As you already noticed, (core) ant has it limits.
> OK, to be fair, it
> was never meant as a scripting language, but is
> often used
> like that.
>
> If i get to the limits i use <script> with (j)ruby
> or write a new task.
> There are other languages that run in the VM via
> BSF, f.e. if you want a
> syntax similar to java, use beanshell or javascript
> (rhino).
>
>
> >> also possible without antcontrib =
> >>
> >> <script language="ruby">
> >> <![CDATA[
> >> echoTask = $project.createTask 'echo'
> >> IO.readlines("Y:/foobar.txt").each do |line|
> >> echoTask.addText(line)
> >> echoTask.execute
> >> end
> >> ]]>
> >> </script>
> >>
> >> you have full access to the ant api
>
> Regards, Gilbert
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value
as parameter?
Posted by Gilbert Rebhan <an...@schillbaer.de>.
Paul Taylor schrieb:
> I dont understand Ruby so this wouldnt be an option for me. It just
> seems that this is such a common problem that it shoulg go into ant proper
As you already noticed, (core) ant has it limits. OK, to be fair, it
was never meant as a scripting language, but is often used
like that.
If i get to the limits i use <script> with (j)ruby or write a new task.
There are other languages that run in the VM via BSF, f.e. if you want a
syntax similar to java, use beanshell or javascript (rhino).
>> also possible without antcontrib =
>>
>> <script language="ruby">
>> <![CDATA[
>> echoTask = $project.createTask 'echo'
>> IO.readlines("Y:/foobar.txt").each do |line|
>> echoTask.addText(line)
>> echoTask.execute
>> end
>> ]]>
>> </script>
>>
>> you have full access to the ant api
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value
as parameter?
Posted by Paul Taylor <pa...@fastmail.fm>.
I dont understand Ruby so this wouldnt be an option for me. It just
seems that this is such a common problem that it shoulg go into ant proper
Rebhan, Gilbert wrote:
>
>
> -----Original Message-----
> From: Paul Taylor [mailto:paul_t100@fastmail.fm]
> Sent: Wednesday, July 02, 2008 10:30 AM
> To: Ant Users List
> Subject: Re: How do I call antcall once per line of file using line
> value as parameter?
>
> /*
> I did it using Ant-contrib as follows
>
> <target name="Maintask">
> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
> <loadfile property="params" srcFile="inputfile"/>
> <foreach list="${params}" delimiter="
" target="subtask"
> param="param1"/>
> </target>
> */
>
> also possible without antcontrib =
>
> <script language="ruby">
> <![CDATA[
> echoTask = $project.createTask 'echo'
> IO.readlines("Y:/foobar.txt").each do |line|
> echoTask.addText(line)
> echoTask.execute
> end
> ]]>
> </script>
>
> you have full access to the ant api
>
>
> Regards, Gilbert
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: How do I call antcall once per line of file using line value as parameter?
Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
-----Original Message-----
From: Paul Taylor [mailto:paul_t100@fastmail.fm]
Sent: Wednesday, July 02, 2008 10:30 AM
To: Ant Users List
Subject: Re: How do I call antcall once per line of file using line
value as parameter?
/*
I did it using Ant-contrib as follows
<target name="Maintask">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<loadfile property="params" srcFile="inputfile"/>
<foreach list="${params}" delimiter="
" target="subtask"
param="param1"/>
</target>
*/
also possible without antcontrib =
<script language="ruby">
<![CDATA[
echoTask = $project.createTask 'echo'
IO.readlines("Y:/foobar.txt").each do |line|
echoTask.addText(line)
echoTask.execute
end
]]>
</script>
you have full access to the ant api
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value
as parameter?
Posted by Paul Taylor <pa...@fastmail.fm>.
I did it using Ant-contrib as follows
<target name="Maintask">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<loadfile property="params" srcFile="inputfile"/>
<foreach list="${params}" delimiter="
" target="subtask"
param="param1"/>
</target>
thanks Paul
(BTW why dont they merge things like foreach into the main ant project,
its very useful)
Paul Taylor wrote:
> Hi, sure simple enough, but cant work out to iterate through lines of
> file, i,e how do I implement the for loop in pseudo code below
>
> <target name="Maintask">
> <file name="inputfile"/>
> for line in file
> <antcall target="subtask"><param name="param1
> value="nextlineoffile"/></antcall> rof
> </target>
>
> <target name=Subtask">
> <dosomething param="${param1}"/>
> </target>
>
> thanks Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value as
parameter?
Posted by Steven Guitar <st...@mac.com>.
i have used regular expressions to either take multilines and format
them to one line with comma delimited entries for the ant contrib
foreach
On Jul 2, 2008, at 12:54 AM, Roman Kennke wrote:
> Hi,
>
> The foreach task from ant-contrib could help:
>
> http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html
>
> Dunno how to get the lines of a file in a list though. I'm sure it is
> possible.
>
> /Roman
>
> Am Mittwoch, den 02.07.2008, 00:20 +0100 schrieb Paul Taylor:
>> Hi, sure simple enough, but cant work out to iterate through lines of
>> file, i,e how do I implement the for loop in pseudo code below
>>
>> <target name="Maintask">
>> <file name="inputfile"/>
>> for line in file
>> <antcall target="subtask"><param name="param1
>> value="nextlineoffile"/></antcall>
>> rof
>> </target>
>>
>> <target name=Subtask">
>> <dosomething param="${param1}"/>
>> </target>
>>
>> thanks Paul
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
> --
> http://kennke.org/blog/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: How do I call antcall once per line of file using line value
as parameter?
Posted by Roman Kennke <ro...@kennke.org>.
Hi,
The foreach task from ant-contrib could help:
http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html
Dunno how to get the lines of a file in a list though. I'm sure it is
possible.
/Roman
Am Mittwoch, den 02.07.2008, 00:20 +0100 schrieb Paul Taylor:
> Hi, sure simple enough, but cant work out to iterate through lines of
> file, i,e how do I implement the for loop in pseudo code below
>
> <target name="Maintask">
> <file name="inputfile"/>
> for line in file
> <antcall target="subtask"><param name="param1
> value="nextlineoffile"/></antcall>
> rof
> </target>
>
> <target name=Subtask">
> <dosomething param="${param1}"/>
> </target>
>
> thanks Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
--
http://kennke.org/blog/