Re: com3205:HW6


Subject: Re: com3205:HW6
From: Kojarski Sergei (kojarski@ccs.neu.edu)
Date: Thu Nov 21 2002 - 14:19:37 EST


Hi Myra,

I did all this stuff and it works (!!!)
Brief How To:
1. You need to implement org.eclipse.debug.core.IDebugEventSetListener
interface. Lets say, you have a class
class DebugEventSetListener implements IDebugEventSetListener {
...
  public void handleDebugEvents(DebugEvent[] events) {
    ...your code...
  }
}

2. In your view (I believe, in createControl method, when your view
starts) you just say:
      DebugPlugin dpl = DebugPlugin.getDefault();
      DebugEventSetListener del = new DebugEventSetListener();
      dpl.addDebugEventListener(del);
3. Inside
  public void handleDebugEvents(DebugEvent[] events) {
    ...your code...
  }
  now you receive all the notifications about creation/termination of the
processes/threads/blah blah blah.
  We are interested in the processes. So, we can say:
  (I'll talk about StreamListener further)

  private StreamListener errorStreamListener;
  private StreamListener outStreamListener;
  private IProcess checkingProcess;

  public void handleDebugEvents(DebugEvent[] events) {
    if (events==null) return;
    for (int i=0;i<events.length;i++) {
      if (events[i].getSource() instanceof IProcess) {
          IProcess process = (IProcess)events[i].getSource();

          if (events[i].getKind()==DebugEvent.CREATE &&
compilerProcess==null) {
              checkingProcess=process;
              //That's how we add stream listeners to the streams
              outStreamListener = new StreamListener();
              errorStreamListener = new StreamListener();

checkingProcess.getStreamsProxy().getErrorStreamMonitor().addListener(errorStreamListener);

checkingProcess.getStreamsProxy().getOutputStreamMonitor().addListener(outStreamListener);
          }

          if (events[i].getKind()==DebugEvent.TERMINATE &&
process==checkingProcess) {

          //That's how we remove listeners from the streams
checkingProcess.getStreamsProxy().getErrorStreamMonitor().removeListener(errorStreamListener);

checkingProcess.getStreamsProxy().getOutputStreamMonitor().removeListener(outStreamListener);
              compilerProcess=null;
          }
      }
    }
  }

Now stream listeners listen for all the processes in the running
applications.
STreamListener is the implementstion of
org.eclipse.debug.core.IStreamListener interface:
class StreamListener implements IStreamListener {

  private StringBuffer content = new StringBuffer();
  public void streamAppended(String text, IStreamMonitor monitor) {
     content.append(text);
  }
  public String getStreamContent(){
    return content.toString();
  }
}

Of course, you can do more complicated things inside streamAppended
method. There you can also update your view with new records blah blah
blah.

Now, how to find out what project we listens?
Ok, we can do this:
1. Add ILaunch field into StreamListener class
2. Write constructor for StreamListener in the form:

  ILaunch launch;
  StreamListener (ILaunch launch) {
    this.launch=launch;
  }

3. Now we need to create our listeners not just by saying:
              checkingProcess=process;
              //That's how we add stream listeners to the streams
              outStreamListener = new StreamListener();
              errorStreamListener = new StreamListener();
   BUT by saying:
              checkingProcess=process;
              //That's how we add stream listeners to the streams
              outStreamListener = new
StreamListener(checkingProcess.getLaunch());
              errorStreamListener = new
StreamListener(checkingProcess.getLaunch());

Ok, and right now inside StreamListener's method we can say:
  public void streamAppended(String text, IStreamMonitor monitor) {
    try{
     String projectName =
launch.getLaunchConfiguration().getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,"");
     .....parsing text .....................
     .....change your view appropriately....

    } catch (Exception e)
  }

Smth like this.

Hope it'll help!

Sergei.

On Thu, 21 Nov 2002, Myra Colina B. Dideles wrote:

> hi sergei,
>
> i don't see how you can get an IProcess object with a listener. i defined
> a data member debugListener inside my view class and then registered that
> as a DebugEventListener. was that what you meant by 'register your view
> as DebugEventListener'? the only method i can see that will return an
> IProcess is the newProcess(ILaunch l, Process p, String s) method. we
> don't want to start a new process, do we?
>
> thanks for your help,
> myra
>
> On Tue, 19 Nov 2002, Kojarski Sergei wrote:
>
> >
> > Actually, it's not necessary to include "project name" information into
> > checker. We can obtain project name from:
> > IProcess.getLaunch().getLaunchConfiguration().getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,"")
> > and it'll return as project name.
> >
> > Sergei.
> >
> > On Tue, 19 Nov 2002, Kojarski Sergei wrote:
> >
> > >
> > > Hi Jeff,
> > >
> > > I suppose that we can build communication between checker and Eclipse by
> > > using sockets. But, you know, it's not the best (though) solution.
> > > The other way to orginize communication is (I HAVEN'T CHECKED IT!!!!
> > > TRY!!! IT SHOULD WORK!!!):
> > >
> > > 1. Register your view as DebugEventListener
> > > (see org.eclipse.debug.core.DebugPlugin docs)
> > > Using this listener you'll be able to get source object that
> > > describes running application. You are interested in IProcess objects.
> > > (org.eclipse.debug.core.model.IProcess)
> > >
> > > 2. You can add output/error stream listeners to this IProcess
> > > (smth like
> > > IProcess.getStreamsProxy().getOutputStreamMonitor().addListener(IStreamListener
> > > listener) )
> > >
> > > 3. In your checker print lines in some format, so you can understand in
> > > your plugin what line is being printed to the stream by checker.
> > >
> > > 4. To find out what (running) project actually complaining you need to
> > > extend format of messages with the name of the project. You can do it by
> > > rewriting checker code on copying, just like you do with GlobalPreffered
> > > or Stable pointcuts. SO, your checker will complain errors, that contains
> > > project name, plugin intercepts those messages, decides, whether it should
> > > be reflected in the view or not etc.
> > >
> > > As you can understand, this way is not trivial, but I suspect it's the
> > > best one.
> > >
> > > To find out more about views / Viewer models just take a look at the
> > > http://www.ccs.neu.edu/home/lieber/com3205/f02/eclipse/src/
> > > folder. It contains an example I presented in the class.
> > > I believe, it's helpful.
> > >
> > > Good luck,
> > > Sergei.
>



This archive was generated by hypermail 2b28 : Thu Nov 21 2002 - 14:19:40 EST