Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Custom MessageHandler for static pointcuts

Hi Wes,

I appreciate your help.  I copied your code below, but still see nothing (no
file generated).  Perhaps I am not using the Ant task properly.  Would you
mind posting the Ant task you used to get things sent to the file?

Thanks,
Chuck

> -----Original Message-----
> From: aspectj-users-admin@xxxxxxxxxxx
> [mailto:aspectj-users-admin@xxxxxxxxxxx]On Behalf Of Wes Isberg
> Sent: Friday, September 24, 2004 11:50 AM
> To: aspectj-users@xxxxxxxxxxx
> Subject: RE: [aspectj-users] Custom MessageHandler for static pointcuts
>
>
> Hi Chuck -
>
> I just did an experiment and found that printing to System.out
> didn't work (is Ant suppressing it?), but printing to a file did.
> My code is below.
>
> Regarding IMessageHolder, the basic contract it inherits for
> IMessageHandler.handleMessage(IMessage) is just that it's called for
> each message, so your code should gain control as mine did to write
> the message.  Whether you configure a MessageHandler you extend to
> only accumulate messages shouldn't make a difference.
>
> I hope this works for you...
> Wes
>
> ------------------ Handler.java
> import java.io.*;
> import org.aspectj.bridge.*;
>
> public class Handler extends MessageHandler {
>     public Handler() {
>         super(true);
>     }
>
>     public boolean handleMessage(IMessage m) {
>         try {
>             Writer w = null;
>             try {
>                 w = new FileWriter("output.txt", true);
>                 new PrintWriter(w).println("got " + m);
>             } finally {
>                 if (null != w)
>                     w.close();
>             }
>         } catch (IOException e) {
>             throw new Error(e);
>         }
>         return super.handleMessage(m);
>     }
> }
>
>
> > ------------Original Message------------
> > From: "Charles Daniels" <cjd4@xxxxxxxxx>
> > To: aspectj-users@xxxxxxxxxxx
> > Date: Thu, Sep-23-2004 10:10 PM
> > Subject: RE: [aspectj-users] Custom MessageHandler for static pointcuts
> >
> > Hi Wes,
> >
> > Thanks for your quick reply.  Unfortunately, I'm not forking, and I
> > still
> > can't see what is happening.  Using Maven, I added the -X option to
> > show
> > debugging output and saw that it was loading my IMessageHolder
> > implementation.  However, I still see no difference in behavior and I
> > see no
> > exception.
> >
> > Anyway, I did some digging through the source, as you suggested.  What
> > I
> > found is that perhaps IMessageHolder is not used as I suspected.  I
> > looked
> > at MessageHandler (the default IMessageHolder implementation), and it
> > only
> > accumulates messages.  I don't know where the messages actually get
> > sent to
> > output (or wherever they actually get sent -- logger/listener?).  I
> > just
> > want to be able to capture error messages from 'declare warning'
> > declarations and write them to a file that I can transform into a
> > report.
> >
> > Cheers,
> > Chuck
> >
> > > -----Original Message-----
> > > From: aspectj-users-admin@xxxxxxxxxxx
> > > [mailto:aspectj-users-admin@xxxxxxxxxxx]On Behalf Of Wes Isberg
> > > Sent: Thursday, September 23, 2004 7:13 PM
> > > To: aspectj-users@xxxxxxxxxxx
> > > Subject: Re: [aspectj-users] Custom MessageHandler for static
> > pointcuts
> > >
> > >
> > > You're probably forking; there should be a log message saying
> > > "message holder ignored when forking [...]", but perhaps Ant
> > > has to be in verbose mode for you to see the log message. It's
> > > ignored when forking because it's implemented programmatically
> > > from Ant rather than being supported on the -ajc command line
> > > (which is what's forked).
> > >
> > > The documentation for MessageHandlers is just the mention in
> > > the iajc docs and the IMessageHandler source code.  See also
> > > the code for AjcTask (iajc) and org.aspectj.tools.Ajc.
> > >
> > > Hope this helps; let us know if it's something else...
> > >
> > > Wes
> > >
> > > P.S. - If you must fork, you might consider taking the messages
> > > in XML form from Ant and selecting your messages during the
> > > transform.  (I haven't done this myself, so I'm just speculating.)
> > >
> > > > ------------Original Message------------
> > > > From: "Charles Daniels" <cjd4@xxxxxxxxx>
> > > > To: aspectj-users@xxxxxxxxxxx
> > > > Date: Thu, Sep-23-2004 1:55 PM
> > > > Subject: [aspectj-users] Custom MessageHandler for static pointcuts
> > > >
> > > > Hi All,
> > > >
> > > > I am attempting to implement my own MessageHandler for collecting
> > > > "policy
> > > > violations" detected by static pointcuts (declare warning and
> > declare
> > > > error).  I want my handler to generate an XML report that I can
> > then
> > > > transform into an HTML report.  Unfortunately, when I run iajc, it
> > > > completely ignores the handler implementation that I specify (no
> > error
> > > > message either).  I cannot find and documentation on the use of
> > > > MessageHandlers.  Can anybody shed some light on this topic?
> > > >
> > > > Thanks,
> > > > Chuck
> > > >
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > >
> > >
> > >
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top