• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Wrapping an existing core Ant task

 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am attempting to write an Ant task that wraps the org.apache.tools.ant.taskdefs.Java task.
I am having a problem in determining how it is intended by the Ant API to execute tasks manually.
For example, if I call org.apache.tools.ant.tasksdefs.Java.execute(), I receive a NullPointerException*.
Is there a standard way to invoke existing tasks through the Ant API?
Obviously the Ant framework does some setting up before calling execute(), hence the reason for the failure.
Is there an Ant API such as TaskExecuter.execute(Task)?
Assistance is most appreciated.

Please see the following test case which attempts to illustrate my objective in a trivial manner:

 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to set the project object (as you could see from the source code of Task.log).

myJavaTask.setProject(getProject());

You will also need to set the required attributes via the set*, and nested elements via the add*/create* methods.

Again, take a look at the source code - Ant is open source, after all.

A good book might also help - I'm using "Java Development with Ant" by Erik Hatcher et.al.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:
You need to set the project object (as you could see from the source code of Task.log).

myJavaTask.setProject(getProject());



Hi Ilja,

I remember that when we set the project / target is also important ?
I mean doing myJavaTask.setProject(getProject()),myJavaTask.setOwningTarget(getOwningTarget()) in the constructor probably wouldnt work since the Hello constructor does not get the Project and Target references by then?

Should they be set everytime we do a execute() or something / some other place?

may be you can verify.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you should do it everytime in execute().
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic