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 307587 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/resources/NatureManager.java (-32 / +15 lines)
Lines 25-37 Link Here
25
 */
25
 */
26
public class NatureManager implements ILifecycleListener, IManager {
26
public class NatureManager implements ILifecycleListener, IManager {
27
	//maps String (nature ID) -> descriptor objects
27
	//maps String (nature ID) -> descriptor objects
28
	protected Map descriptors;
28
	private Map descriptors;
29
29
30
	//maps IProject -> String[] of enabled natures for that project
30
	//maps IProject -> String[] of enabled natures for that project
31
	protected Map natureEnablements;
31
	private final Map natureEnablements = Collections.synchronizedMap(new HashMap(20));
32
32
33
	//maps String (builder ID) -> String (nature ID)
33
	//maps String (builder ID) -> String (nature ID)
34
	protected Map buildersToNatures = null;
34
	private Map buildersToNatures = null;
35
	//colour constants used in cycle detection algorithm
35
	//colour constants used in cycle detection algorithm
36
	private static final byte WHITE = 0;
36
	private static final byte WHITE = 0;
37
	private static final byte GREY = 1;
37
	private static final byte GREY = 1;
Lines 43-49 Link Here
43
43
44
	/**
44
	/**
45
	 * Computes the list of natures that are enabled for the given project.
45
	 * Computes the list of natures that are enabled for the given project.
46
	 * Enablement computation is subtlely different from nature set
46
	 * Enablement computation is subtly different from nature set
47
	 * validation, because it must find and remove all inconsistencies.
47
	 * validation, because it must find and remove all inconsistencies.
48
	 */
48
	 */
49
	protected String[] computeNatureEnablements(Project project) {
49
	protected String[] computeNatureEnablements(Project project) {
Lines 108-114 Link Here
108
	/* (non-Javadoc)
108
	/* (non-Javadoc)
109
	 * @see IWorkspace#getNatureDescriptor(String)
109
	 * @see IWorkspace#getNatureDescriptor(String)
110
	 */
110
	 */
111
	public IProjectNatureDescriptor getNatureDescriptor(String natureId) {
111
	public synchronized IProjectNatureDescriptor getNatureDescriptor(String natureId) {
112
		lazyInitialize();
112
		lazyInitialize();
113
		return (IProjectNatureDescriptor) descriptors.get(natureId);
113
		return (IProjectNatureDescriptor) descriptors.get(natureId);
114
	}
114
	}
Lines 116-122 Link Here
116
	/* (non-Javadoc)
116
	/* (non-Javadoc)
117
	 * @see IWorkspace#getNatureDescriptors()
117
	 * @see IWorkspace#getNatureDescriptors()
118
	 */
118
	 */
119
	public IProjectNatureDescriptor[] getNatureDescriptors() {
119
	public synchronized IProjectNatureDescriptor[] getNatureDescriptors() {
120
		lazyInitialize();
120
		lazyInitialize();
121
		Collection values = descriptors.values();
121
		Collection values = descriptors.values();
122
		return (IProjectNatureDescriptor[]) values.toArray(new IProjectNatureDescriptor[values.size()]);
122
		return (IProjectNatureDescriptor[]) values.toArray(new IProjectNatureDescriptor[values.size()]);
Lines 275-281 Link Here
275
	/**
275
	/**
276
	 * Marks all nature descriptors that are involved in cycles
276
	 * Marks all nature descriptors that are involved in cycles
277
	 */
277
	 */
278
	protected void detectCycles() {
278
	private void detectCycles() {
279
		Collection values = descriptors.values();
279
		Collection values = descriptors.values();
280
		ProjectNatureDescriptor[] natures = (ProjectNatureDescriptor[]) values.toArray(new ProjectNatureDescriptor[values.size()]);
280
		ProjectNatureDescriptor[] natures = (ProjectNatureDescriptor[]) values.toArray(new ProjectNatureDescriptor[values.size()]);
281
		for (int i = 0; i < natures.length; i++)
281
		for (int i = 0; i < natures.length; i++)
Lines 294-300 Link Here
294
	 * Returns the ID of the project nature that claims ownership of the
294
	 * Returns the ID of the project nature that claims ownership of the
295
	 * builder with the given ID.  Returns null if no nature owns that builder.
295
	 * builder with the given ID.  Returns null if no nature owns that builder.
296
	 */
296
	 */
297
	public String findNatureForBuilder(String builderID) {
297
	public synchronized String findNatureForBuilder(String builderID) {
298
		if (buildersToNatures == null) {
298
		if (buildersToNatures == null) {
299
			buildersToNatures = new HashMap(10);
299
			buildersToNatures = new HashMap(10);
300
			IProjectNatureDescriptor[] descs = getNatureDescriptors();
300
			IProjectNatureDescriptor[] descs = getNatureDescriptors();
Lines 310-337 Link Here
310
		return (String) buildersToNatures.get(builderID);
310
		return (String) buildersToNatures.get(builderID);
311
	}
311
	}
312
312
313
	protected void flushEnablements(IProject project) {
313
	private synchronized void flushEnablements(IProject project) {
314
		if (natureEnablements != null) {
314
		natureEnablements.remove(project);
315
			natureEnablements.remove(project);
316
			if (natureEnablements.size() == 0) {
317
				natureEnablements = null;
318
			}
319
		}
320
	}
315
	}
321
316
322
	/**
317
	/**
323
	 * Returns the cached array of enabled natures for this project,
318
	 * Returns the cached array of enabled natures for this project,
324
	 * or null if there is nothing in the cache.
319
	 * or null if there is nothing in the cache.
325
	 */
320
	 */
326
	protected String[] getEnabledNatures(Project project) {
321
	protected synchronized String[] getEnabledNatures(Project project) {
327
		String[] enabled;
322
		String[] enabled = (String[]) natureEnablements.get(project);
328
		if (natureEnablements != null) {
323
		if (enabled != null)
329
			enabled = (String[]) natureEnablements.get(project);
324
			return enabled;
330
			if (enabled != null)
331
				return enabled;
332
		}
333
		enabled = computeNatureEnablements(project);
325
		enabled = computeNatureEnablements(project);
334
		setEnabledNatures(project, enabled);
326
		natureEnablements.put(project, enabled);
335
		return enabled;
327
		return enabled;
336
	}
328
	}
337
329
Lines 464-478 Link Here
464
		detectCycles();
456
		detectCycles();
465
	}
457
	}
466
458
467
	/**
468
	 * Sets the cached array of enabled natures for this project.
469
	 */
470
	protected void setEnabledNatures(IProject project, String[] enablements) {
471
		if (natureEnablements == null)
472
			natureEnablements = Collections.synchronizedMap(new HashMap(20));
473
		natureEnablements.put(project, enablements);
474
	}
475
476
	public void shutdown(IProgressMonitor monitor) {
459
	public void shutdown(IProgressMonitor monitor) {
477
		// do nothing
460
		// do nothing
478
	}
461
	}

Return to bug 307587