Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 264394 - Adopt the proper preferences story
Summary: Adopt the proper preferences story
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.5 M7   Edit
Assignee: Ankur Sharma CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-10 12:27 EST by Chris Aniszczyk CLA
Modified: 2009-04-13 11:07 EDT (History)
3 users (show)

See Also:
curtis.windatt.public: review+


Attachments
Work in progress - Patch 1 (53.98 KB, patch)
2009-03-28 16:34 EDT, Ankur Sharma CLA
no flags Details | Diff
Pref Story test cases (4.92 KB, patch)
2009-04-06 07:55 EDT, Ankur Sharma CLA
no flags Details | Diff
Pref fixes for o.e.pde.core (69.46 KB, patch)
2009-04-06 08:04 EDT, Ankur Sharma CLA
no flags Details | Diff
Test Case Patch (6.13 KB, patch)
2009-04-09 17:03 EDT, Ankur Sharma CLA
no flags Details | Diff
Pref Fixes for o.e.pde.core (56.01 KB, patch)
2009-04-09 17:04 EDT, Ankur Sharma CLA
no flags Details | Diff
Combine and updated patch (42.74 KB, patch)
2009-04-09 17:56 EDT, Curtis Windatt CLA
curtis.windatt.public: iplog+
Details | Diff
mylyn/context/zip (28.19 KB, application/octet-stream)
2009-04-09 17:56 EDT, Curtis Windatt CLA
no flags Details
o.e.pde.ui pref fixes (73.15 KB, patch)
2009-04-11 09:57 EDT, Ankur Sharma CLA
curtis.windatt.public: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Aniszczyk CLA 2009-02-10 12:27:07 EST
There's a lot of deprecation warnings in PDE in regards to how we use preferences.

We should review our usage and fix the deprecations to use the new preferences story.
Comment 1 Chris Aniszczyk CLA 2009-03-10 13:57:08 EDT
let's look at this in M7
Comment 2 Curtis Windatt CLA 2009-03-13 13:08:26 EDT
Ankur is going to try creating a patch.
Comment 3 Ankur Sharma CLA 2009-03-17 06:05:42 EDT
There are many classes using the old preferences. Changing them in one shot won't be right idea. How should I segregated them? Making patches per Project/package would be OK?
Comment 4 Chris Aniszczyk CLA 2009-03-17 12:26:23 EDT
small steps are fine, start with what you're comfortable with
Comment 5 Curtis Windatt CLA 2009-03-17 12:32:37 EDT
Just put up regular patches with what you've got done.  I'll try to keep up with reviewing/committing them as they come in.
Comment 6 Ankur Sharma CLA 2009-03-28 16:34:53 EDT
Created attachment 130171 [details]
Work in progress - Patch 1

Please review this patch and let me know if I am doing it right.
Comment 7 Curtis Windatt CLA 2009-03-30 12:51:11 EDT
I am still quite confused as to what the proper preferences story is, but I do see one potential problem with your work.  You are changing the preference initializer to store default values in the default scope.  However, whenever you get preferences you are only grabbing them from the instance scope and providing an explicit default value.  This means that the default value is likely being ignored (I haven't tested it).

It would be better to use the Platform preference service getString() getBoolean() etc. methods because that will check all scopes in the default order.

IPreferencesService service = Platform.getPreferencesService();
service.getString(PLUGIN_ID, prefkey, default, null);
Comment 8 Chris Aniszczyk CLA 2009-03-30 12:55:08 EDT
The proper story is the one that isn't deprecated :)
Comment 9 Curtis Windatt CLA 2009-03-30 13:10:58 EDT
(In reply to comment #8)
> The proper story is the one that isn't deprecated :)
> 

There are multiple ways to do the preferences without using deprecated code.  If we are going to change all of PDE to avoid the warnings, we want to do it right, not end up with random preferences problems throughout 3.5.x.

The preference service appears to be the proper way to access things, but other plug-ins are directly accessing the different scopes.
Comment 10 Chris Aniszczyk CLA 2009-03-30 14:16:24 EDT
One step at a time ;)

I would prefer if we would have no deprecated references by the time we ship 3.5

Since we are in the platform, we should use the IEclipsePreferences mechanism over the vanilla OSGi preferences.
Comment 11 Ankur Sharma CLA 2009-03-31 03:13:27 EDT
so whats the final decision? IPreferencesService or IEclipsePreferences ?
Comment 12 Curtis Windatt CLA 2009-03-31 09:58:00 EDT
IEclipsePreferences

But I would like to make sure that the defaults are being picked up correctly.  I will try to do some manual testing.  It would be even better if we could create a set of tests that make sure that the preferences work correctly (at the project, instance and default scopes).  i.e. have a set of known preferences and their expected default values, some which can be set per project, some which are instance only and make sure the stored preference value is correct.
Comment 13 Ankur Sharma CLA 2009-04-06 07:55:12 EDT
Created attachment 130979 [details]
Pref Story test cases

Some test cases based on the Preferences usage in PDE. Will add more as I progress.
Comment 14 Ankur Sharma CLA 2009-04-06 08:04:28 EDT
Created attachment 130980 [details]
Pref fixes for o.e.pde.core

Curtis,

I've made changes to the way I am approaching this problem. Please review this and let me know your comments/suggestions.

Thanks,
Ankur..
Comment 15 Ankur Sharma CLA 2009-04-09 17:03:06 EDT
Created attachment 131458 [details]
Test Case Patch

Added PDE specific test cases
Comment 16 Ankur Sharma CLA 2009-04-09 17:04:29 EDT
Created attachment 131459 [details]
Pref Fixes for o.e.pde.core

Switched to PDEPreferencesManager approach.
Comment 17 Curtis Windatt CLA 2009-04-09 17:56:46 EDT
Created attachment 131467 [details]
Combine and updated patch

Unfortunately I have a concern that needs to be addressed before putting this in.

The old and new preferences do not appear to be compatable.  i.e. setting preferences with the new manager does not change the values when getting from the old style preferences (and vice versa).  This is a problem for two reasons, people with existing workspaces won't have their preferences migrated, and PDE UI (and possibly others, though the code is internal) still get preferences the old way and so they will be missing values.

I added a simple test to the patch for this.  I would also like to see the PDEPreferencesManager have javadoc.
Comment 18 Curtis Windatt CLA 2009-04-09 17:56:52 EDT
Created attachment 131468 [details]
mylyn/context/zip
Comment 19 Ankur Sharma CLA 2009-04-10 05:38:42 EDT
The old and new preferences are compatible. I just tested. The small glitch in the test case was that the PDECore.getDefault().getPluginPreferences() gets the o.e.pde.core 's preferences. While the "stringKey" exists in the test case plug-in (private static final String PLUGIN_ID = "org.eclipse.pde.ui.tests";)

I have changes the test case to assert equals on prefs fetched by old and new preference mechanism.
Comment 20 Curtis Windatt CLA 2009-04-10 11:45:49 EDT
Made a couple more changes, fixed up the tests and committed the fix to HEAD.
Comment 21 Ankur Sharma CLA 2009-04-11 09:57:33 EDT
Created attachment 131545 [details]
o.e.pde.ui pref fixes

The o.e.pde.ui switched to PDEPreferencesManager. The usage of IPreferenceStore has not be touched as it hasn't deprecated. Test cases have been added that compare the compatibility of 
1) PDEPreferencesManager and Preferences 
2) PDEPreferencesManager and IPreferenceStore
Comment 22 Curtis Windatt CLA 2009-04-13 11:07:36 EDT
Applied the UI patch.  Added bug 272021 to finish documenting the manager.  Thanks Ankur.