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

(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-16 lines)
Lines 128-139 Link Here
128
		entry,
128
		entry,
129
		decoded);
129
		decoded);
130
}
130
}
131
protected void assertMarkers(String message, String expectedMarkers, IJavaProject project) throws CoreException {
132
	waitForAutoBuild();
133
	IMarker[] markers = project.getProject().findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
134
	this.sortMarkers(markers);
135
	assertMarkers(message, expectedMarkers, markers);
136
}
137
protected void assertStatus(String expected, IStatus status) {
131
protected void assertStatus(String expected, IStatus status) {
138
	String actual = status.getMessage();
132
	String actual = status.getMessage();
139
	if (!expected.equals(actual)) {
133
	if (!expected.equals(actual)) {
Lines 179-194 Link Here
179
	return result;
173
	return result;
180
}
174
}
181
175
182
protected void sortMarkers(IMarker[] markers) {
183
	org.eclipse.jdt.internal.core.util.Util.Comparer comparer = new org.eclipse.jdt.internal.core.util.Util.Comparer() {
184
		public int compare(Object a, Object b) {
185
			IMarker markerA = (IMarker)a;
186
			IMarker markerB = (IMarker)b;
187
			return markerA.getAttribute(IMarker.MESSAGE, "").compareTo(markerB.getAttribute(IMarker.MESSAGE, "")); //$NON-NLS-1$ //$NON-NLS-2$
188
		}
189
	};
190
	org.eclipse.jdt.internal.core.util.Util.sort(markers, comparer);
191
}
192
/**
176
/**
193
 * Add an entry to the classpath for a non-existent root. Then create
177
 * Add an entry to the classpath for a non-existent root. Then create
194
 * the root and ensure that it comes alive.
178
 * the root and ensure that it comes alive.
(-)src/org/eclipse/jdt/core/tests/model/OptionTests.java (+17 lines)
Lines 506-511 Link Here
506
			preferences.get(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", "null"));
506
			preferences.get(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", "null"));
507
	}
507
	}
508
508
509
	/*
510
	 * Ensures that classpath problems are removed when missing classpath variable is added through the preferences
511
	 * (regression test for bug 109691 Importing preferences does not update classpath variables)
512
	 */
513
	public void test12() throws CoreException {
514
		IEclipsePreferences preferences = JavaModelManager.getJavaModelManager().getInstancePreferences();
515
		try {
516
			IJavaProject project = createJavaProject("P", new String[0], new String[] {"TEST"}, "");
517
			waitForAutoBuild();
518
			preferences.put(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST", getExternalJCLPathString());
519
			assertMarkers("Unexpected markers", "", project);
520
		} finally {
521
			deleteProject("P");
522
			preferences.remove(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+"TEST");
523
		}
524
	}
525
509
	/**
526
	/**
510
	 * Bug 68993: [Preferences] IAE when opening project preferences
527
	 * Bug 68993: [Preferences] IAE when opening project preferences
511
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=68993"
528
	 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=68993"
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (+16 lines)
Lines 370-375 Link Here
370
		}
370
		}
371
		assertEquals("Unexpected type hierarchy", expected, actual);
371
		assertEquals("Unexpected type hierarchy", expected, actual);
372
	}
372
	}
373
	protected void assertMarkers(String message, String expectedMarkers, IJavaProject project) throws CoreException {
374
		waitForAutoBuild();
375
		IMarker[] markers = project.getProject().findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
376
		sortMarkers(markers);
377
		assertMarkers(message, expectedMarkers, markers);
378
	}
379
	protected void sortMarkers(IMarker[] markers) {
380
		org.eclipse.jdt.internal.core.util.Util.Comparer comparer = new org.eclipse.jdt.internal.core.util.Util.Comparer() {
381
			public int compare(Object a, Object b) {
382
				IMarker markerA = (IMarker)a;
383
				IMarker markerB = (IMarker)b;
384
				return markerA.getAttribute(IMarker.MESSAGE, "").compareTo(markerB.getAttribute(IMarker.MESSAGE, "")); //$NON-NLS-1$ //$NON-NLS-2$
385
			}
386
		};
387
		org.eclipse.jdt.internal.core.util.Util.sort(markers, comparer);
388
	}
373
	protected void assertMarkers(String message, String expectedMarkers, IMarker[] markers) throws CoreException {
389
	protected void assertMarkers(String message, String expectedMarkers, IMarker[] markers) throws CoreException {
374
		StringBuffer buffer = new StringBuffer();
390
		StringBuffer buffer = new StringBuffer();
375
		if (markers != null) {
391
		if (markers != null) {
(-)model/org/eclipse/jdt/core/JavaCore.java (-2 / +2 lines)
Lines 3896-3902 Link Here
3896
		IProgressMonitor monitor) {
3896
		IProgressMonitor monitor) {
3897
3897
3898
		try {
3898
		try {
3899
			JavaModelManager.getJavaModelManager().updateVariableValues(new String[]{ variableName}, new IPath[]{ null }, monitor);
3899
			JavaModelManager.getJavaModelManager().updateVariableValues(new String[]{ variableName}, new IPath[]{ null }, true/*update preferences*/, monitor);
3900
		} catch (JavaModelException e) {
3900
		} catch (JavaModelException e) {
3901
			// cannot happen: ignore
3901
			// cannot happen: ignore
3902
		}
3902
		}
