View | Details | Raw Unified | Return to bug 59258 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/core/JavaCore.java (-102 / +188 lines)
Lines 58-76 Link Here
58
package org.eclipse.jdt.core;
58
package org.eclipse.jdt.core;
59
59
60
import java.io.File;
60
import java.io.File;
61
import java.util.*;
61
import java.util.Enumeration;
62
62
import java.util.HashMap;
63
import org.eclipse.core.resources.*;
63
import java.util.HashSet;
64
import org.eclipse.core.runtime.*;
64
import java.util.Hashtable;
65
import java.util.Iterator;
66
import java.util.Map;
67
68
import org.eclipse.core.resources.IContainer;
69
import org.eclipse.core.resources.IFile;
70
import org.eclipse.core.resources.IFolder;
71
import org.eclipse.core.resources.IMarker;
72
import org.eclipse.core.resources.IMarkerDelta;
73
import org.eclipse.core.resources.IProject;
74
import org.eclipse.core.resources.IResource;
75
import org.eclipse.core.resources.IResourceChangeEvent;
76
import org.eclipse.core.resources.IResourceChangeListener;
77
import org.eclipse.core.resources.ISavedState;
78
import org.eclipse.core.resources.IWorkspace;
79
import org.eclipse.core.resources.IWorkspaceRoot;
80
import org.eclipse.core.resources.IWorkspaceRunnable;
81
import org.eclipse.core.resources.ResourcesPlugin;
82
import org.eclipse.core.runtime.CoreException;
83
import org.eclipse.core.runtime.IConfigurationElement;
84
import org.eclipse.core.runtime.IExtension;
85
import org.eclipse.core.runtime.IExtensionPoint;
86
import org.eclipse.core.runtime.IPath;
87
import org.eclipse.core.runtime.IProgressMonitor;
88
import org.eclipse.core.runtime.Platform;
89
import org.eclipse.core.runtime.Plugin;
65
import org.eclipse.core.runtime.jobs.ISchedulingRule;
90
import org.eclipse.core.runtime.jobs.ISchedulingRule;
91
import org.eclipse.core.runtime.preferences.DefaultScope;
92
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
93
import org.eclipse.core.runtime.preferences.IPreferencesService;
94
import org.eclipse.core.runtime.preferences.InstanceScope;
66
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
95
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
67
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
96
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
68
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
97
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
69
import org.eclipse.jdt.internal.core.*;
98
import org.eclipse.jdt.internal.core.Assert;
99
import org.eclipse.jdt.internal.core.BatchOperation;
100
import org.eclipse.jdt.internal.core.BufferFactoryWrapper;
101
import org.eclipse.jdt.internal.core.BufferManager;
102
import org.eclipse.jdt.internal.core.ClasspathEntry;
103
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
104
import org.eclipse.jdt.internal.core.JavaModel;
105
import org.eclipse.jdt.internal.core.JavaModelManager;
106
import org.eclipse.jdt.internal.core.JavaProject;
107
import org.eclipse.jdt.internal.core.Region;
108
import org.eclipse.jdt.internal.core.SetClasspathOperation;
109
import org.eclipse.jdt.internal.core.UserLibraryManager;
70
import org.eclipse.jdt.internal.core.search.processing.IJob;
110
import org.eclipse.jdt.internal.core.search.processing.IJob;
71
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
111
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
72
import org.eclipse.jdt.internal.core.util.Util;
112
import org.eclipse.jdt.internal.core.util.Util;
73
import org.osgi.framework.BundleContext;
113
import org.osgi.framework.BundleContext;
114
import org.osgi.service.prefs.BackingStoreException;
74
115
75
/**
116
/**
76
 * The plug-in runtime class for the Java model plug-in containing the core
117
 * The plug-in runtime class for the Java model plug-in containing the core
Lines 880-885 Link Here
880
	public static final String PRIVATE = "private"; //$NON-NLS-1$
921
	public static final String PRIVATE = "private"; //$NON-NLS-1$
881
	
922
	
882
	/**
923
	/**
924
	 * New Preferences API
925
	 * @since 3.1
926
	 */
927
	public static final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
928
	static final int PREF_INSTANCE = 0;
929
	static final int PREF_DEFAULT = 1;
930
931
	/**
883
	 * Creates the Java core plug-in.
932
	 * Creates the Java core plug-in.
884
	 * <p>
933
	 * <p>
885
	 * The plug-in instance is created automatically by the 
934
	 * The plug-in instance is created automatically by the 
Lines 969-975 Link Here
969
	 * </p>
1018
	 * </p>
970
	 * 
1019
	 * 
971
	 * @param listener the listener
1020
	 * @param listener the listener
972
	 * @see #removePreResourceChangeListener(IResourceChangeListener)
1021
	 * @see #removePreProcessingResourceChangedListener(IResourceChangeListener)
973
	 * @since 3.0
1022
	 * @since 3.0
974
	 */
1023
	 */
975
	public static void addPreProcessingResourceChangedListener(IResourceChangeListener listener) {
1024
	public static void addPreProcessingResourceChangedListener(IResourceChangeListener listener) {
Lines 2126-2139 Link Here
2126
		Hashtable defaultOptions = new Hashtable(10);
2175
		Hashtable defaultOptions = new Hashtable(10);
2127
2176
2128
		// see #initializeDefaultPluginPreferences() for changing default settings
2177
		// see #initializeDefaultPluginPreferences() for changing default settings
2129
		Preferences preferences = getPlugin().getPluginPreferences();
2178
		IEclipsePreferences defaultPreferences = getDefaultPreferences();
2130
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2179
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2131
		
2180
		
2132
		// initialize preferences to their default
2181
		// initialize preferences to their default
2133
		Iterator iterator = optionNames.iterator();
2182
		Iterator iterator = optionNames.iterator();
2134
		while (iterator.hasNext()) {
2183
		while (iterator.hasNext()) {
2135
		    String propertyName = (String) iterator.next();
2184
		    String propertyName = (String) iterator.next();
2136
		    defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
2185
		    String value = defaultPreferences.get(propertyName, null);
2186
		    if (value != null) defaultOptions.put(propertyName, value);
2137
		}
2187
		}
2138
		// get encoding through resource plugin
2188
		// get encoding through resource plugin
2139
		defaultOptions.put(CORE_ENCODING, getEncoding());
2189
		defaultOptions.put(CORE_ENCODING, getEncoding());
Lines 2143-2148 Link Here
2143
		
2193
		
2144
		return defaultOptions;
2194
		return defaultOptions;
2145
	}
2195
	}
2196
 
2197
	/**
2198
	 * @since 3.1
2199
	 */
2200
	public static IEclipsePreferences getInstancePreferences() {
2201
		if (preferencesLookup[PREF_INSTANCE] == null) {
2202
			preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID);
2203
		}
2204
		return preferencesLookup[PREF_INSTANCE];
2205
	}
2206
 
2207
	/**
2208
	 * @since 3.1
2209
	 */
2210
	public static IEclipsePreferences getDefaultPreferences() {
2211
		if (preferencesLookup[PREF_DEFAULT] == null) {
2212
			preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID);
2213
		}
2214
		return preferencesLookup[PREF_DEFAULT];
2215
	}
2146
2216
2147
	/**
2217
	/**
2148
	 * Returns the workspace root default charset encoding.
2218
	 * Returns the workspace root default charset encoding.
Lines 2153-2164 Link Here
2153
	 * @since 3.0
2223
	 * @since 3.0
2154
	 */
2224
	 */
2155
	public static String getEncoding() {
2225
	public static String getEncoding() {
2156
		try {
2226
		// Verify that workspace is not shutting down (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=60687)
2157
			return ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset();
2227
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
2158
		} catch (Exception e) {
2228
		if (workspace != null) {
2159
			// fails silently and return plugin global encoding if core exception occurs or
2229
			try {
2160
			// if workspace is shutting down (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=60687)
2230
				return workspace.getRoot().getDefaultCharset();
2161
		} 
2231
			} catch (CoreException e) {
2232
				// fails silently and return plugin global encoding if core exception occurs
2233
			}
2234
		}
2162
		return ResourcesPlugin.getEncoding();
2235
		return ResourcesPlugin.getEncoding();
2163
	}
2236
	}
2164
2237
Lines 2182-2187 Link Here
2182
	 * @param optionName the name of an option
2255
	 * @param optionName the name of an option
2183
	 * @return the String value of a given option
2256
	 * @return the String value of a given option
2184
	 * @see JavaCore#getDefaultOptions()
2257
	 * @see JavaCore#getDefaultOptions()
2258
	 * @see #initializeDefaultPreferences() for changing default settings
2185
	 * @since 2.0
2259
	 * @since 2.0
2186
	 */
2260
	 */
2187
	public static String getOption(String optionName) {
2261
	public static String getOption(String optionName) {
Lines 2196-2203 Link Here
2196
		}
2270
		}
2197
		String propertyName = optionName;
2271
		String propertyName = optionName;
2198
		if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){
2272
		if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){
2199
			Preferences preferences = getPlugin().getPluginPreferences();
2273
			IPreferencesService service = Platform.getPreferencesService();
2200
			return preferences.getString(propertyName).trim();
2274
			String value =  service.get(optionName, null, preferencesLookup);
2275
			return value==null ? null : value.trim();
2201
		}
2276
		}
2202
		return null;
2277
		return null;
2203
	}
2278
	}
Lines 2211-2249 Link Here
2211
	 * 
2286
	 * 
2212
	 * @return table of current settings of all options 
2287
	 * @return table of current settings of all options 
2213
	 *   (key type: <code>String</code>; value type: <code>String</code>)
2288
	 *   (key type: <code>String</code>; value type: <code>String</code>)
2214
	 * @see JavaCore#getDefaultOptions()
2289
	 * @see #getDefaultOptions()
2290
	 * @see #initializeDefaultPreferences() for changing default settings
2215
	 */
2291
	 */
2216
	public static Hashtable getOptions() {
2292
	public static Hashtable getOptions() {
2217
		
2293
2294
		// init
2218
		Hashtable options = new Hashtable(10);
2295
		Hashtable options = new Hashtable(10);
2296
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2297
		IPreferencesService service = Platform.getPreferencesService();
2219
2298
2220
		// see #initializeDefaultPluginPreferences() for changing default settings
2299
		// set options using preferences service lookup
2221
		Plugin plugin = getPlugin();
2300
		Iterator iterator = optionNames.iterator();
2222
		if (plugin != null) {
2301
		while (iterator.hasNext()) {
2223
			Preferences preferences = getPlugin().getPluginPreferences();
2302
		    String propertyName = (String) iterator.next();
2224
			HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2303
		    String propertyValue = service.get(propertyName, null, preferencesLookup);
2225
			
2304
		    if (propertyValue != null) {
2226
			// initialize preferences to their default
2305
			    options.put(propertyName, propertyValue);
2227
			Iterator iterator = optionNames.iterator();
2306
		    }
2228
			while (iterator.hasNext()) {
2229
			    String propertyName = (String) iterator.next();
2230
			    options.put(propertyName, preferences.getDefaultString(propertyName));
2231
			}
2232
			// get preferences not set to their default
2233
			String[] propertyNames = preferences.propertyNames();
2234
			for (int i = 0; i < propertyNames.length; i++){
2235
				String propertyName = propertyNames[i];
2236
				String value = preferences.getString(propertyName).trim();
2237
				if (optionNames.contains(propertyName)){
2238
					options.put(propertyName, value);
2239
				}
2240
			}
2241
			// get encoding through resource plugin
2242
			options.put(CORE_ENCODING, getEncoding()); 
2243
			// backward compatibility
2244
			options.put(COMPILER_PB_INVALID_IMPORT, ERROR);
2245
			options.put(COMPILER_PB_UNREACHABLE_CODE, ERROR);
2246
		}
2307
		}
2308
2309
		// get encoding through resource plugin
2310
		options.put(CORE_ENCODING, getEncoding()); 
2311
2312
		// backward compatibility
2313
		options.put(COMPILER_PB_INVALID_IMPORT, ERROR);
2314
		options.put(COMPILER_PB_UNREACHABLE_CODE, ERROR);
2315
2316
		// return built map
2247
		return options;
2317
		return options;
2248
	}
2318
	}
2249
2319
Lines 2423-2435 Link Here
2423
		if (result == null) return JavaModelManager.NO_WORKING_COPY;
2493
		if (result == null) return JavaModelManager.NO_WORKING_COPY;
2424
		return result;
2494
		return result;
2425
	}
2495
	}
2426
		
2496
2427
	/**
2497
	/*
2428
	 * Initializes the default preferences settings for this plug-in.
2498
	 * Initializes the default preferences settings for this plug-in.
2429
	 */
2499
	 */
