Discussion:
How to define a task with nested elements in Ant?
Al Le
2017-06-03 21:20:47 UTC
Permalink
Hello,

is it possible to define a task in Ant which would have some nested
elements? Sort of like how it's done with the macrodef task but with a
bit structure.

For example, I'd like to define a task which would be used as follows:

<mytask>
<paramA value="AAA1"/>
<paramA value="AAA2"/>
<paramB value="BBB"/>
</mytask>


This should internally translate to

<java classname="some.Class">
<arg value="-parameterA"/> <arg value="AAA1"/>
<arg value="-parameterA"/> <arg value="AAA2"/>
<arg value="-parameterB"/> <arg value="BBB"/>
</java>


I.e. a <paramA> in the custom task should result in two args for the
java task.

I know I could write a custom task in Java using an instance of the java
task in the implementation. But I'd like to know whether (and how) it's
possible to do this directly in Ant (possibly with javascript), i.e.
without having to have some external JARs.

Thank you for any hints!

AL

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Jan Matèrne (jhm)
2017-06-03 21:42:07 UTC
Permalink
I dont know any easy way.
Simplest thing would be writing that kind in Java.
And if you dont want to download that jar from your buildfile you could the jar creation inline:
- generate the code (<echo>)
- compile (<javac>)
- archive that (<jar>)
- include that (<taskdef>)

Via <script> you have access to the Ant API so it could be possible to do that this way.
But I think, that's very hard ...

Jan
-----Ursprüngliche Nachricht-----
Gesendet: Samstag, 3. Juni 2017 23:21
An: Ant Users List
Betreff: How to define a task with nested elements in Ant?
Hello,
is it possible to define a task in Ant which would have some nested
elements? Sort of like how it's done with the macrodef task but with a
bit structure.
<mytask>
<paramA value="AAA1"/>
<paramA value="AAA2"/>
<paramB value="BBB"/>
</mytask>
This should internally translate to
<java classname="some.Class">
<arg value="-parameterA"/> <arg value="AAA1"/>
<arg value="-parameterA"/> <arg value="AAA2"/>
<arg value="-parameterB"/> <arg value="BBB"/> </java>
I.e. a <paramA> in the custom task should result in two args for the
java task.
I know I could write a custom task in Java using an instance of the
java task in the implementation. But I'd like to know whether (and how)
it's possible to do this directly in Ant (possibly with javascript),
i.e.
without having to have some external JARs.
Thank you for any hints!
AL
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Al Le
2017-06-04 23:41:07 UTC
Permalink
Hrm...

It would be cool if there existed a task which would allow to construct
the translation of the task in Ant into some other existing tasks, e.g.
using XPath.

I.e. you'd

1. Define the syntax of a new task; not with 'attribute' and 'element'
(like in macrodef) but via e.g. XSD.

2. Define how instances of this task should translate into existing Ant
tasks, e.g. using XSL.

The first thing would be used by Ant to check whether the task is used
properly. The second thing would be used to execute such a task: first,
Ant would apply the XSL to the task instance which would yield a
fragment consisting of known ant tasks; then Ant would execute this
fragment.

Have such thought been played with in the Ant community? I think, it
would be a powerful tool to create custom tasks without having to code
in Java.

Just thinking aloud...
Post by Jan Matèrne (jhm)
I dont know any easy way.
Simplest thing would be writing that kind in Java.
- generate the code (<echo>)
- compile (<javac>)
- archive that (<jar>)
- include that (<taskdef>)
Via <script> you have access to the Ant API so it could be possible to do that this way.
But I think, that's very hard ...
Jan
-----Ursprüngliche Nachricht-----
Gesendet: Samstag, 3. Juni 2017 23:21
An: Ant Users List
Betreff: How to define a task with nested elements in Ant?
Hello,
is it possible to define a task in Ant which would have some nested
elements? Sort of like how it's done with the macrodef task but with a
bit structure.
<mytask>
<paramA value="AAA1"/>
<paramA value="AAA2"/>
<paramB value="BBB"/>
</mytask>
This should internally translate to
<java classname="some.Class">
<arg value="-parameterA"/> <arg value="AAA1"/>
<arg value="-parameterA"/> <arg value="AAA2"/>
<arg value="-parameterB"/> <arg value="BBB"/> </java>
I.e. a <paramA> in the custom task should result in two args for the
java task.
I know I could write a custom task in Java using an instance of the
java task in the implementation. But I'd like to know whether (and how)
it's possible to do this directly in Ant (possibly with javascript),
i.e.
without having to have some external JARs.
Thank you for any hints!
AL
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Alexander Levin
2017-06-04 23:39:10 UTC
Permalink
Hrm...

