Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 10314 Details for
Bug 59258
Possibility to share compiler preferences for a shared project
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch implementing new preferences API for jdt-core.
v04.txt (text/plain), 59.31 KB, created by
Frederic Fusier
on 2004-05-05 17:27:22 EDT
(
hide
)
Description:
Patch implementing new preferences API for jdt-core.
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2004-05-05 17:27:22 EDT
Size:
59.31 KB
patch
obsolete
>Index: model/org/eclipse/jdt/core/JavaCore.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v >retrieving revision 1.401 >diff -u -r1.401 JavaCore.java >--- model/org/eclipse/jdt/core/JavaCore.java 4 May 2004 10:01:36 -0000 1.401 >+++ model/org/eclipse/jdt/core/JavaCore.java 5 May 2004 16:39:50 -0000 >@@ -58,19 +58,60 @@ > package org.eclipse.jdt.core; > > import java.io.File; >-import java.util.*; >- >-import org.eclipse.core.resources.*; >-import org.eclipse.core.runtime.*; >+import java.util.Enumeration; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.Hashtable; >+import java.util.Iterator; >+import java.util.Map; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IMarker; >+import org.eclipse.core.resources.IMarkerDelta; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IResourceChangeEvent; >+import org.eclipse.core.resources.IResourceChangeListener; >+import org.eclipse.core.resources.ISavedState; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.IWorkspaceRunnable; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExtension; >+import org.eclipse.core.runtime.IExtensionPoint; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Plugin; > import org.eclipse.core.runtime.jobs.ISchedulingRule; >+import org.eclipse.core.runtime.preferences.DefaultScope; >+import org.eclipse.core.runtime.preferences.IEclipsePreferences; >+import org.eclipse.core.runtime.preferences.IPreferencesService; >+import org.eclipse.core.runtime.preferences.InstanceScope; > import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; > import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > import org.eclipse.jdt.internal.compiler.util.SuffixConstants; >-import org.eclipse.jdt.internal.core.*; >+import org.eclipse.jdt.internal.core.Assert; >+import org.eclipse.jdt.internal.core.BatchOperation; >+import org.eclipse.jdt.internal.core.BufferFactoryWrapper; >+import org.eclipse.jdt.internal.core.BufferManager; >+import org.eclipse.jdt.internal.core.ClasspathEntry; >+import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner; >+import org.eclipse.jdt.internal.core.JavaModel; >+import org.eclipse.jdt.internal.core.JavaModelManager; >+import org.eclipse.jdt.internal.core.JavaProject; >+import org.eclipse.jdt.internal.core.Region; >+import org.eclipse.jdt.internal.core.SetClasspathOperation; >+import org.eclipse.jdt.internal.core.UserLibraryManager; > import org.eclipse.jdt.internal.core.search.processing.IJob; > import org.eclipse.jdt.internal.core.util.MementoTokenizer; > import org.eclipse.jdt.internal.core.util.Util; > import org.osgi.framework.BundleContext; >+import org.osgi.service.prefs.BackingStoreException; > > /** > * The plug-in runtime class for the Java model plug-in containing the core >@@ -880,6 +921,14 @@ > public static final String PRIVATE = "private"; //$NON-NLS-1$ > > /** >+ * New Preferences API >+ * @since 3.1 >+ */ >+ public static final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; >+ static final int PREF_INSTANCE = 0; >+ static final int PREF_DEFAULT = 1; >+ >+ /** > * Creates the Java core plug-in. > * <p> > * The plug-in instance is created automatically by the >@@ -969,7 +1018,7 @@ > * </p> > * > * @param listener the listener >- * @see #removePreResourceChangeListener(IResourceChangeListener) >+ * @see #removePreProcessingResourceChangedListener(IResourceChangeListener) > * @since 3.0 > */ > public static void addPreProcessingResourceChangedListener(IResourceChangeListener listener) { >@@ -2126,14 +2175,15 @@ > Hashtable defaultOptions = new Hashtable(10); > > // see #initializeDefaultPluginPreferences() for changing default settings >- Preferences preferences = getPlugin().getPluginPreferences(); >+ IEclipsePreferences defaultPreferences = getDefaultPreferences(); > HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; > > // initialize preferences to their default > Iterator iterator = optionNames.iterator(); > while (iterator.hasNext()) { > String propertyName = (String) iterator.next(); >- defaultOptions.put(propertyName, preferences.getDefaultString(propertyName)); >+ String value = defaultPreferences.get(propertyName, null); >+ if (value != null) defaultOptions.put(propertyName, value); > } > // get encoding through resource plugin > defaultOptions.put(CORE_ENCODING, getEncoding()); >@@ -2143,6 +2193,26 @@ > > return defaultOptions; > } >+ >+ /** >+ * @since 3.1 >+ */ >+ public static IEclipsePreferences getInstancePreferences() { >+ if (preferencesLookup[PREF_INSTANCE] == null) { >+ preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID); >+ } >+ return preferencesLookup[PREF_INSTANCE]; >+ } >+ >+ /** >+ * @since 3.1 >+ */ >+ public static IEclipsePreferences getDefaultPreferences() { >+ if (preferencesLookup[PREF_DEFAULT] == null) { >+ preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID); >+ } >+ return preferencesLookup[PREF_DEFAULT]; >+ } > > /** > * Returns the workspace root default charset encoding. >@@ -2153,12 +2223,15 @@ > * @since 3.0 > */ > public static String getEncoding() { >- try { >- return ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset(); >- } catch (Exception e) { >- // fails silently and return plugin global encoding if core exception occurs or >- // if workspace is shutting down (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=60687) >- } >+ // Verify that workspace is not shutting down (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=60687) >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ if (workspace != null) { >+ try { >+ return workspace.getRoot().getDefaultCharset(); >+ } catch (CoreException e) { >+ // fails silently and return plugin global encoding if core exception occurs >+ } >+ } > return ResourcesPlugin.getEncoding(); > } > >@@ -2182,6 +2255,7 @@ > * @param optionName the name of an option > * @return the String value of a given option > * @see JavaCore#getDefaultOptions() >+ * @see #initializeDefaultPreferences() for changing default settings > * @since 2.0 > */ > public static String getOption(String optionName) { >@@ -2196,8 +2270,9 @@ > } > String propertyName = optionName; > if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){ >- Preferences preferences = getPlugin().getPluginPreferences(); >- return preferences.getString(propertyName).trim(); >+ IPreferencesService service = Platform.getPreferencesService(); >+ String value = service.get(optionName, null, preferencesLookup); >+ return value==null ? null : value.trim(); > } > return null; > } >@@ -2211,39 +2286,34 @@ > * > * @return table of current settings of all options > * (key type: <code>String</code>; value type: <code>String</code>) >- * @see JavaCore#getDefaultOptions() >+ * @see #getDefaultOptions() >+ * @see #initializeDefaultPreferences() for changing default settings > */ > public static Hashtable getOptions() { >- >+ >+ // init > Hashtable options = new Hashtable(10); >+ HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; >+ IPreferencesService service = Platform.getPreferencesService(); > >- // see #initializeDefaultPluginPreferences() for changing default settings >- Plugin plugin = getPlugin(); >- if (plugin != null) { >- Preferences preferences = getPlugin().getPluginPreferences(); >- HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; >- >- // initialize preferences to their default >- Iterator iterator = optionNames.iterator(); >- while (iterator.hasNext()) { >- String propertyName = (String) iterator.next(); >- options.put(propertyName, preferences.getDefaultString(propertyName)); >- } >- // get preferences not set to their default >- String[] propertyNames = preferences.propertyNames(); >- for (int i = 0; i < propertyNames.length; i++){ >- String propertyName = propertyNames[i]; >- String value = preferences.getString(propertyName).trim(); >- if (optionNames.contains(propertyName)){ >- options.put(propertyName, value); >- } >- } >- // get encoding through resource plugin >- options.put(CORE_ENCODING, getEncoding()); >- // backward compatibility >- options.put(COMPILER_PB_INVALID_IMPORT, ERROR); >- options.put(COMPILER_PB_UNREACHABLE_CODE, ERROR); >+ // set options using preferences service lookup >+ Iterator iterator = optionNames.iterator(); >+ while (iterator.hasNext()) { >+ String propertyName = (String) iterator.next(); >+ String propertyValue = service.get(propertyName, null, preferencesLookup); >+ if (propertyValue != null) { >+ options.put(propertyName, propertyValue); >+ } > } >+ >+ // get encoding through resource plugin >+ options.put(CORE_ENCODING, getEncoding()); >+ >+ // backward compatibility >+ options.put(COMPILER_PB_INVALID_IMPORT, ERROR); >+ options.put(COMPILER_PB_UNREACHABLE_CODE, ERROR); >+ >+ // return built map > return options; > } > >@@ -2423,13 +2493,15 @@ > if (result == null) return JavaModelManager.NO_WORKING_COPY; > return result; > } >- >- /** >+ >+ /* > * Initializes the default preferences settings for this plug-in. > */ >- protected void initializeDefaultPluginPreferences() { >+ protected void initializeDefaultPreferences() { >+ >+ // Init and store default and instance preferences >+ IEclipsePreferences defaultPreferences = getDefaultPreferences(); > >- Preferences preferences = getPluginPreferences(); > HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; > > // Compiler settings >@@ -2437,47 +2509,47 @@ > for (Iterator iter = compilerOptionsMap.entrySet().iterator(); iter.hasNext();) { > Map.Entry entry = (Map.Entry) iter.next(); > String optionName = (String) entry.getKey(); >- preferences.setDefault(optionName, (String)entry.getValue()); >+ defaultPreferences.put(optionName, (String)entry.getValue()); > optionNames.add(optionName); > } > // override some compiler defaults >- preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE); >- preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE); >- preferences.setDefault(COMPILER_TASK_TAGS, DEFAULT_TASK_TAGS); >- preferences.setDefault(COMPILER_TASK_PRIORITIES, DEFAULT_TASK_PRIORITIES); >- preferences.setDefault(COMPILER_TASK_CASE_SENSITIVE, ENABLED); >- preferences.setDefault(COMPILER_DOC_COMMENT_SUPPORT, ENABLED); >+ defaultPreferences.put(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE); >+ defaultPreferences.put(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE); >+ defaultPreferences.put(COMPILER_TASK_TAGS, DEFAULT_TASK_TAGS); >+ defaultPreferences.put(COMPILER_TASK_PRIORITIES, DEFAULT_TASK_PRIORITIES); >+ defaultPreferences.put(COMPILER_TASK_CASE_SENSITIVE, ENABLED); >+ defaultPreferences.put(COMPILER_DOC_COMMENT_SUPPORT, ENABLED); > > // Builder settings >- preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$ > optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER); > >- preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); >+ defaultPreferences.put(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); > optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH); > >- preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); >+ defaultPreferences.put(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); > optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE); > >- preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); >+ defaultPreferences.put(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); > optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER); > > // JavaCore settings >- preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE); >+ defaultPreferences.put(CORE_JAVA_BUILD_ORDER, IGNORE); > optionNames.add(CORE_JAVA_BUILD_ORDER); > >- preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR); >+ defaultPreferences.put(CORE_INCOMPLETE_CLASSPATH, ERROR); > optionNames.add(CORE_INCOMPLETE_CLASSPATH); > >- preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR); >+ defaultPreferences.put(CORE_CIRCULAR_CLASSPATH, ERROR); > optionNames.add(CORE_CIRCULAR_CLASSPATH); > >- preferences.setDefault(CORE_INCOMPATIBLE_JDK_LEVEL, IGNORE); >+ defaultPreferences.put(CORE_INCOMPATIBLE_JDK_LEVEL, IGNORE); > optionNames.add(CORE_INCOMPATIBLE_JDK_LEVEL); > >- preferences.setDefault(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, ENABLED); >+ defaultPreferences.put(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, ENABLED); > optionNames.add(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS); > >- preferences.setDefault(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, ENABLED); >+ defaultPreferences.put(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, ENABLED); > optionNames.add(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS); > > // encoding setting comes from resource plug-in >@@ -2488,68 +2560,68 @@ > for (Iterator iter = codeFormatterOptionsMap.entrySet().iterator(); iter.hasNext();) { > Map.Entry entry = (Map.Entry) iter.next(); > String optionName = (String) entry.getKey(); >- preferences.setDefault(optionName, (String)entry.getValue()); >+ defaultPreferences.put(optionName, (String)entry.getValue()); > optionNames.add(optionName); > } >- preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT); >+ defaultPreferences.put(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT); > optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE); > >- preferences.setDefault(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT); >+ defaultPreferences.put(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT); > optionNames.add(FORMATTER_NEWLINE_CONTROL); > >- preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE); >+ defaultPreferences.put(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE); > optionNames.add(FORMATTER_CLEAR_BLANK_LINES); > >- preferences.setDefault(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT); >+ defaultPreferences.put(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT); > optionNames.add(FORMATTER_NEWLINE_ELSE_IF); > >- preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT); >+ defaultPreferences.put(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT); > optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK); > >- preferences.setDefault(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$ >+ defaultPreferences.put(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$ > optionNames.add(FORMATTER_LINE_SPLIT); > >- preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL); >+ defaultPreferences.put(FORMATTER_COMPACT_ASSIGNMENT, NORMAL); > optionNames.add(FORMATTER_COMPACT_ASSIGNMENT); > >- preferences.setDefault(FORMATTER_TAB_CHAR, TAB); >+ defaultPreferences.put(FORMATTER_TAB_CHAR, TAB); > optionNames.add(FORMATTER_TAB_CHAR); > >- preferences.setDefault(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ >+ defaultPreferences.put(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ > optionNames.add(FORMATTER_TAB_SIZE); > >- preferences.setDefault(FORMATTER_SPACE_CASTEXPRESSION, INSERT); //$NON-NLS-1$ >+ defaultPreferences.put(FORMATTER_SPACE_CASTEXPRESSION, INSERT); //$NON-NLS-1$ > optionNames.add(FORMATTER_SPACE_CASTEXPRESSION); > > // CodeAssist settings >- preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$ > optionNames.add(CODEASSIST_VISIBILITY_CHECK); > >- preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$ > optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION); > >- preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_FIELD_PREFIXES); > >- preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES); > >- preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_LOCAL_PREFIXES); > >- preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_ARGUMENT_PREFIXES); > >- preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_FIELD_SUFFIXES); > >- preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES); > >- preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_LOCAL_SUFFIXES); > >- preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$ >+ defaultPreferences.put(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$ > optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES); > } > >@@ -3647,26 +3719,37 @@ > * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>), > * or <code>null</code> to reset all options to their default values > * @see JavaCore#getDefaultOptions() >+ * @see #initializeDefaultPreferences() for changing default settings > */ > public static void setOptions(Hashtable newOptions) { > >- // see #initializeDefaultPluginPreferences() for changing default settings >- Preferences preferences = getPlugin().getPluginPreferences(); >+ try { >+ IEclipsePreferences defaultPreferences = getDefaultPreferences(); >+ IEclipsePreferences instancePreferences = getInstancePreferences(); > >- if (newOptions == null){ >- newOptions = JavaCore.getDefaultOptions(); >- } >- Enumeration keys = newOptions.keys(); >- while (keys.hasMoreElements()){ >- String key = (String)keys.nextElement(); >- if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option >- if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs >- String value = (String)newOptions.get(key); >- preferences.setValue(key, value); >- } >+ if (newOptions == null){ >+ instancePreferences.clear(); >+ } else { >+ Enumeration keys = newOptions.keys(); >+ while (keys.hasMoreElements()){ >+ String key = (String)keys.nextElement(); >+ if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option >+ if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs >+ String value = (String)newOptions.get(key); >+ String defaultValue = defaultPreferences.get(key, null); >+ if (defaultValue != null && defaultValue.equals(value)) { >+ instancePreferences.remove(key); >+ } else { >+ instancePreferences.put(key, value); >+ } >+ } >+ } > >- // persist options >- getPlugin().savePluginPreferences(); >+ // persist options >+ instancePreferences.flush(); >+ } catch (BackingStoreException e) { >+ // fails silently >+ } > } > > /* (non-Javadoc) >@@ -3711,6 +3794,9 @@ > public void start(BundleContext context) throws Exception { > super.start(context); > >+ // init preferences >+ initializeDefaultPreferences(); >+ > final JavaModelManager manager = JavaModelManager.getJavaModelManager(); > try { > manager.configurePluginDebugOptions(); >@@ -3719,7 +3805,7 @@ > JavaCore.getPlugin().getStateLocation(); > > // retrieve variable values >- JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new JavaModelManager.PluginPreferencesListener()); >+ getInstancePreferences().addPreferenceChangeListener(new JavaModelManager.EclipsePreferencesListener()); > manager.loadVariablesAndContainers(); > > final IWorkspace workspace = ResourcesPlugin.getWorkspace(); >Index: model/org/eclipse/jdt/internal/core/DeltaProcessor.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java,v >retrieving revision 1.235 >diff -u -r1.235 DeltaProcessor.java >--- model/org/eclipse/jdt/internal/core/DeltaProcessor.java 30 Apr 2004 09:22:07 -0000 1.235 >+++ model/org/eclipse/jdt/internal/core/DeltaProcessor.java 5 May 2004 16:39:50 -0000 >@@ -31,7 +31,6 @@ > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.Preferences; > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.core.ElementChangedEvent; > import org.eclipse.jdt.core.IClasspathEntry; >@@ -912,6 +911,8 @@ > } > this.removeFromParentInfo(javaProject); > >+ // remove preferences from per project info >+ this.manager.resetProjectPreferences(javaProject); > } catch (JavaModelException e) { > // java project doesn't exist: ignore > } >@@ -1719,65 +1720,7 @@ > } > } > } >- /* >- * Update the JavaModel according to a .jprefs file change. The file can have changed as a result of a previous >- * call to JavaProject#setOptions or as a result of some user update (through repository) >- * Unused until preference file get shared (.jpref) >- */ >- void reconcilePreferenceFileUpdate(IResourceDelta delta, IFile file, JavaProject project) { >- >- switch (delta.getKind()) { >- case IResourceDelta.REMOVED : // flush project custom settings >- project.setOptions(null); >- return; >- case IResourceDelta.CHANGED : >- if ((delta.getFlags() & IResourceDelta.CONTENT) == 0 // only consider content change >- && (delta.getFlags() & IResourceDelta.MOVED_FROM) == 0) // and also move and overide scenario >- break; >- identityCheck : { // check if any actual difference >- // force to (re)read the property file >- Preferences filePreferences = project.loadPreferences(); >- if (filePreferences == null){ >- project.setOptions(null); // should have got removed delta. >- return; >- } >- Preferences projectPreferences = project.getPreferences(); >- if (projectPreferences == null) return; // not a Java project >- >- // compare preferences set to their default >- String[] defaultProjectPropertyNames = projectPreferences.defaultPropertyNames(); >- String[] defaultFilePropertyNames = filePreferences.defaultPropertyNames(); >- if (defaultProjectPropertyNames.length == defaultFilePropertyNames.length) { >- for (int i = 0; i < defaultProjectPropertyNames.length; i++){ >- String propertyName = defaultProjectPropertyNames[i]; >- if (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){ >- break identityCheck; >- } >- } >- } else break identityCheck; > >- // compare custom preferences not set to their default >- String[] projectPropertyNames = projectPreferences.propertyNames(); >- String[] filePropertyNames = filePreferences.propertyNames(); >- if (projectPropertyNames.length == filePropertyNames.length) { >- for (int i = 0; i < projectPropertyNames.length; i++){ >- String propertyName = projectPropertyNames[i]; >- if (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){ >- break identityCheck; >- } >- } >- } else break identityCheck; >- >- // identical - do nothing >- return; >- } >- case IResourceDelta.ADDED : >- // not identical, create delta and reset cached preferences >- project.setPreferences(null); >- // create delta >- //fCurrentDelta.changed(project, IJavaElementDelta.F_OPTIONS_CHANGED); >- } >- } > /* > * Traverse the set of projects which have changed namespace, and reset their > * caches and their dependents >Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v >retrieving revision 1.227 >diff -u -r1.227 JavaModelManager.java >--- model/org/eclipse/jdt/internal/core/JavaModelManager.java 30 Apr 2004 09:29:16 -0000 1.227 >+++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 5 May 2004 16:39:50 -0000 >@@ -10,18 +10,64 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >-import java.io.*; >+import java.io.BufferedInputStream; >+import java.io.BufferedOutputStream; >+import java.io.DataInputStream; >+import java.io.DataOutputStream; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileOutputStream; >+import java.io.IOException; >+import java.io.StringReader; > import java.text.NumberFormat; >-import java.util.*; >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Map; >+import java.util.WeakHashMap; > import java.util.zip.ZipFile; >- > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; >- >-import org.eclipse.core.resources.*; >-import org.eclipse.core.runtime.*; >-import org.eclipse.jdt.core.*; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ISaveContext; >+import org.eclipse.core.resources.ISaveParticipant; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.IWorkspaceDescription; >+import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExtension; >+import org.eclipse.core.runtime.IExtensionPoint; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.MultiStatus; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Plugin; >+import org.eclipse.core.runtime.QualifiedName; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.preferences.IEclipsePreferences; >+import org.eclipse.jdt.core.IClassFile; >+import org.eclipse.jdt.core.IClasspathContainer; >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.IParent; >+import org.eclipse.jdt.core.IProblemRequestor; >+import org.eclipse.jdt.core.JavaConventions; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.WorkingCopyOwner; > import org.eclipse.jdt.core.compiler.IProblem; > import org.eclipse.jdt.core.search.SearchEngine; > import org.eclipse.jdt.internal.codeassist.CompletionEngine; >@@ -33,6 +79,7 @@ > import org.eclipse.jdt.internal.core.search.indexing.IndexManager; > import org.eclipse.jdt.internal.core.search.processing.JobManager; > import org.eclipse.jdt.internal.core.util.Util; >+import org.osgi.service.prefs.BackingStoreException; > import org.w3c.dom.Element; > import org.w3c.dom.Node; > import org.w3c.dom.NodeList; >@@ -497,7 +544,7 @@ > public IClasspathEntry[] resolvedClasspath; > public Map resolvedPathToRawEntries; // reverse map from resolved path to raw entries > public IPath outputLocation; >- public Preferences preferences; >+ public IEclipsePreferences preferences; > > public PerProjectInfo(IProject project) { > >@@ -576,7 +623,7 @@ > public String toString() { > StringBuffer buffer = new StringBuffer(); > buffer.append("Info for "); //$NON-NLS-1$ >- buffer.append(((JavaElement)workingCopy).toStringWithAncestors()); >+ buffer.append(((JavaElement)this.workingCopy).toStringWithAncestors()); > buffer.append("\nUse count = "); //$NON-NLS-1$ > buffer.append(this.useCount); > buffer.append("\nProblem requestor:\n "); //$NON-NLS-1$ >@@ -599,13 +646,12 @@ > /** > * Update the classpath variable cache > */ >- public static class PluginPreferencesListener implements Preferences.IPropertyChangeListener { >+ public static class EclipsePreferencesListener implements IEclipsePreferences.IPreferenceChangeListener { > /** >- * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(PropertyChangeEvent) >+ * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) > */ >- public void propertyChange(Preferences.PropertyChangeEvent event) { >- >- String propertyName = event.getProperty(); >+ public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) { >+ String propertyName = event.getKey(); > if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) { > String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length()); > String newValue = (String)event.getNewValue(); >@@ -711,7 +757,7 @@ > * Returns the new use count (or -1 if it didn't exist). > */ > public synchronized int discardPerWorkingCopyInfo(CompilationUnit workingCopy) throws JavaModelException { >- synchronized(perWorkingCopyInfos) { >+ synchronized(this.perWorkingCopyInfos) { > WorkingCopyOwner owner = workingCopy.owner; > Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner); > if (workingCopyToInfos == null) return -1; >@@ -811,7 +857,7 @@ > * Returns the handle to the active Java Model. > */ > public final JavaModel getJavaModel() { >- return javaModel; >+ return this.javaModel; > } > > /** >@@ -847,11 +893,11 @@ > * Returns the per-project info for the given project. If specified, create the info if the info doesn't exist. > */ > public PerProjectInfo getPerProjectInfo(IProject project, boolean create) { >- synchronized(perProjectInfos) { // use the perProjectInfo collection as its own lock >- PerProjectInfo info= (PerProjectInfo) perProjectInfos.get(project); >+ synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock >+ PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project); > if (info == null && create) { > info= new PerProjectInfo(project); >- perProjectInfos.put(project, info); >+ this.perProjectInfos.put(project, info); > } > return info; > } >@@ -880,7 +926,7 @@ > * Returns null if it doesn't exist and not create. > */ > public PerWorkingCopyInfo getPerWorkingCopyInfo(CompilationUnit workingCopy,boolean create, boolean recordUsage, IProblemRequestor problemRequestor) { >- synchronized(perWorkingCopyInfos) { // use the perWorkingCopyInfo collection as its own lock >+ synchronized(this.perWorkingCopyInfos) { // use the perWorkingCopyInfo collection as its own lock > WorkingCopyOwner owner = workingCopy.owner; > Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner); > if (workingCopyToInfos == null && create) { >@@ -976,11 +1022,11 @@ > * Returns null if it has none. > */ > public ICompilationUnit[] getWorkingCopies(WorkingCopyOwner owner, boolean addPrimary) { >- synchronized(perWorkingCopyInfos) { >+ synchronized(this.perWorkingCopyInfos) { > ICompilationUnit[] primaryWCs = addPrimary && owner != DefaultWorkingCopyOwner.PRIMARY > ? getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false) > : null; >- Map workingCopyToInfos = (Map)perWorkingCopyInfos.get(owner); >+ Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner); > if (workingCopyToInfos == null) return primaryWCs; > int primaryLength = primaryWCs == null ? 0 : primaryWCs.length; > int size = workingCopyToInfos.size(); // note size is > 0 otherwise pathToPerWorkingCopyInfos would be null >@@ -1099,23 +1145,31 @@ > } > > // load variables and containers from preferences into cache >- Preferences preferences = JavaCore.getPlugin().getPluginPreferences(); >+ IEclipsePreferences preferences = JavaCore.getInstancePreferences(); > > // only get variable from preferences not set to their default >- String[] propertyNames = preferences.propertyNames(); >- int variablePrefixLength = CP_VARIABLE_PREFERENCES_PREFIX.length(); >- for (int i = 0; i < propertyNames.length; i++){ >- String propertyName = propertyNames[i]; >- if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)){ >- String varName = propertyName.substring(variablePrefixLength); >- IPath varPath = new Path(preferences.getString(propertyName).trim()); >- >- this.variables.put(varName, varPath); >- this.previousSessionVariables.put(varName, varPath); >- } >- if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){ >- recreatePersistedContainer(propertyName, preferences.getString(propertyName), true/*add to container values*/); >+ try { >+ String[] propertyNames = preferences.keys(); >+ int variablePrefixLength = CP_VARIABLE_PREFERENCES_PREFIX.length(); >+ for (int i = 0; i < propertyNames.length; i++){ >+ String propertyName = propertyNames[i]; >+ if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)){ >+ String varName = propertyName.substring(variablePrefixLength); >+ String propertyValue = preferences.get(propertyName, null); >+ if (propertyValue != null) { >+ IPath varPath = new Path(propertyValue.trim()); >+ this.variables.put(varName, varPath); >+ this.previousSessionVariables.put(varName, varPath); >+ } >+ } >+ if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){ >+ String propertyValue = preferences.get(propertyName, null); >+ if (propertyValue != null) >+ recreatePersistedContainer(propertyName, propertyValue, true/*add to container values*/); >+ } > } >+ } catch (BackingStoreException e1) { >+ // TODO (frederic) see if it's necessary to report this failure... > } > // override persisted values for variables which have a registered initializer > String[] registeredVariables = getRegisteredVariableNames(); >@@ -1313,11 +1367,24 @@ > } > > public void removePerProjectInfo(JavaProject javaProject) { >- synchronized(perProjectInfos) { // use the perProjectInfo collection as its own lock >+ synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock >+ IProject project = javaProject.getProject(); >+ PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project); >+ if (info != null) { >+ this.perProjectInfos.remove(project); >+ } >+ } >+ } >+ >+ /* >+ * Reset project preferences stored in info cache. >+ */ >+ public void resetProjectPreferences(JavaProject javaProject) { >+ synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock > IProject project = javaProject.getProject(); >- PerProjectInfo info= (PerProjectInfo) perProjectInfos.get(project); >+ PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project); > if (info != null) { >- perProjectInfos.remove(project); >+ info.preferences = null; > } > } > } >@@ -1399,7 +1466,6 @@ > public void saving(ISaveContext context) throws CoreException { > > // save container values on snapshot/full save >- Preferences preferences = JavaCore.getPlugin().getPluginPreferences(); > IJavaProject[] projects = getJavaModel().getJavaProjects(); > for (int i = 0, length = projects.length; i < length; i++) { > IJavaProject project = projects[i]; >@@ -1417,11 +1483,17 @@ > } catch(JavaModelException e){ > // could not encode entry: leave it as CP_ENTRY_IGNORE > } >- preferences.setDefault(containerKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones >- preferences.setValue(containerKey, containerString); >+ JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary... >+ JavaCore.getInstancePreferences().put(containerKey, containerString); > } > } >- JavaCore.getPlugin().savePluginPreferences(); >+ try { >+ JavaCore.getInstancePreferences().flush(); >+ } catch (BackingStoreException e) { >+ // TODO (frederic) see if it's necessary to report this exception >+ // IStatus status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$ >+ // throw new CoreException(status); >+ } > > if (context.getKind() == ISaveContext.FULL_SAVE) { > // will need delta since this save (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658) >@@ -1444,7 +1516,7 @@ > } > > ArrayList vStats= null; // lazy initialized >- for (Iterator iter = perProjectInfos.values().iterator(); iter.hasNext();) { >+ for (Iterator iter = this.perProjectInfos.values().iterator(); iter.hasNext();) { > try { > PerProjectInfo info = (PerProjectInfo) iter.next(); > saveState(info, context); >@@ -1597,11 +1669,16 @@ > } > } > >- Preferences preferences = JavaCore.getPlugin().getPluginPreferences(); > String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName; > String variableString = variablePath == null ? CP_ENTRY_IGNORE : variablePath.toString(); >- preferences.setDefault(variableKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones >- preferences.setValue(variableKey, variableString); >- JavaCore.getPlugin().savePluginPreferences(); >+ JavaCore.getDefaultPreferences().put(variableKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary... >+ JavaCore.getInstancePreferences().put(variableKey, variableString); >+ try { >+ JavaCore.getInstancePreferences().flush(); >+ } catch (BackingStoreException e) { >+ // TODO (frederic) see if it's necessary to report this exception >+// IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$ >+// throw new CoreException(status); >+ } > } > } >Index: model/org/eclipse/jdt/internal/core/JavaProject.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v >retrieving revision 1.305 >diff -u -r1.305 JavaProject.java >--- model/org/eclipse/jdt/internal/core/JavaProject.java 29 Apr 2004 15:10:29 -0000 1.305 >+++ model/org/eclipse/jdt/internal/core/JavaProject.java 5 May 2004 16:39:50 -0000 >@@ -11,15 +11,12 @@ > package org.eclipse.jdt.internal.core; > > import java.io.BufferedInputStream; >-import java.io.BufferedOutputStream; > import java.io.ByteArrayInputStream; > import java.io.ByteArrayOutputStream; > import java.io.File; > import java.io.FileInputStream; >-import java.io.FileOutputStream; > import java.io.IOException; > import java.io.InputStream; >-import java.io.OutputStream; > import java.io.OutputStreamWriter; > import java.io.StringReader; > import java.util.ArrayList; >@@ -28,11 +25,9 @@ > import java.util.Hashtable; > import java.util.Iterator; > import java.util.Map; >- > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; >- > import org.eclipse.core.resources.ICommand; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IFolder; >@@ -43,13 +38,18 @@ > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.ProjectScope; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.Preferences; > import org.eclipse.core.runtime.QualifiedName; >+import org.eclipse.core.runtime.preferences.IEclipsePreferences; >+import org.eclipse.core.runtime.preferences.IPreferencesService; >+import org.eclipse.core.runtime.preferences.IScopeContext; > import org.eclipse.jdt.core.IClasspathContainer; > import org.eclipse.jdt.core.IClasspathEntry; > import org.eclipse.jdt.core.ICompilationUnit; >@@ -74,6 +74,7 @@ > import org.eclipse.jdt.internal.core.util.MementoTokenizer; > import org.eclipse.jdt.internal.core.util.Util; > import org.eclipse.jdt.internal.eval.EvaluationContext; >+import org.osgi.service.prefs.BackingStoreException; > import org.w3c.dom.Element; > import org.w3c.dom.Node; > import org.w3c.dom.NodeList; >@@ -124,6 +125,10 @@ > > /** > * Name of file containing custom project preferences >+ * @deprecated WARNING Visibility will be reduce to private before M9 >+ * If you use this variable, change your implementation to avoid future comilation error... >+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=59258">bug 59258</a> >+ * TODO (frederic) set visibility from public to private > */ > public static final String PREF_FILENAME = ".jprefs"; //$NON-NLS-1$ > >@@ -131,8 +136,6 @@ > * Value of the project's raw classpath if the .classpath file contains invalid entries. > */ > public static final IClasspathEntry[] INVALID_CLASSPATH = new IClasspathEntry[0]; >- >- private static final String CUSTOM_DEFAULT_OPTION_VALUE = "#\r\n\r#custom-non-empty-default-value#\r\n\r#"; //$NON-NLS-1$ > > /** > * Returns a canonicalized path from the given external path. >@@ -1395,11 +1398,11 @@ > > String propertyName = optionName; > if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){ >- Preferences preferences = getPreferences(); >- if (preferences == null || preferences.isDefault(propertyName)) { >- return inheritJavaCoreOptions ? JavaCore.getOption(propertyName) : null; >- } >- return preferences.getString(propertyName).trim(); >+ IEclipsePreferences preferences = getEclipsePreferences(); >+ String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(propertyName) : null; >+ if (preferences == null) return javaCoreDefault; >+ String value = preferences.get(propertyName, javaCoreDefault); >+ return value == null ? null : value.trim(); > } > return null; > } >@@ -1412,21 +1415,25 @@ > // initialize to the defaults from JavaCore options pool > Map options = inheritJavaCoreOptions ? JavaCore.getOptions() : new Hashtable(5); > >- Preferences preferences = getPreferences(); >+ IEclipsePreferences preferences = getEclipsePreferences(); > if (preferences == null) return options; // cannot do better (non-Java project) > HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; > > // project cannot hold custom preferences set to their default, as it uses CUSTOM_DEFAULT_OPTION_VALUE > > // get custom preferences not set to their default >- String[] propertyNames = preferences.propertyNames(); >- for (int i = 0; i < propertyNames.length; i++){ >- String propertyName = propertyNames[i]; >- String value = preferences.getString(propertyName).trim(); >- if (optionNames.contains(propertyName)){ >- options.put(propertyName, value); >- } >- } >+ try { >+ String[] propertyNames = preferences.keys(); >+ for (int i = 0; i < propertyNames.length; i++){ >+ String propertyName = propertyNames[i]; >+ String value = preferences.get(propertyName, null); >+ if (value != null && optionNames.contains(propertyName)){ >+ options.put(propertyName, value.trim()); >+ } >+ } >+ } catch (BackingStoreException e) { >+ // nothing to do >+ } > > return options; > } >@@ -1635,7 +1642,7 @@ > public JavaModelManager.PerProjectInfo getPerProjectInfo() throws JavaModelException { > return JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(this.project); > } >- >+ > /** > * @see IJavaProject#getProject() > */ >@@ -1646,9 +1653,32 @@ > /** > * Returns the project custom preference pool. > * Project preferences may include custom encoding. >- * @return Preferences >+ * @return IEclipsePreferences > */ >+ public IEclipsePreferences getEclipsePreferences(){ >+ if (!JavaProject.hasJavaNature(this.project)) return null; >+ JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true); >+ IEclipsePreferences eclipsePreferences = perProjectInfo.preferences; >+ if (eclipsePreferences != null) return eclipsePreferences; >+ IScopeContext context = new ProjectScope(getProject()); >+ eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID); >+ updatePreferences(eclipsePreferences); >+ perProjectInfo.preferences = eclipsePreferences; >+ return eclipsePreferences; >+ } >+ >+ /** >+ * Returns the project custom preference pool. >+ * Project preferences may include custom encoding. >+ * @return Preferences >+ * @deprecated WARNING: this method do nothing from now and will be removed soon! >+ * If you use it, switch as soon as possible to new preferences API by using >+ * {@link #getEclipsePreferences()} to avoid future compilation error... >+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=59258">bug 59258</a> >+ * TODO (frederic) remove for 3.1... >+ */ > public Preferences getPreferences(){ >+ /* > if (!JavaProject.hasJavaNature(this.project)) return null; > JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true); > Preferences preferences = perProjectInfo.preferences; >@@ -1657,6 +1687,8 @@ > if (preferences == null) preferences = new Preferences(); > perProjectInfo.preferences = preferences; > return preferences; >+ */ >+ return new Preferences(); > } > > /** >@@ -2103,14 +2135,42 @@ > } > > /* >+ * Update eclipse preferences from old preferences. >+ */ >+ private void updatePreferences(IEclipsePreferences preferences) { >+ >+ Preferences oldPreferences = loadPreferences(); >+ IPreferencesService service = Platform.getPreferencesService(); >+ if (oldPreferences != null) { >+ String[] propertyNames = oldPreferences.propertyNames(); >+ for (int i = 0; i < propertyNames.length; i++){ >+ String propertyName = propertyNames[i]; >+ String propertyValue = oldPreferences.getString(propertyName); >+ String defaultValue = service.get(propertyName, null, JavaCore.preferencesLookup); >+ if (!"".equals(propertyValue) && (defaultValue == null || !propertyValue.equals(defaultValue))) { //$NON-NLS-1$ >+ preferences.put(propertyName, propertyValue); >+ } >+ } >+ try { >+ // save immediately old preferences >+ preferences.flush(); >+ } catch (BackingStoreException e) { >+ // fails silently >+ } >+ } >+ } >+ >+ /** > * load preferences from a shareable format (VCM-wise) >+ * @deprecated WARNING, visibility of this method will be decreased soon >+ * to private and won't be usable in the future. >+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=59258">bug 59258</a> >+ * TODO (frederic) set visibility from public to private > */ > public Preferences loadPreferences() { > > Preferences preferences = new Preferences(); >- >-// File prefFile = this.project.getLocation().append(PREF_FILENAME).toFile(); >- IPath projectMetaLocation = getPluginWorkingLocation(); >+ IPath projectMetaLocation = getPluginWorkingLocation(); > if (projectMetaLocation != null) { > File prefFile = projectMetaLocation.append(PREF_FILENAME).toFile(); > if (prefFile.exists()) { // load preferences from file >@@ -2118,7 +2178,6 @@ > try { > in = new BufferedInputStream(new FileInputStream(prefFile)); > preferences.load(in); >- return preferences; > } catch (IOException e) { // problems loading preference store - quietly ignore > } finally { > if (in != null) { >@@ -2128,11 +2187,14 @@ > } > } > } >+ // one shot read, delete old preferences >+ prefFile.delete(); >+ return preferences; > } > } > return null; > } >- >+ > /** > * @see IJavaProject#newEvaluationContext() > */ >@@ -2401,49 +2463,6 @@ > throw new JavaModelException(e); > } > } >- /** >- * Save project custom preferences to shareable file (.jprefs) >- */ >- private void savePreferences(Preferences preferences) { >- >- if (!JavaProject.hasJavaNature(this.project)) return; // ignore >- >- if (preferences == null || (!preferences.needsSaving() && preferences.propertyNames().length != 0)) { >- // nothing to save >- return; >- } >- >- // preferences need to be saved >- // the preferences file is located in the plug-in's state area >- // at a well-known name (.jprefs) >-// File prefFile = this.project.getLocation().append(PREF_FILENAME).toFile(); >- File prefFile = getPluginWorkingLocation().append(PREF_FILENAME).toFile(); >- if (preferences.propertyNames().length == 0) { >- // there are no preference settings >- // rather than write an empty file, just delete any existing file >- if (prefFile.exists()) { >- prefFile.delete(); // don't worry if delete unsuccessful >- } >- return; >- } >- >- // write file, overwriting an existing one >- OutputStream out = null; >- try { >- // do it as carefully as we know how so that we don't lose/mangle >- // the setting in times of stress >- out = new BufferedOutputStream(new FileOutputStream(prefFile)); >- preferences.store(out, null); >- } catch (IOException e) { // problems saving preference store - quietly ignore >- } finally { >- if (out != null) { >- try { >- out.close(); >- } catch (IOException e) { // ignore problems with close >- } >- } >- } >- } > > /** > * Update the Java command in the build spec (replace existing one if present, >@@ -2483,10 +2502,16 @@ > */ > public void setOption(String optionName, String optionValue) { > if (!JavaModelManager.getJavaModelManager().optionNames.contains(optionName)) return; // unrecognized option >- Preferences preferences = getPreferences(); >- preferences.setDefault(optionName, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251) >- preferences.setValue(optionName, optionValue); >- savePreferences(preferences); >+ IEclipsePreferences projectPreferences = getEclipsePreferences(); >+ String defaultValue = JavaCore.getOption(optionName); >+ if (defaultValue == null || !defaultValue.equals(optionValue)) { >+ projectPreferences.put(optionName, optionValue); >+ try { >+ projectPreferences.flush(); >+ } catch (BackingStoreException e) { >+ // problem with pref store - quietly ignore >+ } >+ } > } > > /** >@@ -2494,33 +2519,38 @@ > */ > public void setOptions(Map newOptions) { > >- Preferences preferences = getPreferences(); >- if (newOptions != null){ >- Iterator keys = newOptions.keySet().iterator(); >- while (keys.hasNext()){ >- String key = (String)keys.next(); >- if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option >- // no filtering for encoding (custom encoding for project is allowed) >- String value = (String)newOptions.get(key); >- preferences.setDefault(key, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251) >- preferences.setValue(key, value); >- } >- } >- >- // reset to default all options not in new map >- // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255 >- // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691 >- String[] pNames = preferences.propertyNames(); >- int ln = pNames.length; >- for (int i=0; i<ln; i++) { >- String key = pNames[i]; >- if (newOptions == null || !newOptions.containsKey(key)) { >- preferences.setToDefault(key); // set default => remove from preferences table >+ IEclipsePreferences projectPreferences = getEclipsePreferences(); >+ try { >+ if (newOptions == null){ >+ projectPreferences.clear(); >+ } else { >+ Iterator keys = newOptions.keySet().iterator(); >+ while (keys.hasNext()){ >+ String key = (String)keys.next(); >+ if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option >+ // no filtering for encoding (custom encoding for project is allowed) >+ String value = (String)newOptions.get(key); >+ projectPreferences.put(key, value); >+ } >+ >+ // reset to default all options not in new map >+ // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255 >+ // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691 >+ String[] pNames = projectPreferences.keys(); >+ int ln = pNames.length; >+ for (int i=0; i<ln; i++) { >+ String key = pNames[i]; >+ if (!newOptions.containsKey(key)) { >+ projectPreferences.remove(key); // old preferences => remove from preferences table >+ } >+ } > } >- } > >- // persist options >- savePreferences(preferences); >+ // persist options >+ projectPreferences.flush(); >+ } catch (BackingStoreException e) { >+ // problem with pref store - quietly ignore >+ } > } > > /** >@@ -2536,15 +2566,6 @@ > return; > } > this.setRawClasspath(SetClasspathOperation.ReuseClasspath, path, monitor); >- } >- >- /* >- * Set cached preferences, no preference file is saved, only info is updated >- */ >- public void setPreferences(Preferences preferences) { >- if (!JavaProject.hasJavaNature(this.project)) return; // ignore >- JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true); >- perProjectInfo.preferences = preferences; > } > > /** >Index: model/org/eclipse/jdt/internal/core/UserLibraryManager.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/UserLibraryManager.java,v >retrieving revision 1.2 >diff -u -r1.2 UserLibraryManager.java >--- model/org/eclipse/jdt/internal/core/UserLibraryManager.java 21 Apr 2004 14:50:10 -0000 1.2 >+++ model/org/eclipse/jdt/internal/core/UserLibraryManager.java 5 May 2004 16:39:50 -0000 >@@ -22,16 +22,15 @@ > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.Preferences; > import org.eclipse.core.runtime.SubProgressMonitor; >-import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; >-import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; >+import org.eclipse.core.runtime.preferences.IEclipsePreferences; > import org.eclipse.jdt.core.IClasspathContainer; > import org.eclipse.jdt.core.IClasspathEntry; > import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.internal.core.util.Util; >+import org.osgi.service.prefs.BackingStoreException; > > /** > * >@@ -43,10 +42,10 @@ > > private static Map userLibraries; > private static final boolean logProblems= false; >- private static IPropertyChangeListener listener= new IPropertyChangeListener() { >+ private static IEclipsePreferences.IPreferenceChangeListener listener= new IEclipsePreferences.IPreferenceChangeListener() { > >- public void propertyChange(PropertyChangeEvent event) { >- String key= event.getProperty(); >+ public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) { >+ String key= event.getKey(); > if (key.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) { > try { > recreatePersistedUserLibraryEntry(key, (String) event.getNewValue(), false, true); >@@ -58,7 +57,6 @@ > } > } > } >- > }; > > private UserLibraryManager() { >@@ -126,20 +124,26 @@ > if (userLibraries == null) { > userLibraries= new HashMap(); > // load variables and containers from preferences into cache >- Preferences preferences = JavaCore.getPlugin().getPluginPreferences(); >- preferences.addPropertyChangeListener(listener); >+ IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences(); >+ instancePreferences.addPreferenceChangeListener(listener); > > // only get variable from preferences not set to their default >- String[] propertyNames = preferences.propertyNames(); >- for (int i = 0; i < propertyNames.length; i++) { >- String propertyName = propertyNames[i]; >- if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) { >- try { >- recreatePersistedUserLibraryEntry(propertyName, preferences.getString(propertyName), false, false); >- } catch (JavaModelException e) { >- // won't happen: no rebinding >+ try { >+ String[] propertyNames = instancePreferences.keys(); >+ for (int i = 0; i < propertyNames.length; i++) { >+ String propertyName = propertyNames[i]; >+ if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) { >+ try { >+ String propertyValue = instancePreferences.get(propertyName, null); >+ if (propertyValue != null) >+ recreatePersistedUserLibraryEntry(propertyName,propertyValue, false, false); >+ } catch (JavaModelException e) { >+ // won't happen: no rebinding >+ } > } > } >+ } catch (BackingStoreException e) { >+ // TODO (frederic) see if it's necessary to report this exception > } > } > return userLibraries; >@@ -178,7 +182,7 @@ > } > } > >- Preferences preferences = JavaCore.getPlugin().getPluginPreferences(); >+ IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences(); > String containerKey = CP_USERLIBRARY_PREFERENCES_PREFIX+name; > String containerString = CP_ENTRY_IGNORE; > if (library != null) { >@@ -188,19 +192,23 @@ > // could not encode entry: leave it as CP_ENTRY_IGNORE > } > } >- preferences.removePropertyChangeListener(listener); >+ instancePreferences.removePreferenceChangeListener(listener); > try { >- preferences.setDefault(containerKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones >- preferences.setValue(containerKey, containerString); >+ JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary... >+ instancePreferences.put(containerKey, containerString); > if (save) { >- JavaCore.getPlugin().savePluginPreferences(); >+ try { >+ instancePreferences.flush(); >+ } catch (BackingStoreException e) { >+ // TODO (frederic) see if it's necessary to report this exception >+ } > } > if (rebind) { > rebindClasspathEntries(name, monitor); > } > > } finally { >- preferences.addPropertyChangeListener(listener); >+ instancePreferences.addPreferenceChangeListener(listener); > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 59258
: 10314 |
10315