You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ed Taekema <et...@earthlink.net> on 2004/04/24 05:26:44 UTC

Article: Use Jython to Write Ant Tasks

I've written a guide to writing Ant tasks using Jython:  how to add scripted behaviour
to ant builds. It details the steps to write a custom Ant task in jython, compile
it and install it into ant so it can be used as any other task in an ant build. 
The article also takes a quick look at an alternate implementation using Groovy.

And ... here is the url:  http://www.pycs.net/users/0000177/stories/11.html .

Enjoy,

Ed Taekema
Toronto, Canada

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Article: Use Jython to Write Ant Tasks

Posted by Peter Reilly <pe...@corvil.com>.
Scripttypedef is a task that may be in ant 1.7.
It is like <scriptdef> except that it uses reflection
on a class provided by a BSH script to find the attributes
and nested elements. It may also be used to make
Conditions, Filters , FilenameMappers and Selectors.

<scriptyypedef name="bytwo" language="beanshell">
import org.apache.tools.ant.Task;
public class ByTwo extends Task {
   private int value = 1;
   public void setValue(int value) {
      this.value = value;
   }
   public void execute() {
      log("bytwo is " + (value * 2));
   }
}
</scripttypedef>
<bytwo value="4"/>

<scriptyypedef name="bythree" language="groovy">
import org.apache.tools.ant.Task
public class ByThree extends Task {
   int value = 1
   public void execute() {
      log("bythree is " + (value * 3))
   }
}
ByThree
</scripttypedef>
<bythree value="5"/>

Peter

Ed Taekema wrote:

> Not sure what you need to do to support scripttypedef ... but you can 
> access the project as the following code demonstrates:
>
> def startSession(self):
>
>         project = Task.getProject(self)
>         project.setProperty("SESSION_ADDR", "XXXX");
>
> Does the  task need to "self register"? or does it register as part of 
> its constructor?
>
> Ed
>
>
> \At 03:50 AM 4/26/2004, Peter Reilly wrote:
>
>> Hi Ed,
>> This is a interresting article - I did not know about the """@sig " 
>> trick.
>>
>> I tried to do the following using ant's script task:
>>
>> from org.apache.tools.ant import Task
>>
>> class SimpleTask(Task):
>>
>>  message = ""
>>
>>  def execute(self):
>>     """@sig public void execute()"""
>>     Task.log(self, "Message: " + self.message)
>>
>>  def setMessage(this, aMessage):
>>     """@sig public void setMessage(java.lang.String str)"""
>>     this.message = aMessage
>>
>> project.addTaskDefinition("s", SimpleTask)
>>
>> But when the task is used, I get:
>> ImportError: no module named main
>>
>> This is a pity as it would be nice to add jython to the
>> languages supported by <scripttypedef>.
>>
>>
>> The groovy example would be more  groovly  written:
>>
>> import org.apache.tools.ant.Task
>> public class GroovySimpleTask extends Task {
>>  String message = ""
>>  public void execute() {
>>    log(message)
>>  }
>> }
>>
>> project.addTaskDefinition("s", GroovySimpleTask)
>>
>>
>> Peter
>>
>>
>> Ed Taekema wrote:
>>
>>> I've written a guide to writing Ant tasks using Jython:  how to add 
>>> scripted behaviour
>>> to ant builds. It details the steps to write a custom Ant task in 
>>> jython, compile
>>> it and install it into ant so it can be used as any other task in an 
>>> ant build. The article also takes a quick look at an alternate 
>>> implementation using Groovy.
>>>
>>> And ... here is the url:  
>>> http://www.pycs.net/users/0000177/stories/11.html .
>>>
>>> Enjoy,
>>>
>>> Ed Taekema
>>> Toronto, Canada
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Article: Use Jython to Write Ant Tasks

Posted by Ed Taekema <et...@earthlink.net>.
Not sure what you need to do to support scripttypedef ... but you can 
access the project as the following code demonstrates:

def startSession(self):

         project = Task.getProject(self)
         project.setProperty("SESSION_ADDR", "XXXX");

Does the  task need to "self register"? or does it register as part of its 
constructor?

Ed


\At 03:50 AM 4/26/2004, Peter Reilly wrote:
>Hi Ed,
>This is a interresting article - I did not know about the """@sig " trick.
>
>I tried to do the following using ant's script task:
>
>from org.apache.tools.ant import Task
>
>class SimpleTask(Task):
>
>  message = ""
>
>  def execute(self):
>     """@sig public void execute()"""
>     Task.log(self, "Message: " + self.message)
>
>  def setMessage(this, aMessage):
>     """@sig public void setMessage(java.lang.String str)"""
>     this.message = aMessage
>
>project.addTaskDefinition("s", SimpleTask)
>
>But when the task is used, I get:
>ImportError: no module named main
>
>This is a pity as it would be nice to add jython to the
>languages supported by <scripttypedef>.
>
>
>The groovy example would be more  groovly  written:
>
>import org.apache.tools.ant.Task
>public class GroovySimpleTask extends Task {
>  String message = ""
>  public void execute() {
>    log(message)
>  }
>}
>
>project.addTaskDefinition("s", GroovySimpleTask)
>
>
>Peter
>
>
>Ed Taekema wrote:
>
>>I've written a guide to writing Ant tasks using Jython:  how to add 
>>scripted behaviour
>>to ant builds. It details the steps to write a custom Ant task in jython, 
>>compile
>>it and install it into ant so it can be used as any other task in an ant 
>>build. The article also takes a quick look at an alternate implementation 
>>using Groovy.
>>
>>And ... here is the url:  http://www.pycs.net/users/0000177/stories/11.html .
>>
>>Enjoy,
>>
>>Ed Taekema
>>Toronto, Canada

