Discussion:
Passing command Line args for a list
Petronius
2016-03-04 17:13:07 UTC
Permalink
Hello

We are tyring to automate an ant task, but finding it impossible to pass a
command line argument to a property inside a list.

We need to pass Name and Description for each agent specified from the
command line. for ex:
ant -f build.xml addNodes -Dagents="d01, d02, d03" -D{node???}='node1' -
D{node_description???}='node1 description'

each agent d01/d02/d03 will need have name and description.

<target name="addNodes" depends="clean">
<input message="Agents Name Seperated By , :" addproperty="agents" />
<for list="${agents}" delimiter="," param="agent">
<sequential>
<input message="Node Name:" addproperty="node" />
<input message="Node Description:" addproperty="node_description" />
<exec>
<!-- external task -->
</exec>
<var name="node" unset="true"/>
</sequential>
</for>
</target>

Any suggestions is greatly appreciated.

thanks



---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Scot P. Floess
2016-03-04 21:19:50 UTC
Permalink
So I see in your example below some input tasks. I'm guessing you'd
rather not using input?
Post by Petronius
Hello
We are tyring to automate an ant task, but finding it impossible to pass a
command line argument to a property inside a list.
We need to pass Name and Description for each agent specified from the
ant -f build.xml addNodes -Dagents="d01, d02, d03" -D{node???}='node1' -
D{node_description???}='node1 description'
each agent d01/d02/d03 will need have name and description.
<target name="addNodes" depends="clean">
<input message="Agents Name Seperated By , :" addproperty="agents" />
<for list="${agents}" delimiter="," param="agent">
<sequential>
<input message="Node Name:" addproperty="node" />
<input message="Node Description:" addproperty="node_description" />
<exec>
<!-- external task -->
</exec>
<var name="node" unset="true"/>
</sequential>
</for>
</target>
Any suggestions is greatly appreciated.
thanks
---------------------------------------------------------------------
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Petronius
2016-03-04 22:30:20 UTC
Permalink
We have to have these inputs for manual execution

Thanks



---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Scot P. Floess
2016-03-05 12:44:33 UTC
Permalink
I'm confused as you are asking about using command line params (via the
-D) but then reusing those for the input task.

As an example from your post:

ant -f build.xml addNodes -Dagents="d01, d02, d03" -D{node???}='node1'
-D{node_description???}='node1 description'

Note you list -Dagents

In your target I see this:

<input message="Agents Name Seperated By , :" addproperty="agents" />

So the property "agents" is both passed in command line and then reused
inside with an input task.

Same with the properties node and node_description.

The for loop should have no trouble using properties denoted on the
command line with the -D

The -D will become a property in your ant script.
Post by Petronius
We have to have these inputs for manual execution
Thanks
---------------------------------------------------------------------
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Scot P. Floess
2016-03-08 07:40:56 UTC
Permalink
Didn't hear back - did you get you figure it out?
I'm confused as you are asking about using command line params (via the -D)
but then reusing those for the input task.
ant -f build.xml addNodes -Dagents="d01, d02, d03" -D{node???}='node1'
-D{node_description???}='node1 description'
Note you list -Dagents
<input message="Agents Name Seperated By , :" addproperty="agents" />
So the property "agents" is both passed in command line and then reused
inside with an input task.
Same with the properties node and node_description.
The for loop should have no trouble using properties denoted on the command
line with the -D
The -D will become a property in your ant script.
Post by Petronius
We have to have these inputs for manual execution
Thanks
---------------------------------------------------------------------
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Jan Matèrne (jhm)
2016-03-08 06:58:53 UTC
Permalink
Something like that?

Jan


ant -Dantcontrib.jar=path/to/ant-contrib-1.0b3.jar
-Dagent.list="node1,node2" -Dnode1.description=ServerA
-Dnode2.description=AnotherServer



<project default="startAgents" xmlns:antcontrib="antlib:net.sf.antcontrib">

<taskdef uri="antlib:net.sf.antcontrib"
resource="net/sf/antcontrib/antlib.xml"
classpath="${antcontrib.jar}"/>


