• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Wrapping an existing core Ant task

 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Yes, you should do it everytime in execute().
 
All of the following truths are shameless lies. But what about this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic