File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapping an existing core Ant task

 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • 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:

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • 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.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • 0
  • 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
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you should do it everytime in execute().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic