ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: AW: AW: Task adapter
Date Tue, 16 May 2006 11:05:11 GMT
Jan.Materne@rzf.fin-nrw.de wrote:
>>> If you call the tasks methods directly it behaves just a normal java 
>>> class.
>>> Ant doesnt do any dependency injection ...
>> It does one, setProject().
> 
> 
> Mmh - really?
> 
> MyTask1 extends Task {

	
>     MyTask2 t = new MyTask2();   //  t.getProject() ???
> }
> 
  MyTask2 extends Task {}

what happens when mytask2 calls log() in its execute method if you 
*dont* call setProject(0

(pause.)

OK. its no longer fatal to try and log if there isnt a project. As long 
as you dont assume that getProject() never returns null elsewhere (which 
I tend to do in my code)

     public void log(String msg, int msgLevel) {
         if (getProject() != null) {
             getProject().log(msg, msgLevel);
         } else {
             // 'reasonable' default, if the component is used without
             // a Project ( for example as a standalone Bean ).
             // Most ant components can be used this way.
             if (msgLevel <= Project.MSG_INFO) {
                 System.err.println(msg);
             }
         }
     }





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message