Bug 263564 - API to know when default compiler preference settings have been altered
Summary: API to know when default compiler preference settings have been altered
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2009-02-03 19:25 EST by Darin Wright CLA
Modified: 2009-12-02 02:45 EST (History)
6 users (show)

See Also:


Attachments
Proposed fix (12.91 KB, patch)
2009-10-22 12:10 EDT, Olivier Thomann CLA
no flags Details | Diff
Updated patch based on Frédéric's comment (13.06 KB, patch)
2009-10-22 12:22 EDT, Olivier Thomann CLA
no flags Details | Diff
Updated patch based on Darin's comment (16.03 KB, patch)
2009-10-22 15:13 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Wright CLA 2009-02-03 19:25:47 EST
This bug is created to support bug 249593.

JDT launching sets compiler options to match the default JRE on initial (fist time) workspace startup. We only overwrite preference settings if they match default settings. 

However, if a client uses the preference override mechanism to override default settings, we cannot detect that the JDT defaults have been overridden (we just see that the settings are default, and go ahead and overwrite them).

To fix this issue, we need API from JCore that tells us if compiler settings should be modified to match the default JRE (i.e. have they been modified from JDT's default settings?).
Comment 1 Blazej Kroll CLA 2009-04-08 05:42:07 EDT
Hello,
can you give a time estimate of this bug?
Are you planning to provide the mentioned APIs? (to allow the depending bugs to be addressed)?
Comment 2 Frederic Fusier CLA 2009-04-15 12:31:07 EDT
(In reply to comment #1)
> Hello,
> can you give a time estimate of this bug?
> Are you planning to provide the mentioned APIs? (to allow the depending bugs to
> be addressed)?
> 
Unfortunately I have no clue for now what will be the 3.6 dvpt plan for JDT/Core. So, I put back this bug in the JDT/Core inbox waiting for the next release plan...
Comment 3 Darin Wright CLA 2009-10-21 09:31:53 EDT
DJ, is there any way to determine where default preference settings originate from (i.e. from a bundle's preference initializer vs. product overrides)?
Comment 4 DJ Houghton CLA 2009-10-21 10:00:17 EDT
Nope.
Comment 5 Darin Wright CLA 2009-10-21 11:17:08 EDT
DJ, how/when are product overrides applied to preference stores? Would a preference change listener be able to tell that defaults are being modified? (or does this happen before listeners are in the loop?)
Comment 6 DJ Houghton CLA 2009-10-21 11:54:40 EDT
Unfortunately the listeners are registered after the creation of the node, which is too late... the defaults have already been applied.

DefaultPreferences#loadDefaults shows the order that the defaults are applied. Also, this doc here is a summary doc with the same info:
http://eclipse.org/eclipse/platform-core/documents/user_settings/plugin_customization.html

Off the top of my head I can't think of anything here... it is too late for listeners and it doesn't sound like you could use the presence of a particular value to indicate state.
Comment 7 Krzysztof Daniel CLA 2009-10-22 02:23:20 EDT
DJ, in bug 249593 there is a patch that checks if any preferences are different from default.
JavaCore.getDefaultOptions() returns default options,
while new CompilerOptions().getMap() returns compiler options with applied preferences. 

I really do not remember if this is just a bit better heuristic or if it always work, but the patch attached to 249593 allowed for using plugin_customization.ini.
Comment 8 Olivier Thomann CLA 2009-10-22 11:08:54 EDT
What I don't like too much with this api is that it is limited to some specific options only.
What you really want is an immutable default options from JDT/Core and then the code you put inside the new method in JavaCore could be used in the client code without being API.
The problem you are having is that the JavaCore.getDefaultOptions() is affected by the usage of the plugin_customization.ini file.
Having this could let you query any option vs the default options in order to find out if it has changed.
How does this sound ?
Comment 9 Olivier Thomann CLA 2009-10-22 12:10:20 EDT
Created attachment 150270 [details]
Proposed fix

First draft. Please provide feedback.
jdt.launching patch should be updated to use this new method.
Comment 10 Frederic Fusier CLA 2009-10-22 12:20:37 EDT
(In reply to comment #9)
> Created an attachment (id=150270) [details]
> Proposed fix
> 
> First draft. Please provide feedback.
> jdt.launching patch should be updated to use this new method.

Looks good to me except the added private method in JavaCore.

I'd rather prefer:
public static Map getOriginalDefaultOptions(){
    return Collections.unmodifiableMap(Util.getOriginalDefaultOptions(null));
}
Comment 11 Olivier Thomann CLA 2009-10-22 12:22:56 EDT
Created attachment 150272 [details]
Updated patch based on Frédéric's comment
Comment 12 Darin Wright CLA 2009-10-22 12:47:31 EDT
Looks good to me. The Javadoc might be more explicit on the meaning of "original" - i.e. these are the default settings as defined by JDT core, and the "default" options are the settings defined by an installation/product/configuration (i.e. could be different).
Comment 13 Olivier Thomann CLA 2009-10-22 15:04:40 EDT
I'll make the documentation clearer about what default means in the context of this new API.
Once the API is defined, client code can check the set of compiler options they are interested in like this:
public static boolean isCompilerOptionsOverriden(){
	Map defaultOptions = JavaCore.getDefaultOptions();
	Map originalDefaultOptions = JavaCore.getOriginalDefaultOptions();
	Set compilerSettings = new HashSet(5);
	compilerSettings.add(JavaCore.COMPILER_COMPLIANCE);
	compilerSettings.add(JavaCore.COMPILER_SOURCE);
	compilerSettings.add(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
	compilerSettings.add(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER);
	compilerSettings.add(JavaCore.COMPILER_PB_ENUM_IDENTIFIER);
	for (Iterator iterator = compilerSettings.iterator(); iterator.hasNext();) {
		String optionName = (String) iterator.next();
		if (!equals(optionName, originalDefaultOptions, defaultOptions)) {
			return false;
		}
	}
	return true;
}

private static boolean equals(String optionName, Map defaultOptions, Map options) {
	if (defaultOptions.containsKey(optionName)) {
		return options.containsKey(optionName) &&
			equals(defaultOptions.get(optionName), options.get(optionName));
	}
	return !options.containsKey(optionName);
}

private static boolean equals(Object o1, Object o2) {
	if (o1 == null) {
		return o2 == null;
	}
	return o1.equals(o2);
}
Comment 14 Olivier Thomann CLA 2009-10-22 15:13:35 EDT
Created attachment 150297 [details]
Updated patch based on Darin's comment
Comment 15 Olivier Thomann CLA 2009-10-22 15:20:06 EDT
Released for 3.6M3.
Comment 16 Darin Wright CLA 2009-10-26 12:27:45 EDT
I think we should re-open this bug, based on bug 293331. A new "override" scope could be used in place of this new JDT API - and avoid any API on JDT's part.
Comment 17 Dani Megert CLA 2009-10-26 12:30:07 EDT
Agree with comment 16.
Comment 18 Darin Wright CLA 2009-10-26 12:49:38 EDT
I backed out the changes in JDT launching that use the new JCore API, so it can be removed when ready. JDT UI has not released any changes yet, so there are no more depedencies on the API.
Comment 19 Olivier Thomann CLA 2009-10-26 13:12:08 EDT
Reopen to revert.
Comment 20 Olivier Thomann CLA 2009-10-26 13:12:51 EDT
Closing as INVALID. We won't add new API on JDT/Core to fix this.