View | Details | Raw Unified | Return to bug 131707
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/OptionTests.java (+26 lines)
Lines 16-21 Link Here
16
import junit.framework.Test;
16
import junit.framework.Test;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.Path;
18
import org.eclipse.core.runtime.Path;
19
import org.eclipse.core.runtime.preferences.DefaultScope;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
21
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
21
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IJavaProject;
Lines 602-605 Link Here
602
			deleteProject("P");
603
			deleteProject("P");
603
		}
604
		}
604
	}
605
	}
606
	
607
	/**
608
	 * @bug 131707: Cannot add classpath variables when starting with -pluginCustomization option
609
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=131707"
610
	 */
611
	public void testBug131707() throws CoreException {
612
		IEclipsePreferences defaultPreferences = new DefaultScope().getNode(JavaCore.PLUGIN_ID);
613
		try {
614
			defaultPreferences.put("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB", "c:\\temp\\lib.jar");
615
			simulateExitRestart();
616
			String[] variableNames = JavaCore.getClasspathVariableNames();
617
			for (int i = 0, length = variableNames.length; i < length; i++) {
618
				if ("MY_DEFAULT_LIB".equals(variableNames[i])) {
619
					assertEquals(
620
						"Unexpected value for MY_DEFAULT_LIB", 
621
						new Path("c:\\temp\\lib.jar"), 
622
						JavaCore.getClasspathVariable("MY_DEFAULT_LIB"));
623
					return;
624
				}
625
			}
626
			assertFalse("Variable MY_DEFAULT_LIB not found", true);
627
		} finally {
628
			defaultPreferences.remove("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB");
629
		}
630
	}
605
}
631
}
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-39 / +58 lines)
Lines 2106-2149 Link Here
2106
		}
2106
		}
2107
2107
2108
		// backward compatibility, load variables and containers from preferences into cache
2108
		// backward compatibility, load variables and containers from preferences into cache
2109
		IEclipsePreferences preferences = getInstancePreferences();
2109
		loadVariablesAndContainers(getDefaultPreferences());
2110
		try {
2110
		loadVariablesAndContainers(getInstancePreferences());
2111
			// only get variable from preferences not set to their default
2112
			String[] propertyNames = preferences.keys();
2113
			int variablePrefixLength = CP_VARIABLE_PREFERENCES_PREFIX.length();
2114
			for (int i = 0; i < propertyNames.length; i++){
2115
				String propertyName = propertyNames[i];
2116
				if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)){
2117
					String varName = propertyName.substring(variablePrefixLength);
2118
					String propertyValue = preferences.get(propertyName, null);
2119
					if (propertyValue != null) {
2120
						String pathString = propertyValue.trim();
2121
						
2122
						if (CP_ENTRY_IGNORE.equals(pathString)) {
2123
							// cleanup old preferences
2124
							preferences.remove(propertyName); 
2125
							continue;
2126
						}
2127
						
2128
						// add variable to table
2129
						IPath varPath = new Path(pathString);
2130
						this.variables.put(varName, varPath); 
2131
						this.previousSessionVariables.put(varName, varPath);
2132
					}
2133
				} else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){
2134
					String propertyValue = preferences.get(propertyName, null);
2135
					if (propertyValue != null) {
2136
						// cleanup old preferences
2137
						preferences.remove(propertyName); 
2138
						
2139
						// recreate container
2140
						recreatePersistedContainer(propertyName, propertyValue, true/*add to container values*/);
2141
					}
2142
				}
2143
			}
2144
		} catch (BackingStoreException e1) {
2145
			// TODO (frederic) see if it's necessary to report this failure...
2146
		}
2147
2111
2148
		// load variables and containers from saved file into cache
2112
		// load variables and containers from saved file into cache
2149
		File file = getVariableAndContainersFile();
2113
		File file = getVariableAndContainersFile();
Lines 2210-2215 Link Here
2210
		containersReset(getRegisteredContainerIDs());
2174
		containersReset(getRegisteredContainerIDs());
2211
	}
2175
	}
2212
2176
2177
	private void loadVariablesAndContainers(IEclipsePreferences preferences) {
2178
		try {
2179
			// only get variable from preferences not set to their default
2180
			String[] propertyNames = preferences.keys();
2181
			int variablePrefixLength = CP_VARIABLE_PREFERENCES_PREFIX.length();
2182
			for (int i = 0; i < propertyNames.length; i++){
2183
				String propertyName = propertyNames[i];
2184
				if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)){
2185
					String varName = propertyName.substring(variablePrefixLength);
2186
					String propertyValue = preferences.get(propertyName, null);
2187
					if (propertyValue != null) {
2188
						String pathString = propertyValue.trim();
2189
						
2190
						if (CP_ENTRY_IGNORE.equals(pathString)) {
2191
							// cleanup old preferences
2192
							preferences.remove(propertyName); 
2193
							continue;
2194
						}
2195
						
2196
						// add variable to table
2197
						IPath varPath = new Path(pathString);
2198
						this.variables.put(varName, varPath); 
2199
						this.previousSessionVariables.put(varName, varPath);
2200
					}
2201
				} else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){
2202
					String propertyValue = preferences.get(propertyName, null);
2203
					if (propertyValue != null) {
2204
						// cleanup old preferences
2205
						preferences.remove(propertyName); 
2206
						
2207
						// recreate container
2208
						recreatePersistedContainer(propertyName, propertyValue, true/*add to container values*/);
2209
					}
2210
				}
2211
			}
2212
		} catch (BackingStoreException e1) {
2213
			// TODO (frederic) see if it's necessary to report this failure...
2214
		}
2215
	}
2216
2213
	private static final class PersistedClasspathContainer implements
2217
	private static final class PersistedClasspathContainer implements
2214
			IClasspathContainer {
2218
			IClasspathContainer {
2215
2219
Lines 2935-2941 Link Here
2935
2939
2936
		void save() throws IOException, JavaModelException {
2940
		void save() throws IOException, JavaModelException {
2937
			saveProjects(JavaModelManager.this.getJavaModel().getJavaProjects());
2941
			saveProjects(JavaModelManager.this.getJavaModel().getJavaProjects());
2938
			saveVariables(JavaModelManager.this.variables);
2942
			
2943
			// don't save classpath variables from the default preferences as there is no delta if they are removed
2944
			HashMap varsToSave = null;
2945
			Iterator iterator = JavaModelManager.this.variables.keySet().iterator();
2946
			IEclipsePreferences defaultPreferences = getDefaultPreferences();
2947
			while (iterator.hasNext()) {
2948
				String varName = (String) iterator.next();
2949
				if (defaultPreferences.get(CP_VARIABLE_PREFERENCES_PREFIX + varName, null) != null) {
2950
					if (varsToSave == null)
2951
						varsToSave = new HashMap(JavaModelManager.this.variables);
2952
					varsToSave.remove(varName);
2953
				}
2954
					
2955
			}
2956
			
2957
			saveVariables(varsToSave != null ? varsToSave : JavaModelManager.this.variables);
2939
		}
2958
		}
2940
2959
2941
		private void saveAccessRule(ClasspathAccessRule rule) throws IOException {
2960
		private void saveAccessRule(ClasspathAccessRule rule) throws IOException {

Return to bug 131707