There is a preference that tells Eclipse to poll the file system looking for changes (Windows->Preferences expand General, click on workspace -> "Refresh using native hooks or polling". I have a plugin that uses the startup extension point so that it starts when the workspace starts - in the earlyStartup method I am attempting to overwrite this parameter with the following code (have tried both ways InstanceScope and ConfigurationScope):
The purpose is so that a resource change listener I configure later gets notified if files under a project get modified externally. It does not appear to be working however... if I go into the preferences window the option is not checked - if I check it and hit apply and then modify a file externally my resource change listener does fire.
This isn't really a JDT question. The problem is very likely that
you're just doing it too early. At some point, Eclipse will read the
stored preferences and that's likely to overwrite what you're setting
early, i.e, what you're setting before those preferences are read.
On 09/09/2013 3:38 PM, Kevin Regan wrote:
> There is a preference that tells Eclipse to poll the file system
> looking for changes (Windows->Preferences expand General, click on
> workspace -> "Refresh using native hooks or polling". I have a
> plugin that uses the startup extension point so that it starts when
> the workspace starts - in the earlyStartup method I am attempting to
> overwrite this parameter with the following code (have tried both ways
> InstanceScope and ConfigurationScope):
>
>
> //IEclipsePreferences prefs =
> InstanceScope.INSTANCE.getNode(PLUGIN_ID);
> IEclipsePreferences prefs =
> ConfigurationScope.INSTANCE.getNode(PLUGIN_ID);
> prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
>
> try {
> prefs.flush();
> } catch (BackingStoreException e2) {
> // TODO Auto-generated catch block
> e2.printStackTrace();
> }
>
>
> The purpose is so that a resource change listener I configure later
> gets notified if files under a project get modified externally. It
> does not appear to be working however... if I go into the preferences
> window the option is not checked - if I check it and hit apply and
> then modify a file externally my resource change listener does fire.
> How to I properly set this preference?
I don't doing it to early is the problem... I think the problem is that I'm trying to modify a core eclipse preference but the way I'm doing it is just modifying it for my plugin's "node" and the actual service in eclipse that does the resource polling is not looking at my plugin's preference but the "core" one.
Basically, I got it to work by changing the node I'm getting from the preferences to the org.eclipse.core.resources one like this:
What I'm worried about is whether this is OK. I'm finding that this setting gets persisted to the workspace preferences so if I run a completely separate plugin using that workspace the setting is still disabled. I intended to set this preference just for this one run of my plugin. I feel like I may be doing something wrong here but I'm not sure what the correct approach is.
Please let me know also if this is in the wrong forum and I will move it (I think I already have a similar thread in the plugin forum but it's a bit different).
Sorry, I didn't look closely at your code. It's just a similar issue to
a tool I've been working on to manage preferences as part of an
automated installation processes...
Definitely this preference is a global workspace-specific one that's
persisted in the workspace and I would expect the code that depends on
that setting to only look at that preference node. It's also generally
not a great idea to have a plugin override/change user preferences.
Perhaps it could record the old value and on shutdown restore that old
value...
This kind of question would be appropriate for the eclipse.platform forum.
On 09/09/2013 10:06 PM, Kevin Regan wrote:
> I don't doing it to early is the problem... I think the problem is
> that I'm trying to modify a core eclipse preference but the way I'm
> doing it is just modifying it for my plugin's "node" and the actual
> service in eclipse that does the resource polling is not looking at my
> plugin's preference but the "core" one.
> Basically, I got it to work by changing the node I'm getting from the
> preferences to the org.eclipse.core.resources one like this:
>
>
>
> IEclipsePreferences prefs =
> InstanceScope.INSTANCE.getNode("org.eclipse.core.resources");
> prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
>
>
>
> What I'm worried about is whether this is OK. I'm finding that this
> setting gets persisted to the workspace preferences so if I run a
> completely separate plugin using that workspace the setting is still
> disabled. I intended to set this preference just for this one run of
> my plugin. I feel like I may be doing something wrong here but I'm
> not sure what the correct approach is.
> Please let me know also if this is in the wrong forum and I will move
> it (I think I already have a similar thread in the plugin forum but
> it's a bit different).
Thanks Ed, I am arriving at the conclusion that it is probably not a good idea for my plugin to rely on the value of a core workspace, non-plugin specific preference, as the users of the plugin can simply change it and cause the plugin to break... Unfortunately, I was hoping to leverage the resource listener functionality to monitor a file that can be externally modified that I need to keep track of but it seems like a safer bet for me to do this in a homegrown fashion considering the way it works now. Thanks for your input.