Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Listening to classpath changes
Listening to classpath changes [message #50909] Thu, 05 June 2003 15:43 Go to next message
Eclipse UserFriend
Originally posted by: creis.rice.edu

I'm working on a plugin that needs to react whenever an entry is added
to a project's classpath. So far, it looks like I need to add an
IElementChangedListener to JavaCore, and then look through the
IJavaElementDelta to see if it contains a change to the classpath. (This
appears to require traversing the entire tree of deltas for *every* change
that comes in, which seems inefficient. Is there a better way?)

Here's how I'm adding the listener:

JavaCore.addElementChangedListener(new IElementChangedListener() {
public void elementChanged(ElementChangedEvent e) {
IJavaElementDelta delta = e.getDelta();
visitDelta(delta);
}
}

The real problem I'm running into is that additions to the classpath
don't appear to be flagged how they should be. If I remove something from
a project classpath, I get a delta with a F_REMOVED_FROM_CLASSPATH flag.
If I add something to a project classpath, the corresponding delta *does
not* have the F_ADDED_TO_CLASSPATH flag, even though the documentation
says it will. It only has type ADDED instead of type CHANGED. (This is
in Eclipse 2.1, Linux Motif.) As a result, I can't figure out how to
differentiate between adding classpath entries and any other ADDED delta,
such as adding a new file...

Has anyone else seen this? Should I go ahead and submit it as a bug?
Is there a workaround, or a better way to listen for changes to the
classpath?

Thanks in advance,
Charlie
Re: Listening to classpath changes [message #51513 is a reply to message #50909] Fri, 06 June 2003 05:45 Go to previous messageGo to next message
Eclipse UserFriend
Charlie,

Yes traversing the delta tree is the only way. However you don't need to go
deeper than the 3rd level (for IPackageFragmentRoot deltas).

As you said, when adding an entry on the classpath, the corresponding
IPackageFragmentRoot delta should be of kind CHANGED with a
F_ADDED_TO_CLASSPATH flag. However if the corresponding resource (a folder
of a jar file) didn't exist and it is added in the same operation, then the
kind of the delta will be ADDED.

If this is not the case, please enter a bug report against JDT/Core with
steps to reproduce the problem.

Jerome

"Charles Reis" <creis@rice.edu> wrote in message
news:bbo6gl$kru$1@rogue.oti.com...
> I'm working on a plugin that needs to react whenever an entry is added
> to a project's classpath. So far, it looks like I need to add an
> IElementChangedListener to JavaCore, and then look through the
> IJavaElementDelta to see if it contains a change to the classpath. (This
> appears to require traversing the entire tree of deltas for *every* change
> that comes in, which seems inefficient. Is there a better way?)
>
> Here's how I'm adding the listener:
>
> JavaCore.addElementChangedListener(new IElementChangedListener() {
> public void elementChanged(ElementChangedEvent e) {
> IJavaElementDelta delta = e.getDelta();
> visitDelta(delta);
> }
> }
>
> The real problem I'm running into is that additions to the classpath
> don't appear to be flagged how they should be. If I remove something from
> a project classpath, I get a delta with a F_REMOVED_FROM_CLASSPATH flag.
> If I add something to a project classpath, the corresponding delta *does
> not* have the F_ADDED_TO_CLASSPATH flag, even though the documentation
> says it will. It only has type ADDED instead of type CHANGED. (This is
> in Eclipse 2.1, Linux Motif.) As a result, I can't figure out how to
> differentiate between adding classpath entries and any other ADDED delta,
> such as adding a new file...
>
> Has anyone else seen this? Should I go ahead and submit it as a bug?
> Is there a workaround, or a better way to listen for changes to the
> classpath?
>
> Thanks in advance,
> Charlie
>
Re: Listening to classpath changes [message #51539 is a reply to message #50909] Fri, 06 June 2003 06:11 Go to previous messageGo to next message
Eclipse UserFriend
You should only need to traverse down to package fragment roots which are
mapping to classpath entries. It is pointless to traverse the delta further.
Now on the surface, the flag seems inconsistent, please enter a defect and
we will investigate it (provide build number, steps etc...).

"Charles Reis" <creis@rice.edu> wrote in message
news:bbo6gl$kru$1@rogue.oti.com...
> I'm working on a plugin that needs to react whenever an entry is added
> to a project's classpath. So far, it looks like I need to add an
> IElementChangedListener to JavaCore, and then look through the
> IJavaElementDelta to see if it contains a change to the classpath. (This
> appears to require traversing the entire tree of deltas for *every* change
> that comes in, which seems inefficient. Is there a better way?)
>
> Here's how I'm adding the listener:
>
> JavaCore.addElementChangedListener(new IElementChangedListener() {
> public void elementChanged(ElementChangedEvent e) {
> IJavaElementDelta delta = e.getDelta();
> visitDelta(delta);
> }
> }
>
> The real problem I'm running into is that additions to the classpath
> don't appear to be flagged how they should be. If I remove something from
> a project classpath, I get a delta with a F_REMOVED_FROM_CLASSPATH flag.
> If I add something to a project classpath, the corresponding delta *does
> not* have the F_ADDED_TO_CLASSPATH flag, even though the documentation
> says it will. It only has type ADDED instead of type CHANGED. (This is
> in Eclipse 2.1, Linux Motif.) As a result, I can't figure out how to
> differentiate between adding classpath entries and any other ADDED delta,
> such as adding a new file...
>
> Has anyone else seen this? Should I go ahead and submit it as a bug?
> Is there a workaround, or a better way to listen for changes to the
> classpath?
>
> Thanks in advance,
> Charlie
>
Re: Listening to classpath changes [message #51631 is a reply to message #51513] Fri, 06 June 2003 10:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: creis.rice.edu

Thanks--
It is the case that a new resource (an external jar file) is being added
to the classpath, so according to your email, the delta should be of kind
ADDED. However, how can I distinguish between that case and any other
ADDED event, such as a new file? Is checking whether it is a
IPackageFragmentRoot sufficient to identify an added classpath
entry/resource? If not, what would you recommend?

Thanks for your help,
Charlie


Jerome Lanneluc wrote:

> Charlie,

> Yes traversing the delta tree is the only way. However you don't need to go
> deeper than the 3rd level (for IPackageFragmentRoot deltas).

> As you said, when adding an entry on the classpath, the corresponding
> IPackageFragmentRoot delta should be of kind CHANGED with a
> F_ADDED_TO_CLASSPATH flag. However if the corresponding resource (a folder
> of a jar file) didn't exist and it is added in the same operation, then the
> kind of the delta will be ADDED.

> If this is not the case, please enter a bug report against JDT/Core with
> steps to reproduce the problem.

> Jerome

> "Charles Reis" <creis@rice.edu> wrote in message
> news:bbo6gl$kru$1@rogue.oti.com...
> > I'm working on a plugin that needs to react whenever an entry is added
> > to a project's classpath. So far, it looks like I need to add an
> > IElementChangedListener to JavaCore, and then look through the
> > IJavaElementDelta to see if it contains a change to the classpath. (This
> > appears to require traversing the entire tree of deltas for *every* change
> > that comes in, which seems inefficient. Is there a better way?)
> >
> > Here's how I'm adding the listener:
> >
> > JavaCore.addElementChangedListener(new IElementChangedListener() {
> > public void elementChanged(ElementChangedEvent e) {
> > IJavaElementDelta delta = e.getDelta();
> > visitDelta(delta);
> > }
> > }
> >
> > The real problem I'm running into is that additions to the classpath
> > don't appear to be flagged how they should be. If I remove something from
> > a project classpath, I get a delta with a F_REMOVED_FROM_CLASSPATH flag.
> > If I add something to a project classpath, the corresponding delta *does
> > not* have the F_ADDED_TO_CLASSPATH flag, even though the documentation
> > says it will. It only has type ADDED instead of type CHANGED. (This is
> > in Eclipse 2.1, Linux Motif.) As a result, I can't figure out how to
> > differentiate between adding classpath entries and any other ADDED delta,
> > such as adding a new file...
> >
> > Has anyone else seen this? Should I go ahead and submit it as a bug?
> > Is there a workaround, or a better way to listen for changes to the
> > classpath?
> >
> > Thanks in advance,
> > Charlie
> >
Re: Listening to classpath changes [message #51847 is a reply to message #51631] Fri, 06 June 2003 12:28 Go to previous message
Eclipse UserFriend
Yes, checking whether it is a IPackageFragmentRoot would be sufficient.

Jerome

"Charles Reis" <creis@rice.edu> wrote in message
news:bbq842$7sm$1@rogue.oti.com...
> Thanks--
> It is the case that a new resource (an external jar file) is being added
> to the classpath, so according to your email, the delta should be of kind
> ADDED. However, how can I distinguish between that case and any other
> ADDED event, such as a new file? Is checking whether it is a
> IPackageFragmentRoot sufficient to identify an added classpath
> entry/resource? If not, what would you recommend?
>
> Thanks for your help,
> Charlie
>
>
> Jerome Lanneluc wrote:
>
> > Charlie,
>
> > Yes traversing the delta tree is the only way. However you don't need to
go
> > deeper than the 3rd level (for IPackageFragmentRoot deltas).
>
> > As you said, when adding an entry on the classpath, the corresponding
> > IPackageFragmentRoot delta should be of kind CHANGED with a
> > F_ADDED_TO_CLASSPATH flag. However if the corresponding resource (a
folder
> > of a jar file) didn't exist and it is added in the same operation, then
the
> > kind of the delta will be ADDED.
>
> > If this is not the case, please enter a bug report against JDT/Core with
> > steps to reproduce the problem.
>
> > Jerome
>
> > "Charles Reis" <creis@rice.edu> wrote in message
> > news:bbo6gl$kru$1@rogue.oti.com...
> > > I'm working on a plugin that needs to react whenever an entry is
added
> > > to a project's classpath. So far, it looks like I need to add an
> > > IElementChangedListener to JavaCore, and then look through the
> > > IJavaElementDelta to see if it contains a change to the classpath.
(This
> > > appears to require traversing the entire tree of deltas for *every*
change
> > > that comes in, which seems inefficient. Is there a better way?)
> > >
> > > Here's how I'm adding the listener:
> > >
> > > JavaCore.addElementChangedListener(new IElementChangedListener() {
> > > public void elementChanged(ElementChangedEvent e) {
> > > IJavaElementDelta delta = e.getDelta();
> > > visitDelta(delta);
> > > }
> > > }
> > >
> > > The real problem I'm running into is that additions to the classpath
> > > don't appear to be flagged how they should be. If I remove something
from
> > > a project classpath, I get a delta with a F_REMOVED_FROM_CLASSPATH
flag.
> > > If I add something to a project classpath, the corresponding delta
*does
> > > not* have the F_ADDED_TO_CLASSPATH flag, even though the documentation
> > > says it will. It only has type ADDED instead of type CHANGED. (This
is
> > > in Eclipse 2.1, Linux Motif.) As a result, I can't figure out how to
> > > differentiate between adding classpath entries and any other ADDED
delta,
> > > such as adding a new file...
> > >
> > > Has anyone else seen this? Should I go ahead and submit it as a
bug?
> > > Is there a workaround, or a better way to listen for changes to the
> > > classpath?
> > >
> > > Thanks in advance,
> > > Charlie
> > >
>
>
>
>
>
Previous Topic:No more handles
Next Topic:CVS checkout of non-Eclipse project gives broken tree
Goto Forum:
  


Current Time: Sun May 11 22:07:15 EDT 2025

Powered by FUDForum. Page generated in 0.05069 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top