It would be cool if there existed a task which would allow to construct
the translation of the task in Ant into some other existing tasks, e.g.
using XPath.

I.e. you'd

1. Define the syntax of a new task; not with 'attribute' and 'element'
(like in macrodef) but via e.g. XSD.

2. Define how instances of this task should translate into existing Ant
tasks, e.g. using XSL.

The first thing would be used by Ant to check whether the task is used
properly. The second thing would be used to execute such a task: first,
Ant would apply the XSL to the task instance which would yield a
fragment consisting of known ant tasks; then Ant would execute this
fragment.

Have such thought been played with in the Ant community? I think, it
would be a powerful tool to create custom tasks without having to code
in Java.

Just thinking aloud...
Post by Jan Matèrne (jhm)
I dont know any easy way.
Simplest thing would be writing that kind in Java.
- generate the code (<echo>)
- compile (<javac>)
- archive that (<jar>)
- include that (<taskdef>)
Via <script> you have access to the Ant API so it could be possible to do that this way.
But I think, that's very hard ...
Jan
-----Ursprüngliche Nachricht-----
Gesendet: Samstag, 3. Juni 2017 23:21
An: Ant Users List
Betreff: How to define a task with nested elements in Ant?
Hello,
is it possible to define a task in Ant which would have some nested
elements? Sort of like how it's done with the macrodef task but with a
bit structure.
<mytask>
<paramA value="AAA1"/>
<paramA value="AAA2"/>
<paramB value="BBB"/>
</mytask>
This should internally translate to
<java classname="some.Class">
<arg value="-parameterA"/> <arg value="AAA1"/>
<arg value="-parameterA"/> <arg value="AAA2"/>
<arg value="-parameterB"/> <arg value="BBB"/> </java>
I.e. a <paramA> in the custom task should result in two args for the
java task.
I know I could write a custom task in Java using an instance of the
java task in the implementation. But I'd like to know whether (and how)
it's possible to do this directly in Ant (possibly with javascript),
i.e.
without having to have some external JARs.
Thank you for any hints!
AL
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Jan Matèrne (jhm)
2017-06-05 13:15:35 UTC
Permalink
You could play that way:
* use <xslt> to transform that peace into a 'valid Ant buildfile'
* use <ant> to call that generated file

Jan
-----Ursprüngliche Nachricht-----
Gesendet: Montag, 5. Juni 2017 01:39
An: Ant Users List; Jan Matèrne (jhm)
Betreff: Re: How to define a task with nested elements in Ant?
Hrm...
It would be cool if there existed a task which would allow to construct
the translation of the task in Ant into some other existing tasks, e.g.
using XPath.
I.e. you'd
1. Define the syntax of a new task; not with 'attribute' and 'element'
(like in macrodef) but via e.g. XSD.
2. Define how instances of this task should translate into existing Ant
tasks, e.g. using XSL.
The first thing would be used by Ant to check whether the task is used
properly. The second thing would be used to execute such a task: first,
Ant would apply the XSL to the task instance which would yield a
fragment consisting of known ant tasks; then Ant would execute this
fragment.
Have such thought been played with in the Ant community? I think, it
would be a powerful tool to create custom tasks without having to code
in Java.
Just thinking aloud...
Post by Jan Matèrne (jhm)
I dont know any easy way.
Simplest thing would be writing that kind in Java.
And if you dont want to download that jar from your buildfile you
- generate the code (<echo>)
- compile (<javac>)
- archive that (<jar>)
- include that (<taskdef>)
Via <script> you have access to the Ant API so it could be possible
to do that this way.
Post by Jan Matèrne (jhm)
But I think, that's very hard ...
Jan
-----Ursprüngliche Nachricht-----
Gesendet: Samstag, 3. Juni 2017 23:21
An: Ant Users List
Betreff: How to define a task with nested elements in Ant?
Hello,
is it possible to define a task in Ant which would have some nested
elements? Sort of like how it's done with the macrodef task but with
a bit structure.
For example, I'd like to define a task which would be used as
<mytask>
<paramA value="AAA1"/>
<paramA value="AAA2"/>
<paramB value="BBB"/>
</mytask>
This should internally translate to
<java classname="some.Class">
<arg value="-parameterA"/> <arg value="AAA1"/>
<arg value="-parameterA"/> <arg value="AAA2"/>
<arg value="-parameterB"/> <arg value="BBB"/> </java>
I.e. a <paramA> in the custom task should result in two args for the
java task.
I know I could write a custom task in Java using an instance of the
java task in the implementation. But I'd like to know whether (and
how) it's possible to do this directly in Ant (possibly with
javascript), i.e.
without having to have some external JARs.
Thank you for any hints!
AL
--------------------------------------------------------------------
-
Post by Jan Matèrne (jhm)
---------------------------------------------------------------------
additional
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Al Le
2017-06-05 15:38:20 UTC
Permalink
Yes, indeed.

