You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Conor MacNeill <co...@cortexebusiness.com.au> on 2000/08/10 01:03:56 UTC
using project.createTask bad?
As has been pointed out on the ant-user list, the practice of using
project.createTask("taskx") and then casting it to the desired task type is
not really desirable. All you can rely on is that project will give you a
class that implements the Task interface. Since the mapping of task names to
classes can be changed you can't assume anything more.
This pattern has been used a lot. I think we should change it. If you want a
particular class, then I think it would be better to create an instance of
that class and avoid the cast. We should reorganize the methods in the
Project class a little so that Tasks can be created outside the project and
then initialised in a consistent manner. This would involve splitting out an
initTask method from the current createTask method.
I will go ahead with this change unless someone objects.
Thoughts?
--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au
Re: using project.createTask bad?
Posted by Peter Donald <do...@mad.scientist.com>.
At 09:03 10/8/00 +1000, you wrote:
>I will go ahead with this change unless someone objects.
>
>Thoughts?
One thing to think about before you do so is the proposal of a while ago of
allowing multiple Javacs. ie like JikesJavac, ClassicJavac and ModernJavac
all extending Javac (an abstract class). The mapping was done via
properties/etc - so if this was to go ahead it would mean each task would
have to know what munging to do.
A solution would be to go
project.createTask( org.apache.tools.ant.taskdefs.Javac.class )
This would return the create an instance of first sub-class of javac
registered ... thoughts ??? Either way I don't mind how it goes.
Cheers,
Pete
*------------------------------------------------------*
| "Nearly all men can stand adversity, but if you want |
| to test a man's character, give him power." |
| -Abraham Lincoln |
*------------------------------------------------------*