Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 137398 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java (-5 / +24 lines)
Lines 288-295 Link Here
288
		}
288
		}
289
289
290
		try {
290
		try {
291
			// project pref should not exist
291
			// project pref should be cleared (see bug 137398)
292
			assertTrue("3.0", !parent.nodeExists(project.getName()));
292
			assertTrue("3.0", isNodeCleared(parent, new String[]{project.getName()}));
293
		} catch (BackingStoreException e) {
293
		} catch (BackingStoreException e) {
294
			fail("3.1", e);
294
			fail("3.1", e);
295
		}
295
		}
Lines 324-334 Link Here
324
			fail("2.0", e);
324
			fail("2.0", e);
325
		}
325
		}
326
		
326
		
327
		// ensure that preferences for the old project are removed
327
		// ensure that preferences for the old project are cleared (see bug 137398)
328
		node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
328
		node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
329
		assertNotNull("2.1", node);
329
		assertNotNull("2.1", node);
330
		try {
330
		try {
331
			assertTrue("2.2", !node.nodeExists(project1.getName()));
331
			assertTrue("2.2", isNodeCleared(node, new String[] {project1.getName()}));
332
		} catch (BackingStoreException e) {
332
		} catch (BackingStoreException e) {
333
			fail("2.3", e);
333
			fail("2.3", e);
334
		}
334
		}
Lines 352-357 Link Here
352
		assertNotNull("4.1", node);
352
		assertNotNull("4.1", node);
353
		assertEquals("4.2", value, node.get(key, null));
353
		assertEquals("4.2", value, node.get(key, null));
354
	}
354
	}
355
	
356
	/**
357
	 * @param node the node to check
358
	 * @param childrenNames the names of children to check
359
	 * @return true, if the node and its children have no associated values
360
	 * @throws BackingStoreException
361
	 */
362
	private boolean isNodeCleared(Preferences node, String[] childrenNames) throws BackingStoreException {	
363
		// check if the node has associate values
364
		if (node.keys().length !=0) return false;
365
	
366
		// perform a subsequent check for the node children
367
		Preferences childNode = null;
368
		for (int i=0; i<childrenNames.length; i++){
369
			childNode = node.node(childrenNames[i]);
370
			if (!isNodeCleared(childNode, childNode.childrenNames())) return false;
371
		}
372
		return true;
373
	}
355
374
356
	/**
375
	/**
357
	 * Regression test for Bug 60925 - project preferences do not show up in workspace.
376
	 * Regression test for Bug 60925 - project preferences do not show up in workspace.
Lines 894-900 Link Here
894
		assertTrue("3.1", !fileInFS.exists());
913
		assertTrue("3.1", !fileInFS.exists());
895
		IEclipsePreferences projectNode = (IEclipsePreferences) service.getRootNode().node(ProjectScope.SCOPE).node(project.getName());
914
		IEclipsePreferences projectNode = (IEclipsePreferences) service.getRootNode().node(ProjectScope.SCOPE).node(project.getName());
896
		try {
915
		try {
897
			assertTrue("3.2", !projectNode.nodeExists(qualifier));
916
			assertTrue("3.2", isNodeCleared(projectNode, new String[]{qualifier}));
898
		} catch (BackingStoreException e) {
917
		} catch (BackingStoreException e) {
899
			fail("3.91", e);
918
			fail("3.91", e);
900
		}
919
		}
(-)src/org/eclipse/core/tests/resources/CharsetTest.java (-3 / +6 lines)
Lines 951-957 Link Here
951
	 */
951
	 */