But then I'd probably rather translate the whole Ant script and then let
Ant process the result of the translation. I.e. the "trick" would be
absolutely transparent to Ant (it would be rather part of the build
infrastructure).

Not quite what I've thought of (in my dreams it should happen internally
in Ant), but technically possible :-)

Thank you for the quick responses!

AL
Post by Jan Matèrne (jhm)
* use <xslt> to transform that peace into a 'valid Ant buildfile'
* use <ant> to call that generated file
Jan
-----Ursprüngliche Nachricht-----
Gesendet: Montag, 5. Juni 2017 01:39
An: Ant Users List; Jan Matèrne (jhm)
Betreff: Re: How to define a task with nested elements in Ant?
Hrm...
It would be cool if there existed a task which would allow to construct
the translation of the task in Ant into some other existing tasks, e.g.
using XPath.
I.e. you'd
1. Define the syntax of a new task; not with 'attribute' and 'element'
(like in macrodef) but via e.g. XSD.
2. Define how instances of this task should translate into existing Ant
tasks, e.g. using XSL.
The first thing would be used by Ant to check whether the task is used
properly. The second thing would be used to execute such a task: first,
Ant would apply the XSL to the task instance which would yield a
fragment consisting of known ant tasks; then Ant would execute this
fragment.
Have such thought been played with in the Ant community? I think, it
would be a powerful tool to create custom tasks without having to code
in Java.
Just thinking aloud...
Post by Jan Matèrne (jhm)
I dont know any easy way.
Simplest thing would be writing that kind in Java.
And if you dont want to download that jar from your buildfile you
- generate the code (<echo>)
- compile (<javac>)
- archive that (<jar>)
- include that (<taskdef>)
Via <script> you have access to the Ant API so it could be possible
to do that this way.
Post by Jan Matèrne (jhm)
But I think, that's very hard ...
Jan
-----Ursprüngliche Nachricht-----
Gesendet: Samstag, 3. Juni 2017 23:21
An: Ant Users List
Betreff: How to define a task with nested elements in Ant?
Hello,
is it possible to define a task in Ant which would have some nested
elements? Sort of like how it's done with the macrodef task but with
a bit structure.
For example, I'd like to define a task which would be used as
<mytask>
<paramA value="AAA1"/>
<paramA value="AAA2"/>
<paramB value="BBB"/>
</mytask>
This should internally translate to
<java classname="some.Class">
<arg value="-parameterA"/> <arg value="AAA1"/>
<arg value="-parameterA"/> <arg value="AAA2"/>
<arg value="-parameterB"/> <arg value="BBB"/> </java>
I.e. a <paramA> in the custom task should result in two args for the
java task.
I know I could write a custom task in Java using an instance of the
java task in the implementation. But I'd like to know whether (and
how) it's possible to do this directly in Ant (possibly with
javascript), i.e.
without having to have some external JARs.
Thank you for any hints!
AL
--------------------------------------------------------------------
-
Post by Jan Matèrne (jhm)
---------------------------------------------------------------------
additional
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org

Loading...