You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Conor MacNeill <co...@cortexebusiness.com.au> on 2003/06/13 07:23:19 UTC
Re: Ant scripting from Jython.
Hi Duncan,
You all might like to look at two recent threads in ant-dev and ant-user that
are somewhat related to this topic.
http://marc.theaimsgroup.com/?l=ant-dev&m=105516662409107&w=2
and
http://marc.theaimsgroup.com/?l=ant-user&m=105491111510585&w=2
Instead of the "script driving Ant tasks" approach, <scriptdef> is more like a
script within a task. As such, the scripts would potentially be more focussed
on the things that need to be scripty rather than doing the whole build in
the script. After all, IMHO,
copyWrapper("C:\\java\\jython_ant\\src\HelloJython.java",
"C:\\java\\jython_ant\\temp", project)
doesn't end up any "better" than
<copy file="C:\java\jython_ant\src\HelloJython.java"
todir="C:\java\jython_ant\temp"/>
In fact because the attributes are named, the XML is easier to understand as
it does not rely on implicit position-dependent parameters. IT's more redable
which is probably counter-intuitive.
In terms of Jonathan's original need for wrappers, there is some possibility
that they could be auto-generated using the Ant introspection facilities. One
problem is that most Ant tasks support a multitude of attributes. As I said
above, XML is quite nice there as it allows attributes to be named. You only
provide the attributes you want and mostly everything else takes sensible
defaults. In the copy example, think about what the wrapper would look like
that exposes all the capabilities of <copy>
(http://ant.apache.org/manual/CoreTasks/copy.html). I think it could be quite
ugly unless your scripting language also supports named attributes - I have
limited experience with Jython, so I can't say.
BTW, I once experimented with converting build files to scripts (code
actually). I wrote an XSL template to turn a simple Ant build into a Java
program. It was effectively a build compiler (part of Mutant's botostrap
process).
Here's the XSL
http://cvs.apache.org/viewcvs.cgi/*checkout*/ant/proposal/mutant/build/Attic/bootstrap.xsl?rev=1.3&content-type=text/plain
You can see the result here.
http://cvs.apache.org/viewcvs.cgi/ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Attic/MutantBuilder.java?rev=1.7&content-type=text/vnd.viewcvs-markup
Not that useful but a bit more grist for this mill. It certainly showed me
that it is hard to cram the expressiveness of the XML approach into method
calls. I had to limit myself to a very narrow subset of tasks and their usage
patterns.
Conor
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: Ant scripting from Jython.
Posted by Bruce Atherton <br...@callenish.com>.
At 11:43 AM 6/13/2003 -0700, James Duncan Davidson wrote:
>>Not that useful but a bit more grist for this mill. It certainly showed me
>>that it is hard to cram the expressiveness of the XML approach into method
>>calls. I had to limit myself to a very narrow subset of tasks and their usage
>>patterns.
>
>It is a tradeoff.
I'm curious about this tradeoff and about the "XML Burden" you mention in
your blog. Is the issue using XML or is it better access to scripting
facilities within Ant?
The reason I ask is that Jelly already provides an XML scripting language
that can run Ant tasks. Using Jelly would allow both the expressiveness of
XML and the flexibility of scripting languages, for those that need it. It
would also minimize the mental shifts as well as the ugliness of mixing
different languages in a single file.
I don't know if Jelly is the right answer to the problem you see (I've
never used it myself). I know that many people are intimidated by XML,
especially XML that has a lot of namespace stuff going on and Jelly has
plenty of that. Also, Python is a very intuitive language to write in,
whereas using tags is awkward. I'm just trying to make sure I understand
the problem you are identifying.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: Ant scripting from Jython.
Posted by peter reilly <pe...@corvil.com>.
jython does support named parameters, one
can do some bizarre stuff:
<script language="jython">
from java.io import File
def twrapper(taskname, **args):
t = project.createTask(taskname)
for a in args.keys():
exec("t.%s = %s" % (a, args[a]))
t.execute()
twrapper('echo', message="'hello world'")
twrapper('delete', quiet="1", dir="File('todir')")
twrapper('mkdir', dir='File("todir")')
twrapper('copy', file='File("fromfile")', todir='File("todir")')
</script>
output:
hello world
Deleting directory /home/preilly/proj/learning/outofdate/todir
Created dir: /home/preilly/proj/learning/outofdate/todir
Copying 1 file to /home/preilly/proj/learning/outofdate/todir
Peter.
On Friday 13 June 2003 06:23, Conor MacNeill wrote:
> Hi Duncan,
>
> You all might like to look at two recent threads in ant-dev and ant-user
> that are somewhat related to this topic.
>
> http://marc.theaimsgroup.com/?l=ant-dev&m=105516662409107&w=2
>
> and
>
> http://marc.theaimsgroup.com/?l=ant-user&m=105491111510585&w=2
>
> Instead of the "script driving Ant tasks" approach, <scriptdef> is more
> like a script within a task. As such, the scripts would potentially be more
> focussed on the things that need to be scripty rather than doing the whole
> build in the script. After all, IMHO,
>
> copyWrapper("C:\\java\\jython_ant\\src\HelloJython.java",
> "C:\\java\\jython_ant\\temp", project)
>
> doesn't end up any "better" than
>
> <copy file="C:\java\jython_ant\src\HelloJython.java"
> todir="C:\java\jython_ant\temp"/>
>
> In fact because the attributes are named, the XML is easier to understand
> as it does not rely on implicit position-dependent parameters. IT's more
> redable which is probably counter-intuitive.
>
> In terms of Jonathan's original need for wrappers, there is some
> possibility that they could be auto-generated using the Ant introspection
> facilities. One problem is that most Ant tasks support a multitude of
> attributes. As I said above, XML is quite nice there as it allows
> attributes to be named. You only provide the attributes you want and mostly
> everything else takes sensible defaults. In the copy example, think about
> what the wrapper would look like that exposes all the capabilities of
> <copy>
> (http://ant.apache.org/manual/CoreTasks/copy.html). I think it could be
> quite ugly unless your scripting language also supports named attributes -
> I have limited experience with Jython, so I can't say.
>
> BTW, I once experimented with converting build files to scripts (code
> actually). I wrote an XSL template to turn a simple Ant build into a Java
> program. It was effectively a build compiler (part of Mutant's botostrap
> process).
>
> Here's the XSL
> http://cvs.apache.org/viewcvs.cgi/*checkout*/ant/proposal/mutant/build/Atti
>c/bootstrap.xsl?rev=1.3&content-type=text/plain
>
> You can see the result here.
> http://cvs.apache.org/viewcvs.cgi/ant/proposal/mutant/src/java/bootstrap/or
>g/apache/ant/builder/Attic/MutantBuilder.java?rev=1.7&content-type=text/vnd.
>viewcvs-markup
>
> Not that useful but a bit more grist for this mill. It certainly showed me
> that it is hard to cram the expressiveness of the XML approach into method
> calls. I had to limit myself to a very narrow subset of tasks and their
> usage patterns.
>
> Conor
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: Ant scripting from Jython.
Posted by James Duncan Davidson <du...@x180.net>.
On Thursday, Jun 12, 2003, at 22:23 US/Pacific, Conor MacNeill wrote:
> http://marc.theaimsgroup.com/?l=ant-dev&m=105516662409107&w=2
> Instead of the "script driving Ant tasks" approach, <scriptdef> is
> more like a
> script within a task. As such, the scripts would potentially be more
> focussed
> on the things that need to be scripty rather than doing the whole
> build in
> the script.
Cool. My only thought here is that I've been doing quite a bit of work
with Sherlock where you can define functionality in either JavaScript
or XQuery and all the little scriptlets are embedded in tags. After a
few months of playing with that approach, I've really decided that I
dislike writing code between XML tags. Mental shifts and all that. But
that's just a personal finding. YMMV.
Also, there's an entire discussion that could be had of where the
control flow should be (inside or outside).
> After all, IMHO,
>
> copyWrapper("C:\\java\\jython_ant\\src\HelloJython.java",
> "C:\\java\\jython_ant\\temp", project)
>
> doesn't end up any "better" than
>
> <copy file="C:\java\jython_ant\src\HelloJython.java"
> todir="C:\java\jython_ant\temp"/>
No, in this example it doesn't. But it'll be interesting to see if the
full expressiveness of the language can be brought to bear on the
problem. I'm not endorsing making the big shift now, but I do like
Jonathan's approach as an experiment. If it turns out that having the
full expressiveness of the language allows a shift in the way that you
can do things, then great, it's a success. If all you've done is like
you've shown above and end up with simple replacements, then it's still
nice (though maybe not as nice) from the point of shifting logic from
the inside of the tag to the outside.
> In terms of Jonathan's original need for wrappers, there is some
> possibility
> that they could be auto-generated using the Ant introspection
> facilities. One
> problem is that most Ant tasks support a multitude of attributes.
Possible. Though auto-gen code usually doesn't do that good a job at
allowing a paradigm shift in thinking.
> Not that useful but a bit more grist for this mill. It certainly
> showed me
> that it is hard to cram the expressiveness of the XML approach into
> method
> calls. I had to limit myself to a very narrow subset of tasks and
> their usage
> patterns.
It is a tradeoff. And it's one that will take a bit of experience with
playing with a new model to figure out if its worthwhile or not. In any
case, I'm still off playing with Mac stuff so my involvement will be
limited to just seeing how things turn out.
James Duncan Davidson
Coder, Speaker, Author
http://x180.net/
[life live];
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org