952
	public void testMovingProject() throws CoreException {
952
	public void testMovingProject() throws CoreException {
953
		IWorkspace workspace = getWorkspace();
953
		IWorkspace workspace = getWorkspace();
954
		IProject project1 = workspace.getRoot().getProject("Project1");
954
		String project1Name = getUniqueString();
955
		IProject project1 = workspace.getRoot().getProject(project1Name);
955
		IProject project2 = null;
956
		IProject project2 = null;
956
		try {
957
		try {
957
			IFolder folder = project1.getFolder("folder1");
958
			IFolder folder = project1.getFolder("folder1");
Lines 967-974 Link Here
967
			assertEquals("1.3", "FOO", project1.getDefaultCharset());
968
			assertEquals("1.3", "FOO", project1.getDefaultCharset());
968
969
969
			// move project and ensures charsets settings are preserved
970
			// move project and ensures charsets settings are preserved
970
			project1.move(new Path("Project2"), false, null);
971
			String project2Name = getUniqueString();
971
			project2 = workspace.getRoot().getProject("Project2");
972
			project1.move(new Path(project2Name), false, null);
973
			
974
			project2 = workspace.getRoot().getProject(project2Name);
972
			folder = project2.getFolder("folder1");
975
			folder = project2.getFolder("folder1");
973
			file1 = project2.getFile("file1.txt");
976
			file1 = project2.getFile("file1.txt");
974
			file2 = folder.getFile("file2.txt");
977
			file2 = folder.getFile("file2.txt");
(-)src/org/eclipse/core/internal/resources/Resource.java (-3 / +3 lines)
Lines 766-780 Link Here
766
			for (Iterator it = links.iterator(); it.hasNext();)
766
			for (Iterator it = links.iterator(); it.hasNext();)
767
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_DELETE, (IResource) it.next()));
767
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_DELETE, (IResource) it.next()));
768
768
769
		// check if we deleted a preferences file 
770
		ProjectPreferences.deleted(this);
771
772
		/* if we are synchronizing, do not delete the resource. Convert it
769
		/* if we are synchronizing, do not delete the resource. Convert it
773
		 into a phantom. Actual deletion will happen when we refresh or push. */
770
		 into a phantom. Actual deletion will happen when we refresh or push. */
774
		if (convertToPhantom && getType() != PROJECT && synchronizing(getResourceInfo(true, false)))
771
		if (convertToPhantom && getType() != PROJECT && synchronizing(getResourceInfo(true, false)))
775
			convertToPhantom();
772
			convertToPhantom();
776
		else
773
		else
777
			workspace.deleteResource(this);
774
			workspace.deleteResource(this);
775
		
776
		// check if we deleted a preferences file
777
		ProjectPreferences.deleted(this);
778
778
779
		//remove all deleted linked resources from the project description
779
		//remove all deleted linked resources from the project description
780
		if (getType() != IResource.PROJECT && links != null) {
780
		if (getType() != IResource.PROJECT && links != null) {
(-)src/org/eclipse/core/internal/resources/ProjectPreferences.java (-16 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 107-120 Link Here
107
			// ignore
107
			// ignore
108
		}
108
		}
109
109
110
		// if the node was loaded we need to clear the values and remove
110
		// clear the preferences
111
		// its reference from the parent (don't save it though)
111
		nodeDeleted(projectNode.node(qualifier));
112
		// otherwise just remove the reference from the parent
113
		String childPath = projectNode.absolutePath() + IPath.SEPARATOR + qualifier;
114
		if (projectNode.isAlreadyLoaded(childPath))
115
			removeNode(projectNode.node(qualifier));
116
		else
117
			projectNode.removeNode(qualifier);
118
112
119
		// notifies the CharsetManager if needed
113
		// notifies the CharsetManager if needed
120
		if (qualifier.equals(ResourcesPlugin.PI_RESOURCES))
114
		if (qualifier.equals(ResourcesPlugin.PI_RESOURCES))
Lines 136-143 Link Here
136
		Preferences projectNode = root.node(ProjectScope.SCOPE).node(project);
130
		Preferences projectNode = root.node(ProjectScope.SCOPE).node(project);
137
		// check if we need to notify the charset manager
131
		// check if we need to notify the charset manager
138
		boolean hasResourcesSettings = getFile(folder, ResourcesPlugin.PI_RESOURCES).exists();
132
		boolean hasResourcesSettings = getFile(folder, ResourcesPlugin.PI_RESOURCES).exists();
139
		// remove the preferences
133
		// clear the preferences
140
		removeNode(projectNode);
134
		nodeDeleted(projectNode);
141
		// notifies the CharsetManager 		
135
		// notifies the CharsetManager 		
142
		if (hasResourcesSettings)
136
		if (hasResourcesSettings)
143
			preferencesChanged(folder.getProject());
137
			preferencesChanged(folder.getProject());
Lines 155-162 Link Here
155
		Preferences projectNode = root.node(ProjectScope.SCOPE).node(project.getName());
149
		Preferences projectNode = root.node(ProjectScope.SCOPE).node(project.getName());
156
		// check if we need to notify the charset manager
150
		// check if we need to notify the charset manager
157
		boolean hasResourcesSettings = getFile(project, ResourcesPlugin.PI_RESOURCES).exists();
151
		boolean hasResourcesSettings = getFile(project, ResourcesPlugin.PI_RESOURCES).exists();
158
		// remove the preferences
152
		// clear the preferences
159
		removeNode(projectNode);
153
		nodeDeleted(projectNode);
160
		// notifies the CharsetManager 		
154
		// notifies the CharsetManager 		
161
		if (hasResourcesSettings)
155
		if (hasResourcesSettings)
162
			preferencesChanged(project);
156
			preferencesChanged(project);
Lines 241-252 Link Here
241
			node.isReading = oldIsReading;
235
			node.isReading = oldIsReading;
242
		}