Re: Article: Use Jython to Write Ant Tasks

Posted by Peter Reilly <pe...@corvil.com>.
Hi Ed,
This is a interresting article - I did not know about the """@sig " trick.

I tried to do the following using ant's script task:

from org.apache.tools.ant import Task

class SimpleTask(Task):

  message = ""

  def execute(self):
     """@sig public void execute()"""
     Task.log(self, "Message: " + self.message)

  def setMessage(this, aMessage):
     """@sig public void setMessage(java.lang.String str)"""
     this.message = aMessage

project.addTaskDefinition("s", SimpleTask)

But when the task is used, I get:
ImportError: no module named main

This is a pity as it would be nice to add jython to the
languages supported by <scripttypedef>.


The groovy example would be more  groovly  written:

import org.apache.tools.ant.Task
public class GroovySimpleTask extends Task {
  String message = ""
  public void execute() {
    log(message)
  }
}

project.addTaskDefinition("s", GroovySimpleTask)


Peter


Ed Taekema wrote:

>I've written a guide to writing Ant tasks using Jython:  how to add scripted behaviour
>to ant builds. It details the steps to write a custom Ant task in jython, compile
>it and install it into ant so it can be used as any other task in an ant build. 
>The article also takes a quick look at an alternate implementation using Groovy.
>
>And ... here is the url:  http://www.pycs.net/users/0000177/stories/11.html .
>
>Enjoy,
>
>Ed Taekema
>Toronto, Canada
>
>---------------------------------------------------------------------
>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: ant2html with support for macrodef? (was... RE: Article: Use Jython to Write Ant Tasks)

Posted by Bill Rich <bi...@attglobal.net>.
Hi Jake,  Sorry about the copyright.  No it does not make sense to have it on this file.
This is what happens when you get in a hurry and just copy without reading what you copy.
All I wanted on there was that I modified the file and to give credit to the original.

I went to the IBM site to get another copy of the file to see what the real differences
were and I found a completely different file there this time.  Now I am puzzled as to
where I got the original file I modified.

I have Mozilla 1.6 on one of my machines and I tried it and got the same result you
reported.  It must be IE specific scripting in the file that causes this to happen.  I
would be very happy to get the file so it works on both IE and Mozilla.

wrt the nbsp problem you mentioned, I did not get that in the original file I downloaded
but this time I do get it in both Mozilla and IE.  To get around it I just replaced all
the '&amp;nbsp;' with ' ' in the file.  It only seems to affect the navigation frames
anyway.

Thanks.  Bill

Bill Rich
Wilandra Consulting LLC
1325 Addiewell Place
San Jose, CA  95120-3905
phone:      +1 408 268-2452
mobile:     +1 408 410-9713
Santa Cruz: +1 831 464-9007
fax:        +1 413 669-9716
billrich@wilandra.com or billrich@attglobal.net
http://www.wilandra.com

-----Original Message-----
From: Jacob Kjome [mailto:hoju@visi.com]
Sent: Sunday, April 25, 2004 4:35 PM
To: Ant Users List
Subject: RE: ant2html with support for macrodef? (was... RE: Article:
Use Jython to Write Ant Tasks)


At 10:56 AM 4/25/2004 -0500, you wrote:
>At 03:09 PM 4/24/2004 -0700, you wrote:
>>Attached is my version of ant2html.  It is based on
>>http://www-106.ibm.com/developerworks/xml/library/x-antxsl/, which, like
>>you, I found to
>>do the basic work nicely but ...  I renamed it so it will not conflict
>>with the original.
>>You will need to reference wfrant2html.xsl to use it.  I added the
>>support for macrodef
>>but not scriptdef.  I also fiddled with the formatting a little but it is
>>not up to what I
>>would really like.  When I have some time I will try to do more with the
>>formatting.  I
>>will try to add scriptdef support this weekend and make it available to
>>you as soon as it
>>is ready.
>>
>>Thanks.  Bill
>
>Hi Bill,
>
>Thanks for providing file.  However, I tried it out under Mozilla (recent
>nightly version) and all I get is a frameset with no content.  Mozilla
>successfully renders the original file other than the issue I brought up
>previously with the literal rendering of "&nbsp;".  What did you use to
>test your modifications?  IE, the Ant <style> task?  I'm not sure whether
>this is an issue with a bug in Mozilla's XSLT engine or something in the
>XSLT itself.  If you could try it in Mozilla, that would be great.

Shortly after I sent this, I realized that there is scripting which is IE
specific.  I think I will try to convert this to work for both IE and
Mozilla and post the result back to the list.  BTW, I noticed you added a
copyright to the file.  Does that make sense when the original code was
written by someone else and you just added to it?  I'm no expert on
copyright law so let me know my question is a silly one.

Jake


>>-----Original Message-----
>>From: Jacob Kjome [mailto:hoju@visi.com]
>>Sent: Saturday, April 24, 2004 1:55 PM
>>To: Ant Users List
>>Subject: ant2html with support for macrodef? (was... RE: Article: Use
>>Jython to Write Ant Tasks)
>>
>>
>>At 09:55 AM 4/24/2004 -0700, you wrote:
>> >For the documentation I got a copy of ant2html
>> >but found it did not list the macrodefs and left out all comments in the
>> >code.  I added
>> >this to ant2html and it now produces more of what I want for
>> >documentation.  I think there
>> >is more that can be done to add links and other documentation information
>> >to Ant but it
>> >can come later.  The xsl file was fairly easy to modify and I may try some
>> >more
>> >modifications later when I have more time.
>> >
>> >Thanks.  Bill
>>
>>Mind providing your modified ant2html?  I take it you mean the one from
>>here, right..
>>http://www-106.ibm.com/developerworks/xml/library/x-antxsl/
>>
>>
>>I tried that out and I found it to basically work, except that the
>>indentation done using &nbsp; entities ended up showing up literally in the
>>transformed document, so I saw a ton of "&nbsp;" (at least as transformed
>>by Mozilla).  I'm not a super-whiz with XSLT, so I'm not sure how to get
>>rid of them.  If your version accounts for <macrodef>, <scriptdef>, and
>>other things, that would be very useful to me and, I'm sure, others as well.
>>
>>
>>Jake
>>
>>
>>---------------------------------------------------------------------
>>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
>
>
>---------------------------------------------------------------------
>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



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: ant2html with support for macrodef? (was... RE: Article: Use Jython to Write Ant Tasks)

Posted by Jacob Kjome <ho...@visi.com>.
At 10:56 AM 4/25/2004 -0500, you wrote:
>At 03:09 PM 4/24/2004 -0700, you wrote:
>>Attached is my version of ant2html.  It is based on
>>http://www-106.ibm.com/developerworks/xml/library/x-antxsl/, which, like 
>>you, I found to
>>do the basic work nicely but ...  I renamed it so it will not conflict 
>>with the original.
>>You will need to reference wfrant2html.xsl to use it.  I added the 
>>support for macrodef
>>but not scriptdef.  I also fiddled with the formatting a little but it is 
>>not up to what I
>>would really like.  When I have some time I will try to do more with the 
>>formatting.  I
>>will try to add scriptdef support this weekend and make it available to 
>>you as soon as it
>>is ready.
>>
>>Thanks.  Bill
>
>Hi Bill,
>
>Thanks for providing file.  However, I tried it out under Mozilla (recent 
>nightly version) and all I get is a frameset with no content.  Mozilla 
>successfully renders the original file other than the issue I brought up 
>previously with the literal rendering of "&nbsp;".  What did you use to 
>test your modifications?  IE, the Ant <style> task?  I'm not sure whether 
>this is an issue with a bug in Mozilla's XSLT engine or something in the 
>XSLT itself.  If you could try it in Mozilla, that would be great.

Shortly after I sent this, I realized that there is scripting which is IE 
specific.  I think I will try to convert this to work for both IE and 
Mozilla and post the result back to the list.  BTW, I noticed you added a 
copyright to the file.  Does that make sense when the original code was 
written by someone else and you just added to it?  I'm no expert on 
copyright law so let me know my question is a silly one.

Jake


>>-----Original Message-----
>>From: Jacob Kjome [mailto:hoju@visi.com]
>>Sent: Saturday, April 24, 2004 1:55 PM
>>To: Ant Users List
>>Subject: ant2html with support for macrodef? (was... RE: Article: Use
>>Jython to Write Ant Tasks)
>>
>>
>>At 09:55 AM 4/24/2004 -0700, you wrote:
>> >For the documentation I got a copy of ant2html
>> >but found it did not list the macrodefs and left out all comments in the
>> >code.  I added
>> >this to ant2html and it now produces more of what I want for
>> >documentation.  I think there
>> >is more that can be done to add links and other documentation information
>> >to Ant but it
>> >can come later.  The xsl file was fairly easy to modify and I may try some
>> >more
>> >modifications later when I have more time.
>> >
>> >Thanks.  Bill
>>
>>Mind providing your modified ant2html?  I take it you mean the one from
>>here, right..
>>http://www-106.ibm.com/developerworks/xml/library/x-antxsl/
>>
>>
>>I tried that out and I found it to basically work, except that the
>>indentation done using &nbsp; entities ended up showing up literally in the
>>transformed document, so I saw a ton of "&nbsp;" (at least as transformed
>>by Mozilla).  I'm not a super-whiz with XSLT, so I'm not sure how to get
>>rid of them.  If your version accounts for <macrodef>, <scriptdef>, and
>>other things, that would be very useful to me and, I'm sure, others as well.
>>
>>
>>Jake
>>
>>
>>---------------------------------------------------------------------
>>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
>
>
>---------------------------------------------------------------------
>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: ant2html with support for macrodef? (was... RE: Article: Use Jython to Write Ant Tasks)

Posted by Jacob Kjome <ho...@visi.com>.
At 03:09 PM 4/24/2004 -0700, you wrote:
>Attached is my version of ant2html.  It is based on
>http://www-106.ibm.com/developerworks/xml/library/x-antxsl/, which, like 
>you, I found to
>do the basic work nicely but ...  I renamed it so it will not conflict 
>with the original.
>You will need to reference wfrant2html.xsl to use it.  I added the support 
>for macrodef
>but not scriptdef.  I also fiddled with the formatting a little but it is 
>not up to what I
>would really like.  When I have some time I will try to do more with the 
>formatting.  I
>will try to add scriptdef support this weekend and make it available to 
>you as soon as it
>is ready.
>
>Thanks.  Bill

Hi Bill,

Thanks for providing file.  However, I tried it out under Mozilla (recent 
nightly version) and all I get is a frameset with no content.  Mozilla 
successfully renders the original file other than the issue I brought up 
previously with the literal rendering of "&nbsp;".  What did you use to 
test your modifications?  IE, the Ant <style> task?  I'm not sure whether 
this is an issue with a bug in Mozilla's XSLT engine or something in the 
XSLT itself.  If you could try it in Mozilla, that would be great.


Jake



>-----Original Message-----
>From: Jacob Kjome [mailto:hoju@visi.com]
>Sent: Saturday, April 24, 2004 1:55 PM
>To: Ant Users List
>Subject: ant2html with support for macrodef? (was... RE: Article: Use
>Jython to Write Ant Tasks)
>
>
>At 09:55 AM 4/24/2004 -0700, you wrote:
> >For the documentation I got a copy of ant2html
> >but found it did not list the macrodefs and left out all comments in the
> >code.  I added
> >this to ant2html and it now produces more of what I want for
> >documentation.  I think there
> >is more that can be done to add links and other documentation information
> >to Ant but it
> >can come later.  The xsl file was fairly easy to modify and I may try some
> >more
> >modifications later when I have more time.
> >
> >Thanks.  Bill
>
>Mind providing your modified ant2html?  I take it you mean the one from
>here, right..
>http://www-106.ibm.com/developerworks/xml/library/x-antxsl/
>
>
>I tried that out and I found it to basically work, except that the
>indentation done using &nbsp; entities ended up showing up literally in the
>transformed document, so I saw a ton of "&nbsp;" (at least as transformed
>by Mozilla).  I'm not a super-whiz with XSLT, so I'm not sure how to get
>rid of them.  If your version accounts for <macrodef>, <scriptdef>, and
>other things, that would be very useful to me and, I'm sure, others as well.
>
>
>Jake
>
>
>---------------------------------------------------------------------
>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


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: ant2html with support for macrodef? (was... RE: Article: Use Jython to Write Ant Tasks)

Posted by Bill Rich <bi...@attglobal.net>.
Attached is my version of ant2html.  It is based on
http://www-106.ibm.com/developerworks/xml/library/x-antxsl/, which, like you, I found to
do the basic work nicely but ...  I renamed it so it will not conflict with the original.
You will need to reference wfrant2html.xsl to use it.  I added the support for macrodef
but not scriptdef.  I also fiddled with the formatting a little but it is not up to what I
would really like.  When I have some time I will try to do more with the formatting.  I
will try to add scriptdef support this weekend and make it available to you as soon as it
is ready.

Thanks.  Bill

Bill Rich
Wilandra Consulting LLC
1325 Addiewell Place
San Jose, CA  95120-3905
phone:      +1 408 268-2452
mobile:     +1 408 410-9713
Santa Cruz: +1 831 464-9007
fax:        +1 413 669-9716
billrich@wilandra.com or billrich@attglobal.net
http://www.wilandra.com

-----Original Message-----
From: Jacob Kjome [mailto:hoju@visi.com]
Sent: Saturday, April 24, 2004 1:55 PM
To: Ant Users List
Subject: ant2html with support for macrodef? (was... RE: Article: Use
Jython to Write Ant Tasks)


At 09:55 AM 4/24/2004 -0700, you wrote:
>For the documentation I got a copy of ant2html
>but found it did not list the macrodefs and left out all comments in the
>code.  I added
>this to ant2html and it now produces more of what I want for
>documentation.  I think there
>is more that can be done to add links and other documentation information
>to Ant but it
>can come later.  The xsl file was fairly easy to modify and I may try some
>more
>modifications later when I have more time.
>
>Thanks.  Bill

Mind providing your modified ant2html?  I take it you mean the one from
here, right..
http://www-106.ibm.com/developerworks/xml/library/x-antxsl/


I tried that out and I found it to basically work, except that the
indentation done using &nbsp; entities ended up showing up literally in the
transformed document, so I saw a ton of "&nbsp;" (at least as transformed
by Mozilla).  I'm not a super-whiz with XSLT, so I'm not sure how to get
rid of them.  If your version accounts for <macrodef>, <scriptdef>, and
other things, that would be very useful to me and, I'm sure, others as well.


Jake


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


ant2html with support for macrodef? (was... RE: Article: Use Jython to Write Ant Tasks)

Posted by Jacob Kjome <ho...@visi.com>.
At 09:55 AM 4/24/2004 -0700, you wrote:
>For the documentation I got a copy of ant2html
>but found it did not list the macrodefs and left out all comments in the 
>code.  I added
>this to ant2html and it now produces more of what I want for 
>documentation.  I think there
>is more that can be done to add links and other documentation information 
>to Ant but it
>can come later.  The xsl file was fairly easy to modify and I may try some 
>more
>modifications later when I have more time.
>
>Thanks.  Bill

Mind providing your modified ant2html?  I take it you mean the one from 
here, right..
http://www-106.ibm.com/developerworks/xml/library/x-antxsl/


I tried that out and I found it to basically work, except that the 
indentation done using &nbsp; entities ended up showing up literally in the 
transformed document, so I saw a ton of "&nbsp;" (at least as transformed 
by Mozilla).  I'm not a super-whiz with XSLT, so I'm not sure how to get 
rid of them.  If your version accounts for <macrodef>, <scriptdef>, and 
other things, that would be very useful to me and, I'm sure, others as well.


Jake 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Article: Use Jython to Write Ant Tasks

Posted by Bill Rich <bi...@attglobal.net>.
I just read your article and applaud your approach to simplifying the writing of Ant tasks
although I don't understand why writing the code in jython is easier than writing the code
in Java.  But if that suits you so be it.

I also take some exception with a couple of your statements.

One statement is "Eventually, builds need to do either a lot of odd conditional logic in
the xml file and ends up burying the logic in scripts, or in a large number of custom
tasks written in java."

I am using Ant for process control rather than for just building executables.  My current
job is in localization (l10n) where I must make sure that the translatable strings in a
product are translated into whatever target language is needed.  We have designed a
process to extract the strings, prepare a Translation Request Package (TRP), send the TRP
out for translation, resurrect the appropriate files with the translated strings, and
build a localized product for testing.  In the process we use many tools written in-house
and purchased.  We use Ant to control when to run any of the tools that have a command
line interface (unfortunately some of the tools we use do not have a command line
interface so we are forced to deal with them separately).  We deal with many different
types of files such as Java LRB and PRB, MC, RC, HTML, JSP, and XML.  The process is
driven from a list of files maintained in an XML file.  Each file is described by its
type, source file name, and a target file name pattern.  I have been working with Ant for
about 6 weeks now and have the process control working pretty well.  I have written many
Ant targets, 5 macrodefs, and separated the pieces in 4 XML files that are imported as
needed.  I wrote 2 Ant tasks and abandoned them in favor of using pure Ant.  I also use
ant-contrib to help with logic control.  I have tried to keep the Ant code down to as
simple as possible but I have not succeeded in many cases because of my lack of
understanding of all the elements of Ant.  I am still learning and adjusting as I go.  The
process requires the repeated application of tools over the list of files and the
gathering and merging of some of the output files into a more manageable list of files.  I
use <if> and <for> a lot to control logic and I use the <macrodef> to make sure the tasks
are consistent where needed.  I think we will try to integrate the product build into the
process soon but this is more complex since each product has its own build environment and
Ant files.  I seriously doubt that we will need any Ant tasks to complete the process
control work we are doing.

Another statement is "One of the strengths that Make always had was the ability to easily
call scripts and command utilities. This is something that is definitely possible with Ant
script/exec tasks, but it feels very un-java. What we need is an elegant way to add adhoc
behaviour to Ant builds ... in a java-ish way."

In my opinion it is not a good thing to try to make Ant like anything else.  Ant is what
Ant is and Ant feels like Ant.  Ant is not Java and should not be forced to look or feel
like Java.  To use Ant effectively you need to step into the Ant zone and think in Ant.
If something like the use of script/exec feels un-java so what, Ant is not Java.  The
important thing is does it feel un-Ant?  My answer is no it feels like it belongs in Ant
because it was designed to be there so use it.  Also in my opinion, there is no place for
"adhoc behaviour" in Ant or any other programming language.  All behavior should be
planned and carefully integrated into the system.  From Java up to the theory of Object
Oriented programming there is no place for adhoc behavior.  All objects have well defined
behavior and they stay within the confines of their spec.  If a new behavior is needed
then the spec is changed first or a new object is defined.  So if you need a new behavior
in a build, understand what it is you need then see if Ant or an already available
extension to Ant can provide it.  Then if no task is available you can decide to make the
Ant task to extend Ant.

Now a few random thoughts of my own on Ant.  I am very pleased with Ant and how easy it
has been for me to get into the Ant zone and begin understanding how to use Ant.  The
documentation is good, although there could be some better examples in a few places.  Eric
Hatcher's book is also very good but it is out of date now.  It helps to give the basic
understanding of the philosophy of Ant and how to think in Ant.  I have found that Ant is
easy to write and I found a documentation tool that worked pretty well once I tailored it
a little to get more information out of it.  To help myself in writing Ant code I created
a small clip file for use in TextPad so I can click on the construct name I want and a
model of the code is inserted in the file.  For the documentation I got a copy of ant2html
but found it did not list the macrodefs and left out all comments in the code.  I added
this to ant2html and it now produces more of what I want for documentation.  I think there
is more that can be done to add links and other documentation information to Ant but it
can come later.  The xsl file was fairly easy to modify and I may try some more
modifications later when I have more time.

Thanks.  Bill

Bill Rich
Wilandra Consulting LLC
1325 Addiewell Place
San Jose, CA  95120-3905
phone:      +1 408 268-2452
mobile:     +1 408 410-9713
Santa Cruz: +1 831 464-9007
fax:        +1 413 669-9716
billrich@wilandra.com or billrich@attglobal.net
http://www.wilandra.com


-----Original Message-----
From: Ed Taekema [mailto:etaekema@earthlink.net]
Sent: Friday, April 23, 2004 8:27 PM
To: user@ant.apache.org
Subject: Article: Use Jython to Write Ant Tasks


I've written a guide to writing Ant tasks using Jython:  how to add scripted behaviour
to ant builds. It details the steps to write a custom Ant task in jython, compile
it and install it into ant so it can be used as any other task in an ant build.
The article also takes a quick look at an alternate implementation using Groovy.

And ... here is the url:  http://www.pycs.net/users/0000177/stories/11.html .

Enjoy,

Ed Taekema
Toronto, Canada

---------------------------------------------------------------------
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