File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Wrapping an existing core Ant task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Wrapping an existing core Ant task" Watch "Wrapping an existing core Ant task" New topic
Author

Wrapping an existing core Ant task

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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:



Tony Morris
Java Q&A (FAQ, Trivia)
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
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
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Yes, you should do it everytime in execute().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapping an existing core Ant task