You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Thomas SMETS <sm...@yahoo.com> on 2005/10/14 00:19:36 UTC
invoking the logger in the constructor
dear,
I create a simple task as indicated in the ANT book : "Ant: The Definitive Guide", Second Edition
from O'Reilly. Something like
import java.io.IOException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.types.Commandline;
public class MyCustomTask extends Task
{
public MyCustomTask ()
{
System.out.println("Instanciated");
}
public void init()
{
System.out.println("initialized");
}
public void execute()
{
System.out.println("executed");
}
}
The funny thing is that the init seems to be called twice ... ANT-version is either 1.6.2 & 1.6.5
and invoking the log-methode in the constructor throws a NullPOinterException. Any idea about
those ... ?
\T,
--
Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.
Martin Fowler
T. : +32 (0)2 742 05 94
M. : +32 (0)497 44 68 12
@ : duvelbier-tsmets@yahoo.com
Do you skype too ... ?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: invoking the logger in the constructor
Posted by du...@yahoo.com.
The reason seem to be (but I haven't been able to confirm as I have been busy in other matters)
that the Task has a default constructor (that I use). To use the 'log()' method, I'd need to
invoke a constructor with the node name I want to use.
Smthg like :
<snip>
class MyTask extends Task
{
public MyTask()
{
super("com.cpy_name.pckg.MyTask");
}
...
}
</snip>
If that is the case, the constructor could use the following definition :
logger = Logger.getLogger(this.getClass());
\T,
--- Steve Loughran <st...@apache.org> wrote:
> Thomas SMETS wrote:
> > dear,
> > I create a simple task as indicated in the ANT book : "Ant: The Definitive Guide", Second
> Edition
> > from O'Reilly. Something like
> >
> > import java.io.IOException;
> > import org.apache.tools.ant.Task;
> > import org.apache.tools.ant.taskdefs.Execute;
> > import org.apache.tools.ant.types.Commandline;
> >
> > public class MyCustomTask extends Task
> > {
> > public MyCustomTask ()
> > {
> > System.out.println("Instanciated");
> > }
> >
> > public void init()
> > {
> > System.out.println("initialized");
> > }
> >
> > public void execute()
> > {
> > System.out.println("executed");
> > }
> > }
> >
> > The funny thing is that the init seems to be called twice ... ANT-version is either 1.6.2 &
> 1.6.5
> > and invoking the log-methode in the constructor throws a NullPOinterException. Any idea about
> > those ... ?
>
> I think the double-init was a regression in ant that will be fixed in
> the next release.
>
> regarding the exception in the constructor; send a stack trace.
>
>
> Ant tasks normally use the log() operations, with different levels of
> verbosity
>
> log("your files have been deleted",Project.MSG_VERBOSE);
> log("unstable condition in the antimatter core",Project.MSG_ERROR);
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
--
Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.
Martin Fowler
T. : +32 (0)2 742 05 94
M. : +32 (0)497 44 68 12
@ : duvelbier-tsmets@yahoo.com
Do you skype too ... ?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: invoking the logger in the constructor
Posted by Steve Loughran <st...@apache.org>.
Thomas SMETS wrote:
> dear,
> I create a simple task as indicated in the ANT book : "Ant: The Definitive Guide", Second Edition
> from O'Reilly. Something like
>
> import java.io.IOException;
> import org.apache.tools.ant.Task;
> import org.apache.tools.ant.taskdefs.Execute;
> import org.apache.tools.ant.types.Commandline;
>
> public class MyCustomTask extends Task
> {
> public MyCustomTask ()
> {
> System.out.println("Instanciated");
> }
>
> public void init()
> {
> System.out.println("initialized");
> }
>
> public void execute()
> {
> System.out.println("executed");
> }
> }
>
> The funny thing is that the init seems to be called twice ... ANT-version is either 1.6.2 & 1.6.5
> and invoking the log-methode in the constructor throws a NullPOinterException. Any idea about
> those ... ?
I think the double-init was a regression in ant that will be fixed in
the next release.
regarding the exception in the constructor; send a stack trace.
Ant tasks normally use the log() operations, with different levels of
verbosity
log("your files have been deleted",Project.MSG_VERBOSE);
log("unstable condition in the antimatter core",Project.MSG_ERROR);
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org