236
		}
243
	}
237
	}
238
	
239
	private static void clearAll(Preferences node) throws BackingStoreException {
240
		node.clear();
241
		String[] names = node.childrenNames();
242
		for (int i = 0; i < names.length; i++) {
243
			clearAll(node.node(names[i]));
244
		}
245
	}
244
246
245
	static void removeNode(Preferences node) throws CoreException {
247
	static void nodeDeleted(Preferences node) throws CoreException {
246
		String message = NLS.bind(Messages.preferences_removeNodeException, node.absolutePath());
248
 		// if the underlying properties file was deleted, clear the values and remove
249
		// it from the list of loaded classes keep the node as it might still be referenced
247
		try {
250
		try {
248
			node.removeNode();
251
			clearAll(node);
249
		} catch (BackingStoreException e) {
252
		} catch (BackingStoreException e) {
253
			String message = NLS.bind(Messages.preferences_clearNodeException, node.absolutePath());
250
			IStatus status = new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, e);
254
			IStatus status = new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, e);
251
			throw new CoreException(status);
255
			throw new CoreException(status);
252
		}
256
		}
(-)src/org/eclipse/core/internal/utils/Messages.java (-1 / +1 lines)
Lines 105-111 Link Here
105
	public static String preferences_deleteException;
105
	public static String preferences_deleteException;
106
	public static String preferences_loadException;
106
	public static String preferences_loadException;
107
	public static String preferences_operationCanceled;
107
	public static String preferences_operationCanceled;
108
	public static String preferences_removeNodeException;
108
	public static String preferences_clearNodeException;
109
	public static String preferences_saveProblems;
109
	public static String preferences_saveProblems;
110
	public static String preferences_syncException;
110
	public static String preferences_syncException;
111
111
(-)src/org/eclipse/core/internal/utils/messages.properties (-1 / +1 lines)
Lines 101-107 Link Here
101
preferences_deleteException=Exception deleting file: {0}.
101
preferences_deleteException=Exception deleting file: {0}.
102
preferences_loadException=Exception loading preferences from: {0}.
102
preferences_loadException=Exception loading preferences from: {0}.
103
preferences_operationCanceled=Operation canceled.
103
preferences_operationCanceled=Operation canceled.
104
preferences_removeNodeException=Exception while removing preference node: {0}.
104
preferences_clearNodeException=Exception while clearing preference node: {0}.
105
preferences_saveProblems=Exception occurred while saving project preferences: {0}.
105
preferences_saveProblems=Exception occurred while saving project preferences: {0}.
106
preferences_syncException=Exception occurred while synchronizing node: {0}.
106
preferences_syncException=Exception occurred while synchronizing node: {0}.
107
107

Return to bug 137398