<macrodef name="executeAgent">
<attribute name="agent"/>
<attribute name="description"/>
<sequential>
<echo>starting Agent @{agent}: @{description}</echo>
</sequential>
</macrodef>


<target name="startAgents">
<antcontrib:for list="${agent.list}" delimiter="," param="agent">
<sequential>
<executeAgent agent="@{agent}"
description="${@{agent}.description}"/>
</sequential>
</antcontrib:for>
</target>

</project>



Buildfile: C:\temp\ant-test\build.xml

startAgents:
[echo] starting Agent node1: ServerA
[echo] starting Agent node2: AnotherServer

BUILD SUCCESSFUL
Total time: 1 second
-----Ursprüngliche Nachricht-----
Gesendet: Dienstag, 8. März 2016 08:41
An: Ant Users List
Betreff: Re: Passing command Line args for a list
Didn't hear back - did you get you figure it out?
Post by Scot P. Floess
I'm confused as you are asking about using command line params (via
the -D) but then reusing those for the input task.
ant -f build.xml addNodes -Dagents="d01, d02, d03" -
D{node???}='node1'
Post by Scot P. Floess
-D{node_description???}='node1 description'
Note you list -Dagents
<input message="Agents Name Seperated By , :" addproperty="agents" />
So the property "agents" is both passed in command line and then
reused inside with an input task.
Same with the properties node and node_description.
The for loop should have no trouble using properties denoted on the
command line with the -D
The -D will become a property in your ant script.
Post by Petronius
We have to have these inputs for manual execution
Thanks
--------------------------------------------------------------------
-
Post by Scot P. Floess
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
additional
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Scot P. Floess
2016-03-09 20:35:09 UTC
Permalink
Jan,

Yeah that's what I thought would be wanted too... But I asked about the
input tasks and apparently those are needed as well. So I was sorta
confused about the whole thing.
Post by Jan Matèrne (jhm)
Something like that?
Jan
ant -Dantcontrib.jar=path/to/ant-contrib-1.0b3.jar
-Dagent.list="node1,node2" -Dnode1.description=ServerA
-Dnode2.description=AnotherServer
<project default="startAgents" xmlns:antcontrib="antlib:net.sf.antcontrib">
<taskdef uri="antlib:net.sf.antcontrib"
resource="net/sf/antcontrib/antlib.xml"
classpath="${antcontrib.jar}"/>
<macrodef name="executeAgent">
<attribute name="agent"/>
<attribute name="description"/>
<sequential>
</sequential>
</macrodef>
<target name="startAgents">
<antcontrib:for list="${agent.list}" delimiter="," param="agent">
<sequential>
</sequential>
</antcontrib:for>
</target>
</project>
Buildfile: C:\temp\ant-test\build.xml
[echo] starting Agent node1: ServerA
[echo] starting Agent node2: AnotherServer
BUILD SUCCESSFUL
Total time: 1 second
-----Ursprüngliche Nachricht-----
Gesendet: Dienstag, 8. März 2016 08:41
An: Ant Users List
Betreff: Re: Passing command Line args for a list
Didn't hear back - did you get you figure it out?
Post by Scot P. Floess
I'm confused as you are asking about using command line params (via
the -D) but then reusing those for the input task.
ant -f build.xml addNodes -Dagents="d01, d02, d03" -
D{node???}='node1'
Post by Scot P. Floess
-D{node_description???}='node1 description'
Note you list -Dagents
<input message="Agents Name Seperated By , :" addproperty="agents" />
So the property "agents" is both passed in command line and then
reused inside with an input task.
Same with the properties node and node_description.
The for loop should have no trouble using properties denoted on the
command line with the -D
The -D will become a property in your ant script.
Post by Petronius
We have to have these inputs for manual execution
Thanks
--------------------------------------------------------------------
-
Post by Scot P. Floess
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
additional
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare
---------------------------------------------------------------------
---------------------------------------------------------------------
Scot P. Floess RHCT (Certificate Number 605010084735240)
Chief Architect FlossWare http://sourceforge.net/projects/flossware
http://flossware.sourceforge.net
https://github.com/organizations/FlossWare

Loading...