Lines 4320-4326 Link Here
4320
		throws JavaModelException {
4320
		throws JavaModelException {
4321
4321
4322
		if (variableNames.length != paths.length)	Assert.isTrue(false, "Variable names and paths collections should have the same size"); //$NON-NLS-1$
4322
		if (variableNames.length != paths.length)	Assert.isTrue(false, "Variable names and paths collections should have the same size"); //$NON-NLS-1$
4323
		JavaModelManager.getJavaModelManager().updateVariableValues(variableNames, paths, monitor);
4323
		JavaModelManager.getJavaModelManager().updateVariableValues(variableNames, paths, true/*update preferences*/, monitor);
4324
	}
4324
	}
4325
4325
4326
	/**
4326
	/**
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-8 / +22 lines)
Lines 1043-1052 Link Here
1043
					}
1043
					}
1044
				} else {
1044
				} else {
1045
					String newValue = (String)event.getNewValue();
1045
					String newValue = (String)event.getNewValue();
1046
					IPath newPath;
1046
					if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1047
					if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1047
						manager.variables.put(varName, new Path(newValue));
1048
						newPath = new Path(newValue);
1048
					} else {
1049
					} else {
1049
						manager.variables.remove(varName);
1050
						newPath = null;
1051
					}
1052
					try {
1053
						manager.updateVariableValues(new String[] {varName}, new IPath[] {newPath}, false/*don't update preferences*/, null/*no progress available*/);
1054
					} catch (JavaModelException e) {
1055
						Util.log(e, "Could not set classpath variable " + varName + " to " + newPath); //$NON-NLS-1$ //$NON-NLS-2$
1050
					}
1056
					}
1051
				}
1057
				}
1052
			}
1058
			}
Lines 2940-2952 Link Here
2940
		void save() throws IOException, JavaModelException {
2946
		void save() throws IOException, JavaModelException {
2941
			saveProjects(JavaModelManager.this.getJavaModel().getJavaProjects());
2947
			saveProjects(JavaModelManager.this.getJavaModel().getJavaProjects());
2942
			
2948
			
2943
			// don't save classpath variables from the default preferences as there is no delta if they are removed
2949
			// remove variables that should not be saved
2944
			HashMap varsToSave = null;
2950
			HashMap varsToSave = null;
2945
			Iterator iterator = JavaModelManager.this.variables.keySet().iterator();
2951
			Iterator iterator = JavaModelManager.this.variables.entrySet().iterator();
2946
			IEclipsePreferences defaultPreferences = getDefaultPreferences();
2952
			IEclipsePreferences defaultPreferences = getDefaultPreferences();
2947
			while (iterator.hasNext()) {
2953
			while (iterator.hasNext()) {
2948
				String varName = (String) iterator.next();
2954
				Map.Entry entry = (Map.Entry) iterator.next();
2949
				if (defaultPreferences.get(CP_VARIABLE_PREFERENCES_PREFIX + varName, null) != null) {
2955
				String varName = (String) entry.getKey();
2956
				if (defaultPreferences.get(CP_VARIABLE_PREFERENCES_PREFIX + varName, null) != null // don't save classpath variables from the default preferences as there is no delta if they are removed
2957
					|| CP_ENTRY_IGNORE_PATH.equals(entry.getValue())) {
2958
					
2950
					if (varsToSave == null)
2959
					if (varsToSave == null)
2951
						varsToSave = new HashMap(JavaModelManager.this.variables);
2960
						varsToSave = new HashMap(JavaModelManager.this.variables);
2952
					varsToSave.remove(varName);
2961
					varsToSave.remove(varName);
Lines 3826-3831 Link Here
3826
	public void updateVariableValues(
3835
	public void updateVariableValues(
3827
		String[] variableNames,
3836
		String[] variableNames,
3828
		IPath[] variablePaths,
3837
		IPath[] variablePaths,
3838
		boolean updatePreferences,
3829
		IProgressMonitor monitor) throws JavaModelException {
3839
		IProgressMonitor monitor) throws JavaModelException {
3830
	
3840
	
3831
		if (monitor != null && monitor.isCanceled()) return;
3841
		if (monitor != null && monitor.isCanceled()) return;
Lines 3921-3927 Link Here
3921
		}
3931
		}
3922
		// update variables
3932
		// update variables
3923
		for (int i = 0; i < varLength; i++){
3933
		for (int i = 0; i < varLength; i++){
3924
			this.variablePut(variableNames[i], variablePaths[i]);
3934
			variablePut(variableNames[i], variablePaths[i]);
3935
			if (updatePreferences)
3936
				variablePreferencesPut(variableNames[i], variablePaths[i]);
3925
		}
3937
		}
3926
		final String[] dbgVariableNames = variableNames;
3938
		final String[] dbgVariableNames = variableNames;
3927
				
3939
				
Lines 4024-4030 Link Here
4024
			// discard obsoleted information about previous session
4036
			// discard obsoleted information about previous session
4025
			this.previousSessionVariables.remove(variableName);
4037
			this.previousSessionVariables.remove(variableName);
4026
		}
4038
		}
4027
	
4039
	}
4040
4041
	private void variablePreferencesPut(String variableName, IPath variablePath) {
4028
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
4042
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
4029
		if (variablePath == null) {
4043
		if (variablePath == null) {
4030
			this.variablesWithInitializer.remove(variableName);
4044
			this.variablesWithInitializer.remove(variableName);

Return to bug 109691