Bug 31458 - [runtime] Task Tags preference not exported
Summary: [runtime] Task Tags preference not exported
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.1 RC1   Edit
Assignee: John Arthorne CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-10 10:08 EST by Tod Creasey CLA
Modified: 2003-02-19 11:28 EST (History)
2 users (show)

See Also:


Attachments
patch for runtime (7.46 KB, patch)
2003-02-18 13:01 EST, DJ Houghton CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tod Creasey CLA 2003-02-10 10:08:00 EST
20030206

If you change the Task Tags preference and then export it it will not be set 
when you later import it.

STEPS
1) Remove the TODO tag from the Task Tags page
2) Export your preferences
3) Reset the Task Tags page 
4) Close the preference dialog
5) Reopen the preference dialog
6) Import preferences - you will not get rid of the TODO preference.
Comment 1 Dirk Baeumer CLA 2003-02-10 11:14:32 EST
Moving to JDT/Core since it seems to have something to do with how values are 
stored in the preference store. After load the exported plugins the preferences 
returned form JavaCore via JavaCore.getOptions() has still the TODO value in it.
Comment 2 David Audel CLA 2003-02-11 05:49:43 EST
The problem seems to be 
in 'org.eclipse.core.internal.runtime.PluginExporter#exportPreferences()'.
This method merge all prefences in globalPreferences. The 
method 'mergePluginPreferences' add the value of a preference in 
globalPrefences but the default value is not set. If the actual value is an 
empty String then this value is not add to globalPrefences because the default 
default value is an empty String. But for task tag the real default value is 
not an empty String. That's why task tag preference value is not exported.



Comment 3 David Audel CLA 2003-02-11 05:50:48 EST
Move to platform
Comment 4 DJ Houghton CLA 2003-02-12 14:14:57 EST
Similar problem to bug 22533.

By design, default values are not stored in the Preference store. So if you 
remove all your compiler tasks, then the value in the Preference store is an 
empty string. 

Later, Java core retrieves the value using the get(key, default) and since it 
doesn't exist, is returned the "default" which is "TODO".

Recommend that the TODO task is not given to the user for free.
Comment 5 David Audel CLA 2003-02-13 04:44:08 EST
I still think there is a problem in PreferenceExporter. The preferences are 
correctly stored but the export fails.
In my test case 'Task tag' value is "" and 'Task tag' default value is "TODO".
In PreferenceExporte#exportPreferences globalPreferences is create and all 
default values in globalPreferences are "".
When the current value of 'Task tag ' ("") is store in globalPreferences,
this value is considered as a default value in globalPreferences. But this is 
not the default value for 'Task tag'.

To avoid this problem i think the code of mergePreferences should be

private static boolean mergePluginPreferences(IPluginDescriptor descriptor, 
Preferences preferences) throws CoreException {
  boolean found = false;
  IPath propertiesFile = InternalPlatform.getMetaArea
().getPluginPreferenceLocation(descriptor, false);
  if (propertiesFile.toFile().exists()) {
    Preferences pluginPreferences = loadPreferences(propertiesFile, new 
Preferences());
    String pluginId = descriptor.getUniqueIdentifier();
    String[] keys = pluginPreferences.propertyNames();
    found = keys.length > 0;
    for (int i = 0; i < keys.length; i++) {
      String longKey = pluginId + PLUGIN_SEPARATOR + keys[i];
      preferences.setDefault(longKey, pluginPreferences.getDefaultString(keys
[i])); // This line is added
      preferences.setValue(longKey, pluginPreferences.getString(keys[i]));
    }
  }
  return found;
}

otherwise all the default values of the merged preferences are considered to 
be "".
So all the preferences with current value of "" are lost, even if their default 
values are not "".
Comment 6 DJ Houghton CLA 2003-02-13 15:24:04 EST
I was incorrect, this is not the same as bug 22533. There are 2 different 
problems here, one with the export and one with the import.

In the export, the global Preferences object which is being used to collect the 
preference values to export doesn't know about the default values for the 
workspace. So the empty string is not stored because it is the same as the 
default-default. (and there is no default) That is why the resulting file does 
not include the key for the task tags.

In the import, something similar is happening.

But we have a slight problem. The only one who knows about the defaults is the 
preferences object on the plug-in instances. Which means if a plug-in is not 
activated yet then we can't get a hold of its preferences (and defaults) 
without activating it. So we need to consider a different approach since 
activating all plug-ins on preference export is unacceptable.

The Preferences.setValue is being too smart. In the mergePluginPreferences call 
we already know that the list of keys that we have are values which we want 
stored, so we shouldn't do the "if the value is the same as the default then 
don't include it" optimization.

Investigate being extra smart and by-passing the #setValue call or using 
Properties for persistence.
Comment 7 DJ Houghton CLA 2003-02-18 13:01:40 EST
Created attachment 3553 [details]
patch for runtime

Here is a patch for the org.eclipse.core.runtime project. Needs to be tested
and released.
Comment 8 John Arthorne CLA 2003-02-19 11:28:33 EST
Fixed.  Test case added.  Released.