### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/OptionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/OptionTests.java,v retrieving revision 1.19 diff -u -r1.19 OptionTests.java --- src/org/eclipse/jdt/core/tests/model/OptionTests.java 3 Mar 2006 09:13:00 -0000 1.19 +++ src/org/eclipse/jdt/core/tests/model/OptionTests.java 20 Mar 2006 16:46:23 -0000 @@ -16,6 +16,7 @@ import junit.framework.Test; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.jdt.core.IJavaProject; @@ -602,4 +603,29 @@ deleteProject("P"); } } + + /** + * @bug 131707: Cannot add classpath variables when starting with -pluginCustomization option + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=131707" + */ + public void testBug131707() throws CoreException { + IEclipsePreferences defaultPreferences = new DefaultScope().getNode(JavaCore.PLUGIN_ID); + try { + defaultPreferences.put("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB", "c:\\temp\\lib.jar"); + simulateExitRestart(); + String[] variableNames = JavaCore.getClasspathVariableNames(); + for (int i = 0, length = variableNames.length; i < length; i++) { + if ("MY_DEFAULT_LIB".equals(variableNames[i])) { + assertEquals( + "Unexpected value for MY_DEFAULT_LIB", + new Path("c:\\temp\\lib.jar"), + JavaCore.getClasspathVariable("MY_DEFAULT_LIB")); + return; + } + } + assertFalse("Variable MY_DEFAULT_LIB not found", true); + } finally { + defaultPreferences.remove("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB"); + } + } } #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.332 diff -u -r1.332 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 14 Mar 2006 01:46:19 -0000 1.332 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 20 Mar 2006 16:46:25 -0000 @@ -2106,44 +2106,8 @@ } // backward compatibility, load variables and containers from preferences into cache - IEclipsePreferences preferences = getInstancePreferences(); - try { - // only get variable from preferences not set to their default - 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) { - String pathString = propertyValue.trim(); - - if (CP_ENTRY_IGNORE.equals(pathString)) { - // cleanup old preferences - preferences.remove(propertyName); - continue; - } - - // add variable to table - IPath varPath = new Path(pathString); - this.variables.put(varName, varPath); - this.previousSessionVariables.put(varName, varPath); - } - } else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){ - String propertyValue = preferences.get(propertyName, null); - if (propertyValue != null) { - // cleanup old preferences - preferences.remove(propertyName); - - // recreate container - recreatePersistedContainer(propertyName, propertyValue, true/*add to container values*/); - } - } - } - } catch (BackingStoreException e1) { - // TODO (frederic) see if it's necessary to report this failure... - } + loadVariablesAndContainers(getDefaultPreferences()); + loadVariablesAndContainers(getInstancePreferences()); // load variables and containers from saved file into cache File file = getVariableAndContainersFile(); @@ -2210,6 +2174,46 @@ containersReset(getRegisteredContainerIDs()); } + private void loadVariablesAndContainers(IEclipsePreferences preferences) { + try { + // only get variable from preferences not set to their default + 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) { + String pathString = propertyValue.trim(); + + if (CP_ENTRY_IGNORE.equals(pathString)) { + // cleanup old preferences + preferences.remove(propertyName); + continue; + } + + // add variable to table + IPath varPath = new Path(pathString); + this.variables.put(varName, varPath); + this.previousSessionVariables.put(varName, varPath); + } + } else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)){ + String propertyValue = preferences.get(propertyName, null); + if (propertyValue != null) { + // cleanup old preferences + preferences.remove(propertyName); + + // recreate container + recreatePersistedContainer(propertyName, propertyValue, true/*add to container values*/); + } + } + } + } catch (BackingStoreException e1) { + // TODO (frederic) see if it's necessary to report this failure... + } + } + private static final class PersistedClasspathContainer implements IClasspathContainer { @@ -2935,7 +2939,22 @@ void save() throws IOException, JavaModelException { saveProjects(JavaModelManager.this.getJavaModel().getJavaProjects()); - saveVariables(JavaModelManager.this.variables); + + // don't save classpath variables from the default preferences as there is no delta if they are removed + HashMap varsToSave = null; + Iterator iterator = JavaModelManager.this.variables.keySet().iterator(); + IEclipsePreferences defaultPreferences = getDefaultPreferences(); + while (iterator.hasNext()) { + String varName = (String) iterator.next(); + if (defaultPreferences.get(CP_VARIABLE_PREFERENCES_PREFIX + varName, null) != null) { + if (varsToSave == null) + varsToSave = new HashMap(JavaModelManager.this.variables); + varsToSave.remove(varName); + } + + } + + saveVariables(varsToSave != null ? varsToSave : JavaModelManager.this.variables); } private void saveAccessRule(ClasspathAccessRule rule) throws IOException {