ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mr Pink <mr_pink_is_the_only_...@yahoo.com>
Subject Re: AW: custom task calls classes with logging = NPE
Date Mon, 30 Aug 2004 12:17:39 GMT
Hi Jan,

I finally figured out was was wrong. Yes, it is possible to use System.out from within an
ant task
but I had introduced a seperate problem into my code.

Perhaps you are familiar with the tutorial on writing your own task? I followed it and then
based
my development on that. In the tutorial, the first example puts this method in the task:

    private Project project;

    public void setProject(Project proj) {
        project = proj;
    }

It disappears in the next version of the example (with no explanation, or maybe I just misssed
that bit) and if you leave it in like that (as I did), you're gonna start having NPE coming
out
your ears.

Anyway, once I realized what was happening I pulled the code out and everything was working
fine.
I had already removed all refernces to System.out and loggers so it hadn't clicked with me
that
they might actually start working again. After reading your reply I tested it out and it's
working
fine.

Thanks for you help
Mr Pink

--- Jan.Materne@rzf.fin-nrw.de wrote:

> > I understand that Ant is closing the System.out and 
> > System.err streams and I can kinda appreciate
> > why it's doing that, but it's proving to be a problem for me, 
> > since my task calls various classes
> > that are not aware of ant and those classes use logging and 
> > possibly even direct references to to
> > System.out causing my task to fail with a NullPointerException.
> 
> Im not aware that Ant _closes_ these streams ...
> Ant uses its own streams:
> 
> Main.java:0621: System.setIn(new DemuxInputStream(project));
> Main.java:0622: System.setOut(new PrintStream(new DemuxOutputStream(project,
> false)));
> Main.java:0623: System.setErr(new PrintStream(new DemuxOutputStream(project,
> true)));
> 
> DemuxOutputStream:
> "Logs content written by a thread and forwards the buffers onto the
> project object which will forward the content to the appropriate task."
> 
> 
> 
> > In short, I'd like to know how one deals with that.
> 
> The usual way for logging is invoking the tasks log() method ...
> For your external classes: <java> supports a <redirector>. Maybe you can
do
> something
> with that (its early in the morning - maybe thats not the best idea...)
> 
> 
> Jan
> 



		
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush

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


Mime
View raw message