2430
	protected void initializeDefaultPluginPreferences() {
2500
	protected void initializeDefaultPreferences() {
2501
		
2502
		// Init and store default and instance preferences
2503
		IEclipsePreferences defaultPreferences = getDefaultPreferences();
2431
		
2504
		
2432
		Preferences preferences = getPluginPreferences();
2433
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2505
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2434
		
2506
		
2435
		// Compiler settings
2507
		// Compiler settings
Lines 2437-2483 Link Here
2437
		for (Iterator iter = compilerOptionsMap.entrySet().iterator(); iter.hasNext();) {
2509
		for (Iterator iter = compilerOptionsMap.entrySet().iterator(); iter.hasNext();) {
2438
			Map.Entry entry = (Map.Entry) iter.next();
2510
			Map.Entry entry = (Map.Entry) iter.next();
2439
			String optionName = (String) entry.getKey();
2511
			String optionName = (String) entry.getKey();
2440
			preferences.setDefault(optionName, (String)entry.getValue());
2512
			defaultPreferences.put(optionName, (String)entry.getValue());
2441
			optionNames.add(optionName);
2513
			optionNames.add(optionName);
2442
		}
2514
		}
2443
		// override some compiler defaults
2515
		// override some compiler defaults
2444
		preferences.setDefault(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
2516
		defaultPreferences.put(COMPILER_LOCAL_VARIABLE_ATTR, GENERATE);
2445
		preferences.setDefault(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE);
2517
		defaultPreferences.put(COMPILER_CODEGEN_UNUSED_LOCAL, PRESERVE);
2446
		preferences.setDefault(COMPILER_TASK_TAGS, DEFAULT_TASK_TAGS);
2518
		defaultPreferences.put(COMPILER_TASK_TAGS, DEFAULT_TASK_TAGS);
2447
		preferences.setDefault(COMPILER_TASK_PRIORITIES, DEFAULT_TASK_PRIORITIES);
2519
		defaultPreferences.put(COMPILER_TASK_PRIORITIES, DEFAULT_TASK_PRIORITIES);
2448
		preferences.setDefault(COMPILER_TASK_CASE_SENSITIVE, ENABLED);
2520
		defaultPreferences.put(COMPILER_TASK_CASE_SENSITIVE, ENABLED);
2449
		preferences.setDefault(COMPILER_DOC_COMMENT_SUPPORT, ENABLED);
2521
		defaultPreferences.put(COMPILER_DOC_COMMENT_SUPPORT, ENABLED);
2450
2522
2451
		// Builder settings
2523
		// Builder settings
2452
		preferences.setDefault(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
2524
		defaultPreferences.put(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
2453
		optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
2525
		optionNames.add(CORE_JAVA_BUILD_RESOURCE_COPY_FILTER);
2454
2526
2455
		preferences.setDefault(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); 
2527
		defaultPreferences.put(CORE_JAVA_BUILD_INVALID_CLASSPATH, ABORT); 
2456
		optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
2528
		optionNames.add(CORE_JAVA_BUILD_INVALID_CLASSPATH);
2457
	
2529
	
2458
		preferences.setDefault(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); 
2530
		defaultPreferences.put(CORE_JAVA_BUILD_DUPLICATE_RESOURCE, WARNING); 
2459
		optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
2531
		optionNames.add(CORE_JAVA_BUILD_DUPLICATE_RESOURCE);
2460
		
2532
		
2461
		preferences.setDefault(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); 
2533
		defaultPreferences.put(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, CLEAN); 
2462
		optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
2534
		optionNames.add(CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER);
2463
2535
2464
		// JavaCore settings
2536
		// JavaCore settings
2465
		preferences.setDefault(CORE_JAVA_BUILD_ORDER, IGNORE); 
2537
		defaultPreferences.put(CORE_JAVA_BUILD_ORDER, IGNORE); 
2466
		optionNames.add(CORE_JAVA_BUILD_ORDER);
2538
		optionNames.add(CORE_JAVA_BUILD_ORDER);
2467
	
2539
	
2468
		preferences.setDefault(CORE_INCOMPLETE_CLASSPATH, ERROR); 
2540
		defaultPreferences.put(CORE_INCOMPLETE_CLASSPATH, ERROR); 
2469
		optionNames.add(CORE_INCOMPLETE_CLASSPATH);
2541
		optionNames.add(CORE_INCOMPLETE_CLASSPATH);
2470
		
2542
		
2471
		preferences.setDefault(CORE_CIRCULAR_CLASSPATH, ERROR); 
2543
		defaultPreferences.put(CORE_CIRCULAR_CLASSPATH, ERROR); 
2472
		optionNames.add(CORE_CIRCULAR_CLASSPATH);
2544
		optionNames.add(CORE_CIRCULAR_CLASSPATH);
2473
		
2545
		
2474
		preferences.setDefault(CORE_INCOMPATIBLE_JDK_LEVEL, IGNORE); 
2546
		defaultPreferences.put(CORE_INCOMPATIBLE_JDK_LEVEL, IGNORE); 
2475
		optionNames.add(CORE_INCOMPATIBLE_JDK_LEVEL);
2547
		optionNames.add(CORE_INCOMPATIBLE_JDK_LEVEL);
2476
		
2548
		
2477
		preferences.setDefault(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, ENABLED); 
2549
		defaultPreferences.put(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, ENABLED); 
2478
		optionNames.add(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS);
2550
		optionNames.add(CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS);
2479
2551
2480
		preferences.setDefault(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, ENABLED); 
2552
		defaultPreferences.put(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, ENABLED); 
2481
		optionNames.add(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS);
2553
		optionNames.add(CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS);
2482
2554
2483
		// encoding setting comes from resource plug-in
2555
		// encoding setting comes from resource plug-in
Lines 2488-2555 Link Here
2488
		for (Iterator iter = codeFormatterOptionsMap.entrySet().iterator(); iter.hasNext();) {
2560
		for (Iterator iter = codeFormatterOptionsMap.entrySet().iterator(); iter.hasNext();) {
2489
			Map.Entry entry = (Map.Entry) iter.next();
2561
			Map.Entry entry = (Map.Entry) iter.next();
2490
			String optionName = (String) entry.getKey();
2562
			String optionName = (String) entry.getKey();
2491
			preferences.setDefault(optionName, (String)entry.getValue());
2563
			defaultPreferences.put(optionName, (String)entry.getValue());
2492
			optionNames.add(optionName);
2564
			optionNames.add(optionName);
2493
		}		
2565
		}		
2494
		preferences.setDefault(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT); 
2566
		defaultPreferences.put(FORMATTER_NEWLINE_OPENING_BRACE, DO_NOT_INSERT); 
2495
		optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE);
2567
		optionNames.add(FORMATTER_NEWLINE_OPENING_BRACE);
2496
2568
2497
		preferences.setDefault(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT);
2569
		defaultPreferences.put(FORMATTER_NEWLINE_CONTROL, DO_NOT_INSERT);
2498
		optionNames.add(FORMATTER_NEWLINE_CONTROL);
2570
		optionNames.add(FORMATTER_NEWLINE_CONTROL);
2499
2571
2500
		preferences.setDefault(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE); 
2572
		defaultPreferences.put(FORMATTER_CLEAR_BLANK_LINES, PRESERVE_ONE); 
2501
		optionNames.add(FORMATTER_CLEAR_BLANK_LINES);
2573
		optionNames.add(FORMATTER_CLEAR_BLANK_LINES);
2502
2574
2503
		preferences.setDefault(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT);
2575
		defaultPreferences.put(FORMATTER_NEWLINE_ELSE_IF, DO_NOT_INSERT);
2504
		optionNames.add(FORMATTER_NEWLINE_ELSE_IF);
2576
		optionNames.add(FORMATTER_NEWLINE_ELSE_IF);
2505
2577
2506
		preferences.setDefault(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT); 
2578
		defaultPreferences.put(FORMATTER_NEWLINE_EMPTY_BLOCK, INSERT); 
2507
		optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK);
2579
		optionNames.add(FORMATTER_NEWLINE_EMPTY_BLOCK);
2508
2580
2509
		preferences.setDefault(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
2581
		defaultPreferences.put(FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
2510
		optionNames.add(FORMATTER_LINE_SPLIT);
2582
		optionNames.add(FORMATTER_LINE_SPLIT);
2511
2583
2512
		preferences.setDefault(FORMATTER_COMPACT_ASSIGNMENT, NORMAL); 
2584
		defaultPreferences.put(FORMATTER_COMPACT_ASSIGNMENT, NORMAL); 
2513
		optionNames.add(FORMATTER_COMPACT_ASSIGNMENT);
2585
		optionNames.add(FORMATTER_COMPACT_ASSIGNMENT);
2514
2586
2515
		preferences.setDefault(FORMATTER_TAB_CHAR, TAB); 
2587
		defaultPreferences.put(FORMATTER_TAB_CHAR, TAB); 
2516
		optionNames.add(FORMATTER_TAB_CHAR);
2588
		optionNames.add(FORMATTER_TAB_CHAR);
2517
2589
2518
		preferences.setDefault(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ 
2590
		defaultPreferences.put(FORMATTER_TAB_SIZE, "4"); //$NON-NLS-1$ 
2519
		optionNames.add(FORMATTER_TAB_SIZE);
2591
		optionNames.add(FORMATTER_TAB_SIZE);
2520
		
2592
		
2521
		preferences.setDefault(FORMATTER_SPACE_CASTEXPRESSION, INSERT); //$NON-NLS-1$ 
2593
		defaultPreferences.put(FORMATTER_SPACE_CASTEXPRESSION, INSERT); //$NON-NLS-1$ 
2522
		optionNames.add(FORMATTER_SPACE_CASTEXPRESSION);
2594
		optionNames.add(FORMATTER_SPACE_CASTEXPRESSION);
2523
2595
2524
		// CodeAssist settings
2596
		// CodeAssist settings
2525
		preferences.setDefault(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
2597
		defaultPreferences.put(CODEASSIST_VISIBILITY_CHECK, DISABLED); //$NON-NLS-1$
2526
		optionNames.add(CODEASSIST_VISIBILITY_CHECK);
2598
		optionNames.add(CODEASSIST_VISIBILITY_CHECK);
2527
2599
2528
		preferences.setDefault(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
2600
		defaultPreferences.put(CODEASSIST_IMPLICIT_QUALIFICATION, DISABLED); //$NON-NLS-1$
2529
		optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
2601
		optionNames.add(CODEASSIST_IMPLICIT_QUALIFICATION);
2530
		
2602
		
2531
		preferences.setDefault(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
2603
		defaultPreferences.put(CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
2532
		optionNames.add(CODEASSIST_FIELD_PREFIXES);
2604
		optionNames.add(CODEASSIST_FIELD_PREFIXES);
2533
		
2605
		
2534
		preferences.setDefault(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
2606
		defaultPreferences.put(CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
2535
		optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
2607
		optionNames.add(CODEASSIST_STATIC_FIELD_PREFIXES);
2536
		
2608
		
2537
		preferences.setDefault(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
2609
		defaultPreferences.put(CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
2538
		optionNames.add(CODEASSIST_LOCAL_PREFIXES);
2610
		optionNames.add(CODEASSIST_LOCAL_PREFIXES);
2539
		
2611
		
2540
		preferences.setDefault(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
2612
		defaultPreferences.put(CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
2541
		optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
2613
		optionNames.add(CODEASSIST_ARGUMENT_PREFIXES);
2542
		
2614
		
2543
		preferences.setDefault(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2615
		defaultPreferences.put(CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2544
		optionNames.add(CODEASSIST_FIELD_SUFFIXES);
2616
		optionNames.add(CODEASSIST_FIELD_SUFFIXES);
2545
		
2617
		
2546
		preferences.setDefault(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2618
		defaultPreferences.put(CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
2547
		optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
2619
		optionNames.add(CODEASSIST_STATIC_FIELD_SUFFIXES);
2548
		
2620
		
2549
		preferences.setDefault(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
2621
		defaultPreferences.put(CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
2550
		optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
2622
		optionNames.add(CODEASSIST_LOCAL_SUFFIXES);
2551
		
2623
		
2552
		preferences.setDefault(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
2624
		defaultPreferences.put(CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
2553
		optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);
2625
		optionNames.add(CODEASSIST_ARGUMENT_SUFFIXES);
2554
	}
2626
	}
2555
	
2627
	
Lines 3647-3672 Link Here
3647
	 * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
3719
	 * @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>),
3648
	 *   or <code>null</code> to reset all options to their default values
3720
	 *   or <code>null</code> to reset all options to their default values
3649
	 * @see JavaCore#getDefaultOptions()
3721
	 * @see JavaCore#getDefaultOptions()
3722
	 * @see #initializeDefaultPreferences() for changing default settings
3650
	 */
3723
	 */
3651
	public static void setOptions(Hashtable newOptions) {
3724
	public static void setOptions(Hashtable newOptions) {
3652
		
3725
		
3653
		// see #initializeDefaultPluginPreferences() for changing default settings
3726
		try {
3654
		Preferences preferences = getPlugin().getPluginPreferences();
3727
			IEclipsePreferences defaultPreferences = getDefaultPreferences();
3728
			IEclipsePreferences instancePreferences = getInstancePreferences();
3655
3729
3656
		if (newOptions == null){
3730
			if (newOptions == null){
3657
			newOptions = JavaCore.getDefaultOptions();
3731
				instancePreferences.clear();
3658
		}
3732
			} else {
3659
		Enumeration keys = newOptions.keys();
3733
				Enumeration keys = newOptions.keys();
3660
		while (keys.hasMoreElements()){
3734
				while (keys.hasMoreElements()){
3661
			String key = (String)keys.nextElement();
3735
					String key = (String)keys.nextElement();
3662
			if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option
3736
					if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option
3663
			if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs
3737
					if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs
3664
			String value = (String)newOptions.get(key);
3738
					String value = (String)newOptions.get(key);
3665
			preferences.setValue(key, value);
3739
					String defaultValue = defaultPreferences.get(key, null);
3666
		}
3740
					if (defaultValue != null && defaultValue.equals(value)) {
3741
						instancePreferences.remove(key);
3742
					} else {
3743
						instancePreferences.put(key, value);
3744
					}
3745
				}
3746
			}
3667
3747
3668
		// persist options
3748
			// persist options
3669
		getPlugin().savePluginPreferences();
3749
			instancePreferences.flush();
3750
		} catch (BackingStoreException e) {
3751
			// fails silently
3752
		}
3670
	}
3753
	}
3671
3754
3672
	/* (non-Javadoc)
3755
	/* (non-Javadoc)
Lines 3711-3716 Link Here
3711
	public void start(BundleContext context) throws Exception {
3794
	public void start(BundleContext context) throws Exception {
3712
		super.start(context);
3795
		super.start(context);
3713
		
3796
		
3797
		// init preferences
3798
		initializeDefaultPreferences();
3799
3714
		final JavaModelManager manager = JavaModelManager.getJavaModelManager();
3800
		final JavaModelManager manager = JavaModelManager.getJavaModelManager();
3715
		try {
3801
		try {
3716
			manager.configurePluginDebugOptions();
3802
			manager.configurePluginDebugOptions();
Lines 3719-3725 Link Here
3719
			JavaCore.getPlugin().getStateLocation();
3805
			JavaCore.getPlugin().getStateLocation();
3720
3806
3721
			// retrieve variable values
3807
			// retrieve variable values
3722
			JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new JavaModelManager.PluginPreferencesListener());
3808
			getInstancePreferences().addPreferenceChangeListener(new JavaModelManager.EclipsePreferencesListener());
3723
			manager.loadVariablesAndContainers();
3809
			manager.loadVariablesAndContainers();
3724
3810
3725
			final IWorkspace workspace = ResourcesPlugin.getWorkspace();
3811
			final IWorkspace workspace = ResourcesPlugin.getWorkspace();
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-59 / +2 lines)
Lines 31-37 Link Here
31
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IPath;
32
import org.eclipse.core.runtime.IPath;
33
import org.eclipse.core.runtime.IProgressMonitor;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.Preferences;
35
import org.eclipse.jdt.core.*;
34
import org.eclipse.jdt.core.*;
36
import org.eclipse.jdt.core.ElementChangedEvent;
35
import org.eclipse.jdt.core.ElementChangedEvent;
37
import org.eclipse.jdt.core.IClasspathEntry;
36
import org.eclipse.jdt.core.IClasspathEntry;
Lines 912-917 Link Here
912
			}
911
			}
913
			this.removeFromParentInfo(javaProject);
912
			this.removeFromParentInfo(javaProject);
914
913
914
			// remove preferences from per project info
915
			this.manager.resetProjectPreferences(javaProject);	
915
		} catch (JavaModelException e) {
916
		} catch (JavaModelException e) {
916
			// java project doesn't exist: ignore
917
			// java project doesn't exist: ignore
917
		}
918
		}
Lines 1719-1783 Link Here
1719
				}
1720
				}
1720
		}
1721
		}
1721
	}
1722
	}
1722
	/*
1723
	 * Update the JavaModel according to a .jprefs file change. The file can have changed as a result of a previous
1724
	 * call to JavaProject#setOptions or as a result of some user update (through repository)
1725
	 * Unused until preference file get shared (.jpref)
1726
	 */
1727
	void reconcilePreferenceFileUpdate(IResourceDelta delta, IFile file, JavaProject project) {
1728
			
1729
		switch (delta.getKind()) {
1730
			case IResourceDelta.REMOVED : // flush project custom settings
1731
				project.setOptions(null);
1732
				return;
1733
			case IResourceDelta.CHANGED :
1734
				if ((delta.getFlags() & IResourceDelta.CONTENT) == 0  // only consider content change
1735
						&& (delta.getFlags() & IResourceDelta.MOVED_FROM) == 0) // and also move and overide scenario
1736
					break;
1737
				identityCheck : { // check if any actual difference
1738
					// force to (re)read the property file
1739
					Preferences filePreferences = project.loadPreferences();
1740
					if (filePreferences == null){ 
1741
						project.setOptions(null); // should have got removed delta.
1742
						return;
1743
					}
1744
					Preferences projectPreferences = project.getPreferences();
1745
					if (projectPreferences == null) return; // not a Java project
1746
						
1747
					// compare preferences set to their default
1748
					String[] defaultProjectPropertyNames = projectPreferences.defaultPropertyNames();
1749
					String[] defaultFilePropertyNames = filePreferences.defaultPropertyNames();
1750
					if (defaultProjectPropertyNames.length == defaultFilePropertyNames.length) {
1751
						for (int i = 0; i < defaultProjectPropertyNames.length; i++){
1752
							String propertyName = defaultProjectPropertyNames[i];
1753
							if (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){
1754
								break identityCheck;
1755
							}
1756
						}		
1757
					} else break identityCheck;
1758
1723
1759
					// compare custom preferences not set to their default
1760
					String[] projectPropertyNames = projectPreferences.propertyNames();
1761
					String[] filePropertyNames = filePreferences.propertyNames();
1762
					if (projectPropertyNames.length == filePropertyNames.length) {
1763
						for (int i = 0; i < projectPropertyNames.length; i++){
1764
						String propertyName = projectPropertyNames[i];
1765
							if (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){
1766
								break identityCheck;
1767
							}
1768
						}		
1769
					} else break identityCheck;
1770
					
1771
					// identical - do nothing
1772
					return;
1773
				}
1774
			case IResourceDelta.ADDED :
1775
				// not identical, create delta and reset cached preferences
1776
				project.setPreferences(null);
1777
				// create delta
1778
				//fCurrentDelta.changed(project, IJavaElementDelta.F_OPTIONS_CHANGED);				
1779
		}
1780
	}
1781
	/*
1724
	/*
1782
	 * Traverse the set of projects which have changed namespace, and reset their 
1725
	 * Traverse the set of projects which have changed namespace, and reset their 
1783
	 * caches and their dependents
1726
	 * caches and their dependents
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-48 / +125 lines)
Lines 10-27 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.io.*;
13
import java.io.BufferedInputStream;
14
import java.io.BufferedOutputStream;
15
import java.io.DataInputStream;
16
import java.io.DataOutputStream;
17
import java.io.File;
18
import java.io.FileInputStream;
19
import java.io.FileOutputStream;
20
import java.io.IOException;
21
import java.io.StringReader;
14
import java.text.NumberFormat;
22
import java.text.NumberFormat;
15
import java.util.*;
23
import java.util.ArrayList;
24
import java.util.HashMap;
25
import java.util.HashSet;
26
import java.util.Iterator;
27
import java.util.Map;
28
import java.util.WeakHashMap;
16
import java.util.zip.ZipFile;
29
import java.util.zip.ZipFile;
17
18
import javax.xml.parsers.DocumentBuilder;
30
import javax.xml.parsers.DocumentBuilder;
19
import javax.xml.parsers.DocumentBuilderFactory;
31
import javax.xml.parsers.DocumentBuilderFactory;
20
import javax.xml.parsers.ParserConfigurationException;
32
import javax.xml.parsers.ParserConfigurationException;
21
33
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.*;
34
import org.eclipse.core.resources.IFolder;
23
import org.eclipse.core.runtime.*;
35
import org.eclipse.core.resources.IProject;
24
import org.eclipse.jdt.core.*;
36
import org.eclipse.core.resources.IResource;
37
import org.eclipse.core.resources.ISaveContext;
38
import org.eclipse.core.resources.ISaveParticipant;
39
import org.eclipse.core.resources.IWorkspace;
40
import org.eclipse.core.resources.IWorkspaceDescription;
41
import org.eclipse.core.resources.IWorkspaceRoot;
42
import org.eclipse.core.resources.ResourcesPlugin;
43
import org.eclipse.core.runtime.CoreException;
44
import org.eclipse.core.runtime.IConfigurationElement;
45
import org.eclipse.core.runtime.IExtension;
46
import org.eclipse.core.runtime.IExtensionPoint;
47
import org.eclipse.core.runtime.IPath;
48
import org.eclipse.core.runtime.IProgressMonitor;
49
import org.eclipse.core.runtime.IStatus;
50
import org.eclipse.core.runtime.MultiStatus;
51
import org.eclipse.core.runtime.Path;
52
import org.eclipse.core.runtime.Platform;
53
import org.eclipse.core.runtime.Plugin;
54
import org.eclipse.core.runtime.QualifiedName;
55
import org.eclipse.core.runtime.Status;
56
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
57
import org.eclipse.jdt.core.IClassFile;
58
import org.eclipse.jdt.core.IClasspathContainer;
59
import org.eclipse.jdt.core.IClasspathEntry;
60
import org.eclipse.jdt.core.ICompilationUnit;
61
import org.eclipse.jdt.core.IJavaElement;
62
import org.eclipse.jdt.core.IJavaProject;
63
import org.eclipse.jdt.core.IPackageFragment;
64
import org.eclipse.jdt.core.IPackageFragmentRoot;
65
import org.eclipse.jdt.core.IParent;
66
import org.eclipse.jdt.core.IProblemRequestor;
67
import org.eclipse.jdt.core.JavaConventions;
68
import org.eclipse.jdt.core.JavaCore;
69
import org.eclipse.jdt.core.JavaModelException;
70
import org.eclipse.jdt.core.WorkingCopyOwner;
25
import org.eclipse.jdt.core.compiler.IProblem;
71
import org.eclipse.jdt.core.compiler.IProblem;
26
import org.eclipse.jdt.core.search.SearchEngine;
72
import org.eclipse.jdt.core.search.SearchEngine;
27
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
73
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
Lines 33-38 Link Here
33
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
79
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
34
import org.eclipse.jdt.internal.core.search.processing.JobManager;
80
import org.eclipse.jdt.internal.core.search.processing.JobManager;
35
import org.eclipse.jdt.internal.core.util.Util;
81
import org.eclipse.jdt.internal.core.util.Util;
82
import org.osgi.service.prefs.BackingStoreException;
36
import org.w3c.dom.Element;
83
import org.w3c.dom.Element;
37
import org.w3c.dom.Node;
84
import org.w3c.dom.Node;
38
import org.w3c.dom.NodeList;
85
import org.w3c.dom.NodeList;
Lines 497-503 Link Here
497
		public IClasspathEntry[] resolvedClasspath;
544
		public IClasspathEntry[] resolvedClasspath;
498
		public Map resolvedPathToRawEntries; // reverse map from resolved path to raw entries
545
		public Map resolvedPathToRawEntries; // reverse map from resolved path to raw entries
499
		public IPath outputLocation;
546
		public IPath outputLocation;
500
		public Preferences preferences;
547
		public IEclipsePreferences preferences;
501
		
548
		
502
		public PerProjectInfo(IProject project) {
549
		public PerProjectInfo(IProject project) {
503
550
Lines 576-582 Link Here
576
		public String toString() {
623
		public String toString() {
577
			StringBuffer buffer = new StringBuffer();
624
			StringBuffer buffer = new StringBuffer();
578
			buffer.append("Info for "); //$NON-NLS-1$
625
			buffer.append("Info for "); //$NON-NLS-1$
579
			buffer.append(((JavaElement)workingCopy).toStringWithAncestors());
626
			buffer.append(((JavaElement)this.workingCopy).toStringWithAncestors());
580
			buffer.append("\nUse count = "); //$NON-NLS-1$
627
			buffer.append("\nUse count = "); //$NON-NLS-1$
581
			buffer.append(this.useCount);
628
			buffer.append(this.useCount);
582
			buffer.append("\nProblem requestor:\n  "); //$NON-NLS-1$
629
			buffer.append("\nProblem requestor:\n  "); //$NON-NLS-1$
Lines 599-611 Link Here
599
	/**
646
	/**
600
	 * Update the classpath variable cache
647
	 * Update the classpath variable cache
601
	 */
648
	 */
602
	public static class PluginPreferencesListener implements Preferences.IPropertyChangeListener {
649
	public static class EclipsePreferencesListener implements IEclipsePreferences.IPreferenceChangeListener {
603
		/**
650
		/**
604
		 * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(PropertyChangeEvent)
651
		 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
605
		 */
652
		 */
606
		public void propertyChange(Preferences.PropertyChangeEvent event) {
653
		public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
607
654
			String propertyName = event.getKey();
608
			String propertyName = event.getProperty();
609
			if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
655
			if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
610
				String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
656
				String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
611
				String newValue = (String)event.getNewValue();
657
				String newValue = (String)event.getNewValue();
Lines 711-717 Link Here
711
	 * Returns the new use count (or -1 if it didn't exist).
757
	 * Returns the new use count (or -1 if it didn't exist).
712
	 */
758
	 */
713
	public synchronized int discardPerWorkingCopyInfo(CompilationUnit workingCopy) throws JavaModelException {
759
	public synchronized int discardPerWorkingCopyInfo(CompilationUnit workingCopy) throws JavaModelException {
714
		synchronized(perWorkingCopyInfos) {
760
		synchronized(this.perWorkingCopyInfos) {
715
			WorkingCopyOwner owner = workingCopy.owner;
761
			WorkingCopyOwner owner = workingCopy.owner;
716
			Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner);
762
			Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner);
717
			if (workingCopyToInfos == null) return -1;
763
			if (workingCopyToInfos == null) return -1;
Lines 811-817 Link Here
811
	 * Returns the handle to the active Java Model.
857
	 * Returns the handle to the active Java Model.
812
	 */
858
	 */
813
	public final JavaModel getJavaModel() {
859
	public final JavaModel getJavaModel() {
814
		return javaModel;
860
		return this.javaModel;
815
	}
861
	}
816
862
817
	/**
863
	/**
Lines 847-857 Link Here
847
	 * Returns the per-project info for the given project. If specified, create the info if the info doesn't exist.
893
	 * Returns the per-project info for the given project. If specified, create the info if the info doesn't exist.
848
	 */
894
	 */
849
	public PerProjectInfo getPerProjectInfo(IProject project, boolean create) {
895
	public PerProjectInfo getPerProjectInfo(IProject project, boolean create) {
850
		synchronized(perProjectInfos) { // use the perProjectInfo collection as its own lock
896
		synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock
851
			PerProjectInfo info= (PerProjectInfo) perProjectInfos.get(project);
897
			PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project);
852
			if (info == null && create) {
898
			if (info == null && create) {
853
				info= new PerProjectInfo(project);
899
				info= new PerProjectInfo(project);
854
				perProjectInfos.put(project, info);
900
				this.perProjectInfos.put(project, info);
855
			}
901
			}
856
			return info;
902
			return info;
857
		}
903
		}
Lines 880-886 Link Here
880
	 * Returns null if it doesn't exist and not create.
926
	 * Returns null if it doesn't exist and not create.
881
	 */
927
	 */
882
	public PerWorkingCopyInfo getPerWorkingCopyInfo(CompilationUnit workingCopy,boolean create, boolean recordUsage, IProblemRequestor problemRequestor) {
928
	public PerWorkingCopyInfo getPerWorkingCopyInfo(CompilationUnit workingCopy,boolean create, boolean recordUsage, IProblemRequestor problemRequestor) {
883
		synchronized(perWorkingCopyInfos) { // use the perWorkingCopyInfo collection as its own lock
929
		synchronized(this.perWorkingCopyInfos) { // use the perWorkingCopyInfo collection as its own lock
884
			WorkingCopyOwner owner = workingCopy.owner;
930
			WorkingCopyOwner owner = workingCopy.owner;
885
			Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner);
931
			Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner);
886
			if (workingCopyToInfos == null && create) {
932
			if (workingCopyToInfos == null && create) {
Lines 976-986 Link Here
976
	 * Returns null if it has none.
1022
	 * Returns null if it has none.
977
	 */
1023
	 */
978
	public ICompilationUnit[] getWorkingCopies(WorkingCopyOwner owner, boolean addPrimary) {
1024
	public ICompilationUnit[] getWorkingCopies(WorkingCopyOwner owner, boolean addPrimary) {
979
		synchronized(perWorkingCopyInfos) {
1025
		synchronized(this.perWorkingCopyInfos) {
980
			ICompilationUnit[] primaryWCs = addPrimary && owner != DefaultWorkingCopyOwner.PRIMARY 
1026
			ICompilationUnit[] primaryWCs = addPrimary && owner != DefaultWorkingCopyOwner.PRIMARY 
981
				? getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false) 
1027
				? getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false) 
982
				: null;
1028
				: null;
983
			Map workingCopyToInfos = (Map)perWorkingCopyInfos.get(owner);
1029
			Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner);
984
			if (workingCopyToInfos == null) return primaryWCs;
1030
			if (workingCopyToInfos == null) return primaryWCs;
985
			int primaryLength = primaryWCs == null ? 0 : primaryWCs.length;
1031
			int primaryLength = primaryWCs == null ? 0 : primaryWCs.length;
986
			int size = workingCopyToInfos.size(); // note size is > 0 otherwise pathToPerWorkingCopyInfos would be null
1032
			int size = workingCopyToInfos.size(); // note size is > 0 otherwise pathToPerWorkingCopyInfos would be null
Lines 1099-1121 Link Here
1099
		}
1145
		}
1100
		
1146
		
1101
		// load variables and containers from preferences into cache
1147
		// load variables and containers from preferences into cache
1102
		Preferences preferences = JavaCore.getPlugin().getPluginPreferences();
1148
		IEclipsePreferences preferences = JavaCore.getInstancePreferences();
1103
1149
1104
		// only get variable from preferences not set to their default
1150
		// only get variable from preferences not set to their default
1105
		String[] propertyNames = preferences.propertyNames();
1151
		try {
1106
		int variablePrefixLength = CP_VARIABLE_PREFERENCES_PREFIX.length();
1152
			String[] propertyNames = preferences.keys();
1107
		for (int i = 0; i < propertyNames.length; i++){
1153
			int variablePrefixLength = CP_VARIABLE_PREFERENCES_PREFIX.length();
1108
			String propertyName = propertyNames[i];
1154
			for (int i = 0; i < propertyNames.length; i++){
1109
			if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)){
1155
				String propertyName = propertyNames[i];
1110
				String varName = propertyName.substring(variablePrefixLength);
1156
				if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)){
1111
				IPath varPath = new Path(preferences.getString(propertyName).trim());
1157
					String varName = propertyName.substring(variablePrefixLength);
1112
				
1158
					String propertyValue = preferences.get(propertyName, null);
1113
				this.variables.put(varName, varPath); 
1159
					if (propertyValue != null) {
1114
				this.previousSessionVariables.put(varName, varPath);
1160
						IPath varPath = new Path(propertyValue.trim());
1115
			}
1161
						this.variables.put(varName, varPath); 
1116
			if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){
1162
						this.previousSessionVariables.put(varName, varPath);
1117
				recreatePersistedContainer(propertyName, preferences.getString(propertyName), true/*add to container values*/);
1163
					}
1164
				}
1165
				if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){
1166
					String propertyValue = preferences.get(propertyName, null);
1167
					if (propertyValue != null)
1168
						recreatePersistedContainer(propertyName, propertyValue, true/*add to container values*/);
1169
				}
1118
			}
1170
			}
1171
		} catch (BackingStoreException e1) {
1172
			// TODO (frederic) see if it's necessary to report this failure...
1119
		}
1173
		}
1120
		// override persisted values for variables which have a registered initializer
1174
		// override persisted values for variables which have a registered initializer
1121
		String[] registeredVariables = getRegisteredVariableNames();
1175
		String[] registeredVariables = getRegisteredVariableNames();
Lines 1313-1323 Link Here
1313
	}	
1367
	}	
1314
1368
1315
	public void removePerProjectInfo(JavaProject javaProject) {
1369
	public void removePerProjectInfo(JavaProject javaProject) {
1316
		synchronized(perProjectInfos) { // use the perProjectInfo collection as its own lock
1370
		synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock
1371
			IProject project = javaProject.getProject();
1372
			PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project);
1373
			if (info != null) {
1374
				this.perProjectInfos.remove(project);
1375
			}
1376
		}
1377
	}
1378
1379
	/*
1380
	 * Reset project preferences stored in info cache.
1381
	 */
1382
	public void resetProjectPreferences(JavaProject javaProject) {
1383
		synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock
1317
			IProject project = javaProject.getProject();
1384
			IProject project = javaProject.getProject();
1318
			PerProjectInfo info= (PerProjectInfo) perProjectInfos.get(project);
1385
			PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project);
1319
			if (info != null) {
1386
			if (info != null) {
1320
				perProjectInfos.remove(project);
1387
				info.preferences = null;
1321
			}
1388
			}
1322
		}
1389
		}
1323
	}
1390
	}
Lines 1399-1405 Link Here
1399
	public void saving(ISaveContext context) throws CoreException {
1466
	public void saving(ISaveContext context) throws CoreException {
1400
		
1467
		
1401
	    // save container values on snapshot/full save
1468
	    // save container values on snapshot/full save
1402
		Preferences preferences = JavaCore.getPlugin().getPluginPreferences();
1403
		IJavaProject[] projects = getJavaModel().getJavaProjects();
1469
		IJavaProject[] projects = getJavaModel().getJavaProjects();
1404
		for (int i = 0, length = projects.length; i < length; i++) {
1470
		for (int i = 0, length = projects.length; i < length; i++) {
1405
		    IJavaProject project = projects[i];
1471
		    IJavaProject project = projects[i];
Lines 1417-1427 Link Here
1417
				} catch(JavaModelException e){
1483
				} catch(JavaModelException e){
1418
					// could not encode entry: leave it as CP_ENTRY_IGNORE
1484
					// could not encode entry: leave it as CP_ENTRY_IGNORE
1419
				}
1485
				}
1420
				preferences.setDefault(containerKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones
1486
				JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary...
1421
				preferences.setValue(containerKey, containerString);
1487
				JavaCore.getInstancePreferences().put(containerKey, containerString);
1422
			}
1488
			}
1423
		}
1489
		}
1424
		JavaCore.getPlugin().savePluginPreferences();
1490
		try {
1491
			JavaCore.getInstancePreferences().flush();
1492
		} catch (BackingStoreException e) {
1493
			// TODO (frederic) see if it's necessary to report this exception
1494
			// IStatus status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$
1495
			// throw new CoreException(status);
1496
		}
1425
		
1497
		
1426
		if (context.getKind() == ISaveContext.FULL_SAVE) {
1498
		if (context.getKind() == ISaveContext.FULL_SAVE) {
1427
			// will need delta since this save (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658)
1499
			// will need delta since this save (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658)
Lines 1444-1450 Link Here
1444
		}
1516
		}
1445
1517
1446
		ArrayList vStats= null; // lazy initialized
1518
		ArrayList vStats= null; // lazy initialized
1447
		for (Iterator iter =  perProjectInfos.values().iterator(); iter.hasNext();) {
1519
		for (Iterator iter =  this.perProjectInfos.values().iterator(); iter.hasNext();) {
1448
			try {
1520
			try {
1449
				PerProjectInfo info = (PerProjectInfo) iter.next();
1521
				PerProjectInfo info = (PerProjectInfo) iter.next();
1450
				saveState(info, context);
1522
				saveState(info, context);
Lines 1597-1607 Link Here
1597
			}
1669
			}
1598
		}
1670
		}
1599
1671
1600
		Preferences preferences = JavaCore.getPlugin().getPluginPreferences();
1601
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
1672
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
1602
		String variableString = variablePath == null ? CP_ENTRY_IGNORE : variablePath.toString();
1673
		String variableString = variablePath == null ? CP_ENTRY_IGNORE : variablePath.toString();
1603
		preferences.setDefault(variableKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones
1674
		JavaCore.getDefaultPreferences().put(variableKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary...
1604
		preferences.setValue(variableKey, variableString);
1675
		JavaCore.getInstancePreferences().put(variableKey, variableString);
1605
		JavaCore.getPlugin().savePluginPreferences();
1676
		try {
1677
			JavaCore.getInstancePreferences().flush();
1678
		} catch (BackingStoreException e) {
1679
			// TODO (frederic) see if it's necessary to report this exception
1680
//			IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$
1681
//			throw new CoreException(status);
1682
		}
1606
	}
1683
	}
1607
}
1684
}
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-109 / +130 lines)
Lines 11-25 Link Here
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.io.BufferedInputStream;
13
import java.io.BufferedInputStream;
14
import java.io.BufferedOutputStream;
15
import java.io.ByteArrayInputStream;
14
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayOutputStream;
15
import java.io.ByteArrayOutputStream;
17
import java.io.File;
16
import java.io.File;
18
import java.io.FileInputStream;
17
import java.io.FileInputStream;
19
import java.io.FileOutputStream;
20
import java.io.IOException;
18
import java.io.IOException;
21
import java.io.InputStream;
19
import java.io.InputStream;
22
import java.io.OutputStream;
23
import java.io.OutputStreamWriter;
20
import java.io.OutputStreamWriter;
24
import java.io.StringReader;
21
import java.io.StringReader;
25
import java.util.ArrayList;
22
import java.util.ArrayList;
Lines 28-38 Link Here
28
import java.util.Hashtable;
25
import java.util.Hashtable;
29
import java.util.Iterator;
26
import java.util.Iterator;
30
import java.util.Map;
27
import java.util.Map;
31
32
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilder;
33
import javax.xml.parsers.DocumentBuilderFactory;
29
import javax.xml.parsers.DocumentBuilderFactory;
34
import javax.xml.parsers.ParserConfigurationException;
30
import javax.xml.parsers.ParserConfigurationException;
35
36
import org.eclipse.core.resources.ICommand;
31
import org.eclipse.core.resources.ICommand;
37
import org.eclipse.core.resources.IFile;
32
import org.eclipse.core.resources.IFile;
38
import org.eclipse.core.resources.IFolder;
33
import org.eclipse.core.resources.IFolder;
Lines 43-55 Link Here
43
import org.eclipse.core.resources.IResource;
38
import org.eclipse.core.resources.IResource;
44
import org.eclipse.core.resources.IWorkspace;
39
import org.eclipse.core.resources.IWorkspace;
45
import org.eclipse.core.resources.IWorkspaceRoot;
40
import org.eclipse.core.resources.IWorkspaceRoot;
41
import org.eclipse.core.resources.ProjectScope;
46
import org.eclipse.core.resources.ResourcesPlugin;
42
import org.eclipse.core.resources.ResourcesPlugin;
47
import org.eclipse.core.runtime.CoreException;
43
import org.eclipse.core.runtime.CoreException;
48
import org.eclipse.core.runtime.IPath;
44
import org.eclipse.core.runtime.IPath;
49
import org.eclipse.core.runtime.IProgressMonitor;
45
import org.eclipse.core.runtime.IProgressMonitor;
50
import org.eclipse.core.runtime.Path;
46
import org.eclipse.core.runtime.Path;
47
import org.eclipse.core.runtime.Platform;
51
import org.eclipse.core.runtime.Preferences;
48
import org.eclipse.core.runtime.Preferences;
52
import org.eclipse.core.runtime.QualifiedName;
49
import org.eclipse.core.runtime.QualifiedName;
50
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
51
import org.eclipse.core.runtime.preferences.IPreferencesService;
52
import org.eclipse.core.runtime.preferences.IScopeContext;
53
import org.eclipse.jdt.core.IClasspathContainer;
53
import org.eclipse.jdt.core.IClasspathContainer;
54
import org.eclipse.jdt.core.IClasspathEntry;
54
import org.eclipse.jdt.core.IClasspathEntry;
55
import org.eclipse.jdt.core.ICompilationUnit;
55
import org.eclipse.jdt.core.ICompilationUnit;
Lines 74-79 Link Here
74
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
74
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
75
import org.eclipse.jdt.internal.core.util.Util;
75
import org.eclipse.jdt.internal.core.util.Util;
76
import org.eclipse.jdt.internal.eval.EvaluationContext;
76
import org.eclipse.jdt.internal.eval.EvaluationContext;
77
import org.osgi.service.prefs.BackingStoreException;
77
import org.w3c.dom.Element;
78
import org.w3c.dom.Element;
78
import org.w3c.dom.Node;
79
import org.w3c.dom.Node;
79
import org.w3c.dom.NodeList;
80
import org.w3c.dom.NodeList;
Lines 124-129 Link Here
124
125
125
	/**
126
	/**
126
	 * Name of file containing custom project preferences
127
	 * Name of file containing custom project preferences
128
	 * @deprecated WARNING Visibility will be reduce to private before M9
129
	 * 	If you use this variable, change your implementation to avoid future comilation error...
130
	 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=59258">bug 59258</a>
131
	 * TODO (frederic) set visibility from public to private
127
	 */
132
	 */
128
	public static final String PREF_FILENAME = ".jprefs";  //$NON-NLS-1$
133
	public static final String PREF_FILENAME = ".jprefs";  //$NON-NLS-1$
129
	
134
	
Lines 131-138 Link Here
131
	 * Value of the project's raw classpath if the .classpath file contains invalid entries.
136
	 * Value of the project's raw classpath if the .classpath file contains invalid entries.
132
	 */
137
	 */
133
	public static final IClasspathEntry[] INVALID_CLASSPATH = new IClasspathEntry[0];
138
	public static final IClasspathEntry[] INVALID_CLASSPATH = new IClasspathEntry[0];
134
135
	private static final String CUSTOM_DEFAULT_OPTION_VALUE = "#\r\n\r#custom-non-empty-default-value#\r\n\r#"; //$NON-NLS-1$
136
	
139
	
137
	/**
140
	/**
138
	 * Returns a canonicalized path from the given external path.
141
	 * Returns a canonicalized path from the given external path.
Lines 1395-1405 Link Here
1395
		
1398
		
1396
		String propertyName = optionName;
1399
		String propertyName = optionName;
1397
		if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){
1400
		if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){
1398
			Preferences preferences = getPreferences();
1401
			IEclipsePreferences preferences = getEclipsePreferences();
1399
			if (preferences == null || preferences.isDefault(propertyName)) {
1402
			String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(propertyName) : null;
1400
				return inheritJavaCoreOptions ? JavaCore.getOption(propertyName) : null;
1403
			if (preferences == null) return javaCoreDefault;
1401
			}
1404
			String value = preferences.get(propertyName, javaCoreDefault);
1402
			return preferences.getString(propertyName).trim();
1405
			return value == null ? null : value.trim();
1403
		}
1406
		}
1404
		return null;
1407
		return null;
1405
	}
1408
	}
Lines 1412-1432 Link Here
1412
		// initialize to the defaults from JavaCore options pool
1415
		// initialize to the defaults from JavaCore options pool
1413
		Map options = inheritJavaCoreOptions ? JavaCore.getOptions() : new Hashtable(5);
1416
		Map options = inheritJavaCoreOptions ? JavaCore.getOptions() : new Hashtable(5);
1414
1417
1415
		Preferences preferences = getPreferences();
1418
		IEclipsePreferences preferences = getEclipsePreferences();
1416
		if (preferences == null) return options; // cannot do better (non-Java project)
1419
		if (preferences == null) return options; // cannot do better (non-Java project)
1417
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
1420
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
1418
		
1421
		
1419
		// project cannot hold custom preferences set to their default, as it uses CUSTOM_DEFAULT_OPTION_VALUE
1422
		// project cannot hold custom preferences set to their default, as it uses CUSTOM_DEFAULT_OPTION_VALUE
1420
1423
1421
		// get custom preferences not set to their default
1424
		// get custom preferences not set to their default
1422
		String[] propertyNames = preferences.propertyNames();
1425
		try {
1423
		for (int i = 0; i < propertyNames.length; i++){
1426
			String[] propertyNames = preferences.keys();
1424
			String propertyName = propertyNames[i];
1427
			for (int i = 0; i < propertyNames.length; i++){
1425
			String value = preferences.getString(propertyName).trim();
1428
				String propertyName = propertyNames[i];
1426
			if (optionNames.contains(propertyName)){
1429
				String value = preferences.get(propertyName, null);
1427
				options.put(propertyName, value);
1430
				if (value != null && optionNames.contains(propertyName)){
1428
			}
1431
					options.put(propertyName, value.trim());
1429
		}		
1432
				}
1433
			}		
1434
		} catch (BackingStoreException e) {
1435
			// nothing to do
1436
		}
1430
1437
1431
		return options;
1438
		return options;
1432
	}
1439
	}
Lines 1635-1641 Link Here
1635
	public JavaModelManager.PerProjectInfo getPerProjectInfo() throws JavaModelException {
1642
	public JavaModelManager.PerProjectInfo getPerProjectInfo() throws JavaModelException {
1636
		return JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(this.project);
1643
		return JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(this.project);
1637
	}
1644
	}
1638
	
1645
1639
	/**
1646
	/**
1640
	 * @see IJavaProject#getProject()
1647
	 * @see IJavaProject#getProject()
1641
	 */
1648
	 */
Lines 1646-1654 Link Here
1646
	/**
1653
	/**
1647
	 * Returns the project custom preference pool.
1654
	 * Returns the project custom preference pool.
1648
	 * Project preferences may include custom encoding.
1655
	 * Project preferences may include custom encoding.
1649
	 * @return Preferences
1656
	 * @return IEclipsePreferences
1650
	 */	
1657
	 */	
1658
	public IEclipsePreferences getEclipsePreferences(){
1659
		if (!JavaProject.hasJavaNature(this.project)) return null;
1660
		JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
1661
		IEclipsePreferences eclipsePreferences =  perProjectInfo.preferences;
1662
		if (eclipsePreferences != null) return eclipsePreferences;
1663
		IScopeContext context = new ProjectScope(getProject());
1664
		eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
1665
		updatePreferences(eclipsePreferences);
1666
		perProjectInfo.preferences = eclipsePreferences;
1667
		return eclipsePreferences;
1668
	}
1669
1670
	/**
1671
	 * Returns the project custom preference pool.
1672
	 * Project preferences may include custom encoding.
1673
	 * @return Preferences
1674
	 * @deprecated WARNING:  this method do nothing from now and will be removed soon!
1675
	 * 	If you use it, switch as soon as possible to new preferences API by using 
1676
	 * 	{@link #getEclipsePreferences()} to avoid future compilation error...
1677
	 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=59258">bug 59258</a>
1678
	 * TODO (frederic) remove for 3.1...
1679
	 */
1651
	public Preferences getPreferences(){
1680
	public Preferences getPreferences(){
1681
		/*
1652
		if (!JavaProject.hasJavaNature(this.project)) return null;
1682
		if (!JavaProject.hasJavaNature(this.project)) return null;
1653
		JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
1683
		JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
1654
		Preferences preferences =  perProjectInfo.preferences;
1684
		Preferences preferences =  perProjectInfo.preferences;
Lines 1657-1662 Link Here
1657
		if (preferences == null) preferences = new Preferences();
1687
		if (preferences == null) preferences = new Preferences();
1658
		perProjectInfo.preferences = preferences;
1688
		perProjectInfo.preferences = preferences;
1659
		return preferences;
1689
		return preferences;
1690
		*/
1691
		return new Preferences();
1660
	}
1692
	}
1661
1693
1662
	/**
1694
	/**
Lines 2103-2116 Link Here
2103
	}	
2135
	}	
2104
2136
2105
	/*
2137
	/*
2138
	 * Update eclipse preferences from old preferences.
2139
	 */
2140
	 private void updatePreferences(IEclipsePreferences preferences) {
2141
	 	
2142
	 	Preferences oldPreferences = loadPreferences();
2143
	 	IPreferencesService service = Platform.getPreferencesService();
2144
	 	if (oldPreferences != null) {
2145
	 		String[] propertyNames = oldPreferences.propertyNames();
2146
			for (int i = 0; i < propertyNames.length; i++){
2147
				String propertyName = propertyNames[i];
2148
			    String propertyValue = oldPreferences.getString(propertyName);
2149
				String defaultValue = service.get(propertyName, null, JavaCore.preferencesLookup);
2150
			    if (!"".equals(propertyValue) && (defaultValue == null || !propertyValue.equals(defaultValue))) { //$NON-NLS-1$
2151
				    preferences.put(propertyName, propertyValue);
2152
			    }
2153
			}
2154
			try {
2155
				// save immediately old preferences
2156
				preferences.flush();
2157
			} catch (BackingStoreException e) {
2158
				// fails silently
2159
			}
2160
		}
2161
	 }
2162
2163
	/**
2106
	 * load preferences from a shareable format (VCM-wise)
2164
	 * load preferences from a shareable format (VCM-wise)
2165
	 * @deprecated WARNING, visibility of this method will be decreased soon
2166
	 * 	to private and won't be usable in the future.
2167
	 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=59258">bug 59258</a>
2168
	 * TODO (frederic) set visibility from public to private
2107
	 */
2169
	 */
2108
	 public Preferences loadPreferences() {
2170
	 public Preferences loadPreferences() {
2109
	 	
2171
	 	
2110
	 	Preferences preferences = new Preferences();
2172
	 	Preferences preferences = new Preferences();
2111
	 	
2173
	 	IPath projectMetaLocation = getPluginWorkingLocation();
2112
//		File prefFile = this.project.getLocation().append(PREF_FILENAME).toFile();
2113
		IPath projectMetaLocation = getPluginWorkingLocation();
2114
		if (projectMetaLocation != null) {
2174
		if (projectMetaLocation != null) {
2115
			File prefFile = projectMetaLocation.append(PREF_FILENAME).toFile();
2175
			File prefFile = projectMetaLocation.append(PREF_FILENAME).toFile();
2116
			if (prefFile.exists()) { // load preferences from file
2176
			if (prefFile.exists()) { // load preferences from file
Lines 2118-2124 Link Here
2118
				try {
2178
				try {
2119
					in = new BufferedInputStream(new FileInputStream(prefFile));
2179
					in = new BufferedInputStream(new FileInputStream(prefFile));
2120
					preferences.load(in);
2180
					preferences.load(in);
2121
					return preferences;
2122
				} catch (IOException e) { // problems loading preference store - quietly ignore
2181
				} catch (IOException e) { // problems loading preference store - quietly ignore
2123
				} finally {
2182
				} finally {
2124
					if (in != null) {
2183
					if (in != null) {
Lines 2128-2138 Link Here
2128
						}
2187
						}
2129
					}
2188
					}
2130
				}
2189
				}
2190
				// one shot read, delete old preferences
2191
				prefFile.delete();
2192
				return preferences;
2131
			}
2193
			}
2132
		}
2194
		}
2133
		return null;
2195
		return null;
2134
	 }
2196
	 }
2135
	 
2197
2136
	/**
2198
	/**
2137
	 * @see IJavaProject#newEvaluationContext()
2199
	 * @see IJavaProject#newEvaluationContext()
2138
	 */
2200
	 */
Lines 2401-2449 Link Here
2401
			throw new JavaModelException(e);
2463
			throw new JavaModelException(e);
2402
		}
2464
		}
2403
	}
2465
	}
2404
	/**
2405
	 * Save project custom preferences to shareable file (.jprefs)
2406
	 */
2407
	private void savePreferences(Preferences preferences) {
2408
		
2409
		if (!JavaProject.hasJavaNature(this.project)) return; // ignore
2410
		
2411
		if (preferences == null || (!preferences.needsSaving() && preferences.propertyNames().length != 0)) {
2412
			// nothing to save
2413
			return;
2414
		}
2415
	
2416
		// preferences need to be saved
2417
		// the preferences file is located in the plug-in's state area
2418
		// at a well-known name (.jprefs)
2419
//		File prefFile = this.project.getLocation().append(PREF_FILENAME).toFile();
2420
		File prefFile = getPluginWorkingLocation().append(PREF_FILENAME).toFile();
2421
		if (preferences.propertyNames().length == 0) {
2422
			// there are no preference settings
2423
			// rather than write an empty file, just delete any existing file
2424
			if (prefFile.exists()) {
2425
				prefFile.delete(); // don't worry if delete unsuccessful
2426
			}
2427
			return;
2428
		}
2429
		
2430
		// write file, overwriting an existing one
2431
		OutputStream out = null;
2432
		try {
2433
			// do it as carefully as we know how so that we don't lose/mangle
2434
			// the setting in times of stress
2435
			out = new BufferedOutputStream(new FileOutputStream(prefFile));
2436
			preferences.store(out, null);
2437
		} catch (IOException e) { // problems saving preference store - quietly ignore
2438
		} finally {
2439
			if (out != null) {
2440
				try {
2441
					out.close();
2442
				} catch (IOException e) { // ignore problems with close
2443
				}
2444
			}
2445
		}
2446
	}
2447
2466
2448
	/**
2467
	/**
2449
	 * Update the Java command in the build spec (replace existing one if present,
2468
	 * Update the Java command in the build spec (replace existing one if present,
Lines 2483-2492 Link Here
2483
	 */
2502
	 */
2484
	public void setOption(String optionName, String optionValue) {
2503
	public void setOption(String optionName, String optionValue) {
2485
		if (!JavaModelManager.getJavaModelManager().optionNames.contains(optionName)) return; // unrecognized option
2504
		if (!JavaModelManager.getJavaModelManager().optionNames.contains(optionName)) return; // unrecognized option
2486
		Preferences preferences = getPreferences();
2505
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2487
		preferences.setDefault(optionName, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251)
2506
		String defaultValue = JavaCore.getOption(optionName);
2488
		preferences.setValue(optionName, optionValue);
2507
		if (defaultValue == null || !defaultValue.equals(optionValue)) {
2489
		savePreferences(preferences);
2508
			projectPreferences.put(optionName, optionValue);
2509
			try {
2510
				projectPreferences.flush();
2511
			} catch (BackingStoreException e) {
2512
				// problem with pref store - quietly ignore
2513
			}
2514
		}
2490
	}
2515
	}
2491
2516
2492
	/**
2517
	/**
Lines 2494-2526 Link Here
2494
	 */
2519
	 */
2495
	public void setOptions(Map newOptions) {
2520
	public void setOptions(Map newOptions) {
2496
2521
2497
		Preferences preferences = getPreferences();
2522
		IEclipsePreferences projectPreferences = getEclipsePreferences();
2498
		if (newOptions != null){
2523
		try {
2499
			Iterator keys = newOptions.keySet().iterator();
2524
			if (newOptions == null){
2500
			while (keys.hasNext()){
2525
				projectPreferences.clear();
2501
				String key = (String)keys.next();
2526
			} else {
2502
				if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option
2527
				Iterator keys = newOptions.keySet().iterator();
2503
				// no filtering for encoding (custom encoding for project is allowed)
2528
				while (keys.hasNext()){
2504
				String value = (String)newOptions.get(key);
2529
					String key = (String)keys.next();
2505
				preferences.setDefault(key, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251)
2530
					if (!JavaModelManager.getJavaModelManager().optionNames.contains(key)) continue; // unrecognized option
2506
				preferences.setValue(key, value);
2531
					// no filtering for encoding (custom encoding for project is allowed)
2507
			}
2532
					String value = (String)newOptions.get(key);
2508
		}
2533
					projectPreferences.put(key, value);
2509
			
2534
				}
2510
		// reset to default all options not in new map
2535
				
2511
		// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
2536
				// reset to default all options not in new map
2512
		// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
2537
				// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
2513
		String[] pNames = preferences.propertyNames();
2538
				// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
2514
		int ln = pNames.length;
2539
				String[] pNames = projectPreferences.keys();
2515
		for (int i=0; i<ln; i++) {
2540
				int ln = pNames.length;
2516
			String key = pNames[i];
2541
				for (int i=0; i<ln; i++) {
2517
			if (newOptions == null || !newOptions.containsKey(key)) {
2542
					String key = pNames[i];
2518
				preferences.setToDefault(key); // set default => remove from preferences table
2543
					if (!newOptions.containsKey(key)) {
2544
						projectPreferences.remove(key); // old preferences => remove from preferences table
2545
					}
2546
				}
2519
			}
2547
			}
2520
		}
2521
2548
2522
		// persist options
2549
			// persist options
2523
		savePreferences(preferences);	
2550
			projectPreferences.flush();
2551
		} catch (BackingStoreException e) {
2552
			// problem with pref store - quietly ignore
2553
		}
2524
	}
2554
	}
2525
2555
2526
	/**
2556
	/**
Lines 2536-2550 Link Here
2536
			return;
2566
			return;
2537
		}
2567
		}
2538
		this.setRawClasspath(SetClasspathOperation.ReuseClasspath, path, monitor);
2568
		this.setRawClasspath(SetClasspathOperation.ReuseClasspath, path, monitor);
2539
	}
2540
2541
	/*
2542
	 * Set cached preferences, no preference file is saved, only info is updated
2543
	 */
2544
	public void setPreferences(Preferences preferences) {
2545
		if (!JavaProject.hasJavaNature(this.project)) return; // ignore
2546
		JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
2547
		perProjectInfo.preferences = preferences;
2548
	}
2569
	}
2549
2570
2550
	/**
2571
	/**
(-)model/org/eclipse/jdt/internal/core/UserLibraryManager.java (-23 / +31 lines)
Lines 22-37 Link Here
22
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.NullProgressMonitor;
24
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Preferences;
26
import org.eclipse.core.runtime.SubProgressMonitor;
25
import org.eclipse.core.runtime.SubProgressMonitor;
27
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
26
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
28
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
29
import org.eclipse.jdt.core.IClasspathContainer;
27
import org.eclipse.jdt.core.IClasspathContainer;
30
import org.eclipse.jdt.core.IClasspathEntry;
28
import org.eclipse.jdt.core.IClasspathEntry;
31
import org.eclipse.jdt.core.IJavaProject;
29
import org.eclipse.jdt.core.IJavaProject;
32
import org.eclipse.jdt.core.JavaCore;
30
import org.eclipse.jdt.core.JavaCore;
33
import org.eclipse.jdt.core.JavaModelException;
31
import org.eclipse.jdt.core.JavaModelException;
34
import org.eclipse.jdt.internal.core.util.Util;
32
import org.eclipse.jdt.internal.core.util.Util;
33
import org.osgi.service.prefs.BackingStoreException;
35
34
36
/**
35
/**
37
 *
36
 *
Lines 43-52 Link Here
43
42
44
	private static Map userLibraries;
43
	private static Map userLibraries;
45
	private static final boolean logProblems= false;
44
	private static final boolean logProblems= false;
46
	private static IPropertyChangeListener listener= new IPropertyChangeListener() {
45
	private static IEclipsePreferences.IPreferenceChangeListener listener= new IEclipsePreferences.IPreferenceChangeListener() {
47
46
48
		public void propertyChange(PropertyChangeEvent event) {
47
		public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
49
			String key= event.getProperty();
48
			String key= event.getKey();
50
			if (key.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
49
			if (key.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
51
				try {
50
				try {
52
					recreatePersistedUserLibraryEntry(key, (String) event.getNewValue(), false, true);
51
					recreatePersistedUserLibraryEntry(key, (String) event.getNewValue(), false, true);
Lines 58-64 Link Here
58
				}
57
				}
59
			}
58
			}
60
		}
59
		}
61
		
62
	};
60
	};
63
	
61
	
64
	private UserLibraryManager() {
62
	private UserLibraryManager() {
Lines 126-145 Link Here
126
		if (userLibraries == null) {
124
		if (userLibraries == null) {
127
			userLibraries= new HashMap();
125
			userLibraries= new HashMap();
128
			// load variables and containers from preferences into cache
126
			// load variables and containers from preferences into cache
129
			Preferences preferences = JavaCore.getPlugin().getPluginPreferences();
127
			IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences();
130
			preferences.addPropertyChangeListener(listener);
128
			instancePreferences.addPreferenceChangeListener(listener);
131
129
132
			// only get variable from preferences not set to their default
130
			// only get variable from preferences not set to their default
133
			String[] propertyNames = preferences.propertyNames();
131
			try {
134
			for (int i = 0; i < propertyNames.length; i++) {
132
				String[] propertyNames = instancePreferences.keys();
135
				String propertyName = propertyNames[i];
133
				for (int i = 0; i < propertyNames.length; i++) {
136
				if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
134
					String propertyName = propertyNames[i];
137
					try {
135
					if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
138
						recreatePersistedUserLibraryEntry(propertyName, preferences.getString(propertyName), false, false);
136
						try {
139
					} catch (JavaModelException e) {
137
							String propertyValue = instancePreferences.get(propertyName, null);
140
						// won't happen: no rebinding
138
							if (propertyValue != null)
139
								recreatePersistedUserLibraryEntry(propertyName,propertyValue, false, false);
140
						} catch (JavaModelException e) {
141
							// won't happen: no rebinding
142
						}
141
					}
143
					}
142
				}
144
				}
145
			} catch (BackingStoreException e) {
146
				// TODO (frederic) see if it's necessary to report this exception
143
			}
147
			}
144
		}
148
		}
145
		return userLibraries;
149
		return userLibraries;
Lines 178-184 Link Here
178
			}
182
			}
179
		}
183
		}
180
		
184
		
181
		Preferences preferences = JavaCore.getPlugin().getPluginPreferences();
185
		IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences();
182
		String containerKey = CP_USERLIBRARY_PREFERENCES_PREFIX+name;
186
		String containerKey = CP_USERLIBRARY_PREFERENCES_PREFIX+name;
183
		String containerString = CP_ENTRY_IGNORE;
187
		String containerString = CP_ENTRY_IGNORE;
184
		if (library != null) {
188
		if (library != null) {
Lines 188-206 Link Here
188
				// could not encode entry: leave it as CP_ENTRY_IGNORE
192
				// could not encode entry: leave it as CP_ENTRY_IGNORE
189
			}
193
			}
190
		}
194
		}
191
		preferences.removePropertyChangeListener(listener);
195
		instancePreferences.removePreferenceChangeListener(listener);
192
		try {
196
		try {
193
			preferences.setDefault(containerKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones
197
			JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary...
194
			preferences.setValue(containerKey, containerString);
198
			instancePreferences.put(containerKey, containerString);
195
			if (save) {
199
			if (save) {
196
				JavaCore.getPlugin().savePluginPreferences();
200
				try {
201
					instancePreferences.flush();
202
				} catch (BackingStoreException e) {
203
					// TODO (frederic) see if it's necessary to report this exception
204
				}
197
			}
205
			}
198
			if (rebind) {
206
			if (rebind) {
199
				rebindClasspathEntries(name, monitor);
207
				rebindClasspathEntries(name, monitor);
200
			}
208
			}
201
			
209
			
202
		} finally {
210
		} finally {
203
			preferences.addPropertyChangeListener(listener);
211
			instancePreferences.addPreferenceChangeListener(listener);
204
		}
212
		}
205
	}
213
	}
206
214

Return to bug 59258