ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Simon <>
Subject Ant scripting with Jython (Phase 2)
Date Fri, 20 Jun 2003 14:48:53 GMT

First off, Special thanks to Peter Reilly for his last post. Im still
relatively new to Jython (and Ant dev for that matter!) so his last code
snippet got me thinking in the right direction about the extreme reflection in

Allright. So I took Peter's code and tried to mimic the Ant Main() as much as
possible. This consisted of creating and configuring a project and logging.
Additionally, I changed the the reflection to use the Ant introspector to
create and configure the tasks. This means that instead of having a line like
this (Notice the destFile is case sensitive and the actual object
being instantiated)


you can write this (notice that destfile is NOT case sensitive due to the use
of the introspector. Also, notice that you can pass in a simple string instead
of a instance)


So here is the Jython code (all of it) to get this all working: 


from import File
from import *
from import *
from java.lang import *
from java.util import Locale
from import *

class _Method:
  def __init__(self, name, project): = name
    self.project = project
  def __call__(self, **args):
    target = self.project.createTask(
    ih = IntrospectionHelper.getHelper(target.class)
    ph = ProjectHelper()
    for a in args.keys():
        value = ph.replaceProperties(self.project,

class Ant:
  myProject = Project()
  myProject.setUserProperty("ant.version", Main.getAntVersion());
  logger = DefaultLogger()
  logger.outputPrintStream = System.out
  logger.errorPrintStream = System.out
  logger.messageOutputLevel = 3
  def __getattr__(self, name):
    return _Method(name, self.myProject)
  def setLogLevel(logLevel):
    self.logger.messageOutputLevel = logLevel


Here are the outstading issues that I would like some feedback on. 

1) Sub-elements. I know that we need them. Just not sure how to do it. I am
having more trouble figuring out the introspector works with the subelements
than with the attributes ;-( If the introspectionworks, then you can just pass
a fileset instance in along with the otehr attributes. 

2) Properties. Properties are still good to have in XML. I want to take a look
at the best way to be able to reference XML property file from the Jython

So there you go. Any suggestions or comments? Give a shout!



Jonathan Simon
Home - 732.777.0377  <----------- New!!!
Work - 646.674.2060
Cell - 732.718.8844
Music -

Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message