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 (-1 / +21 lines)
Lines 894-900 Link Here
894
		assertTrue("3.1", !fileInFS.exists());
894
		assertTrue("3.1", !fileInFS.exists());
895
		IEclipsePreferences projectNode = (IEclipsePreferences) service.getRootNode().node(ProjectScope.SCOPE).node(project.getName());
895
		IEclipsePreferences projectNode = (IEclipsePreferences) service.getRootNode().node(ProjectScope.SCOPE).node(project.getName());
896
		try {
896
		try {
897
			assertTrue("3.2", !projectNode.nodeExists(qualifier));
897
		// when the pref file is deleted, its node will be cleared, but not removed
898
			assertTrue("3.2", isNodeCleared(projectNode, new String[]{qualifier}));
898
		} catch (BackingStoreException e) {
899
		} catch (BackingStoreException e) {
899
			fail("3.91", e);
900
			fail("3.91", e);
900
		}
901
		}
Lines 921-924 Link Here
921
		node = context.getNode(qualifier);
922
		node = context.getNode(qualifier);
922
		assertEquals("5.0", newValue, node.get(key, null));
923
		assertEquals("5.0", newValue, node.get(key, null));
923
	}
924
	}
925
	
926
	/**
927
	 * @param node the node to check
928
	 * @param childrenNames the names of children to check
929
	 * @return true, if the node and its children have no associated values
930
	 * @throws BackingStoreException
931
	 */
932
	private boolean isNodeCleared(Preferences node, String[] childrenNames) throws BackingStoreException {	
933
		// check if the node has associate values
934
		if (node.keys().length !=0) return false;
935
	
936
		// perform a subsequent check for the node children
937
		Preferences childNode = null;
938
		for (int i=0; i<childrenNames.length; i++){
939
			childNode = node.node(childrenNames[i]);
940
			if (!isNodeCleared(childNode, childNode.childrenNames())) return false;
941
		}
942
		return true;
943
	}
924
}
944
}
(-)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 (-9 / +29 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 257-262 Link Here
257
				i.remove();
251
				i.remove();
258
		}
252
		}
259
	}
253
	}
254
	
255
	private static void clearAll(Preferences node) throws BackingStoreException {
256
		node.clear();
257
		String[] names = node.childrenNames();
258
		for (int i = 0; i < names.length; i++) {
259
			clearAll(node.node(names[i]));
260
		}
261
	}
262
263
	static void nodeDeleted(Preferences node) throws CoreException {
264
 		// if the underlying properties file was deleted, clear the values and remove
265
		// it from the list of loaded classes keep the node as it might still be referenced
266
		try {
267
			clearAll(node);
268
		} catch (BackingStoreException e) {
269
			String message = NLS.bind(Messages.preferences_clearNodeException, node.absolutePath());
270
			IStatus status = new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, e);
271
			throw new CoreException(status);
272
		}
273
		String path = node.absolutePath();
274
		for (Iterator i = loadedNodes.iterator(); i.hasNext();) {
275
			String key = (String) i.next();
276
			if (key.startsWith(path))
277
				i.remove();
278
		}
279
	}
260
280
261
	public static void updatePreferences(IFile file) throws CoreException {
281
	public static void updatePreferences(IFile file) throws CoreException {
262
		IPath path = file.getFullPath();
282
		IPath path = file.getFullPath();
(-)src/org/eclipse/core/internal/utils/Messages.java (+1 lines)
Lines 106-111 Link Here
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_removeNodeException;
109
	public static String preferences_clearNodeException;
109
	public static String preferences_saveProblems;
110
	public static String preferences_saveProblems;
110
	public static String preferences_syncException;
111
	public static String preferences_syncException;
111
112
(-)src/org/eclipse/core/internal/utils/messages.properties (+1 lines)
Lines 102-107 Link Here
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_removeNodeException=Exception while removing preference node: {0}.
105
preferences_clearNodeException=Exception while clearing preference node: {0}.
105
preferences_saveProblems=Exception occurred while saving project preferences: {0}.
106
preferences_saveProblems=Exception occurred while saving project preferences: {0}.
106
preferences_syncException=Exception occurred while synchronizing node: {0}.
107
preferences_syncException=Exception occurred while synchronizing node: {0}.
107
108

Return to bug 137398