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

Collapse All | Expand All

(-)src/org/eclipse/core/internal/events/LifecycleEvent.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 21-27 Link Here
21
public class LifecycleEvent {
21
public class LifecycleEvent {
22
	//constants for kinds of internal workspace lifecycle events
22
	//constants for kinds of internal workspace lifecycle events
23
	public static final int PRE_PROJECT_CLOSE = 0x01;
23
	public static final int PRE_PROJECT_CLOSE = 0x01;
24
	public static final int PRE_PROJECT_CHANGE = 0x02;
24
	public static final int POST_PROJECT_CHANGE = 0x02;
25
	public static final int PRE_PROJECT_COPY = 0x04;
25
	public static final int PRE_PROJECT_COPY = 0x04;
26
	public static final int PRE_PROJECT_CREATE = 0x08;
26
	public static final int PRE_PROJECT_CREATE = 0x08;
27
27
(-)src/org/eclipse/core/internal/resources/ContentDescriptionManager.java (-1 / +1 lines)
Lines 458-464 Link Here
458
	public void handleEvent(LifecycleEvent event) {
458
	public void handleEvent(LifecycleEvent event) {
459
		//TODO are these the only events we care about?
459
		//TODO are these the only events we care about?
460
		switch (event.kind) {
460
		switch (event.kind) {
461
			case LifecycleEvent.PRE_PROJECT_CHANGE :
461
			case LifecycleEvent.POST_PROJECT_CHANGE :
462
			// if the project changes, its natures may have changed as well (content types may be associated to natures)
462
			// if the project changes, its natures may have changed as well (content types may be associated to natures)
463
			case LifecycleEvent.PRE_PROJECT_DELETE :
463
			case LifecycleEvent.PRE_PROJECT_DELETE :
464
			// if the project gets deleted, we may get confused if it is recreated again (content ids might match)
464
			// if the project gets deleted, we may get confused if it is recreated again (content ids might match)
(-)src/org/eclipse/core/internal/resources/NatureManager.java (-1 / +1 lines)
Lines 124-130 Link Here
124
124
125
	public void handleEvent(LifecycleEvent event) {
125
	public void handleEvent(LifecycleEvent event) {
126
		switch (event.kind) {
126
		switch (event.kind) {
127
			case LifecycleEvent.PRE_PROJECT_CHANGE :
127
			case LifecycleEvent.POST_PROJECT_CHANGE :
128
			case LifecycleEvent.PRE_PROJECT_CLOSE :
128
			case LifecycleEvent.PRE_PROJECT_CLOSE :
129
			case LifecycleEvent.PRE_PROJECT_DELETE :
129
			case LifecycleEvent.PRE_PROJECT_DELETE :
130
			case LifecycleEvent.PRE_PROJECT_MOVE :
130
			case LifecycleEvent.PRE_PROJECT_MOVE :
(-)src/org/eclipse/core/internal/resources/Project.java (-3 / +3 lines)
Lines 1212-1218 Link Here
1212
				//see if we have an old .prj file
1212
				//see if we have an old .prj file
1213
				if (!hadSavedDescription)
1213
				if (!hadSavedDescription)
1214
					hadSavedDescription = workspace.getMetaArea().hasSavedProject(this);
1214
					hadSavedDescription = workspace.getMetaArea().hasSavedProject(this);
1215
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1216
				workspace.beginOperation(true);
1215
				workspace.beginOperation(true);
1217
				MultiStatus status = basicSetDescription(newDescription, updateFlags);
1216
				MultiStatus status = basicSetDescription(newDescription, updateFlags);
1218
				if (hadSavedDescription && !status.isOK())
1217
				if (hadSavedDescription && !status.isOK())
Lines 1230-1235 Link Here
1230
				if (!status.isOK())
1229
				if (!status.isOK())
1231
					throw new CoreException(status);
1230
					throw new CoreException(status);
1232
			} finally {
1231
			} finally {
1232
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1233
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1233
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1234
			}
1234
			}
1235
		} finally {
1235
		} finally {
Lines 1268-1280 Link Here
1268
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1268
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1269
			try {
1269
			try {
1270
				workspace.prepareOperation(rule, monitor);
1270
				workspace.prepareOperation(rule, monitor);
1271
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1272
				workspace.beginOperation(true);
1271
				workspace.beginOperation(true);
1273
				super.touch(Policy.subMonitorFor(monitor, Policy.opWork));
1272
				super.touch(Policy.subMonitorFor(monitor, Policy.opWork));
1274
			} catch (OperationCanceledException e) {
1273
			} catch (OperationCanceledException e) {
1275
				workspace.getWorkManager().operationCanceled();
1274
				workspace.getWorkManager().operationCanceled();
1276
				throw e;
1275
				throw e;
1277
			} finally {
1276
			} finally {
1277
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1278
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1278
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1279
			}
1279
			}
1280
		} finally {
1280
		} finally {
Lines 1292-1298 Link Here
1292
			return;
1292
			return;
1293
		ProjectDescription.isReading = true;
1293
		ProjectDescription.isReading = true;
1294
		try {
1294
		try {
1295
			workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1296
			ProjectDescription description = getLocalManager().read(this, false);
1295
			ProjectDescription description = getLocalManager().read(this, false);
1297
			//links can only be created if the project is open
1296
			//links can only be created if the project is open
1298
			IStatus result = null;
1297
			IStatus result = null;
Lines 1302-1307 Link Here
1302
			if (result != null && !result.isOK())
1301
			if (result != null && !result.isOK())
1303
				throw new CoreException(result);
1302
				throw new CoreException(result);
1304
		} finally {
1303
		} finally {
1304
			workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1305
			ProjectDescription.isReading = false;
1305
			ProjectDescription.isReading = false;
1306
		}
1306
		}
1307
	}
1307
	}
(-)TestFiles/testProject/.project (+113 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>testProject</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
	</buildSpec>
9
	<natures>
10
		<nature>org.eclipse.pde.PluginNature</nature>
11
		<nature>org.eclipse.jdt.core.javanature</nature>
12
		<nature>nature1</nature>
13
<nature>nature2</nature>
14
<nature>nature3</nature>
15
<nature>nature4</nature>
16
<nature>nature5</nature>
17
<nature>nature6</nature>
18
<nature>nature7</nature>
19
<nature>nature8</nature>
20
<nature>nature9</nature>
21
<nature>nature10</nature>
22
<nature>nature11</nature>
23
<nature>nature12</nature>
24
<nature>nature13</nature>
25
<nature>nature14</nature>
26
<nature>nature15</nature>
27
<nature>nature16</nature>
28
<nature>nature17</nature>
29
<nature>nature18</nature>
30
<nature>nature19</nature>
31
<nature>nature20</nature>
32
<nature>nature21</nature>
33
<nature>nature22</nature>
34
<nature>nature23</nature>
35
<nature>nature24</nature>
36
<nature>nature25</nature>
37
<nature>nature26</nature>
38
<nature>nature27</nature>
39
<nature>nature28</nature>
40
<nature>nature29</nature>
41
<nature>nature30</nature>
42
<nature>nature31</nature>
43
<nature>nature32</nature>
44
<nature>nature33</nature>
45
<nature>nature34</nature>
46
<nature>nature35</nature>
47
<nature>nature36</nature>
48
<nature>nature37</nature>
49
<nature>nature38</nature>
50
<nature>nature39</nature>
51
<nature>nature40</nature>
52
<nature>nature41</nature>
53
<nature>nature42</nature>
54
<nature>nature43</nature>
55
<nature>nature44</nature>
56
<nature>nature45</nature>
57
<nature>nature46</nature>
58
<nature>nature47</nature>
59
<nature>nature48</nature>
60
<nature>nature49</nature>
61
<nature>nature50</nature>
62
<nature>nature51</nature>
63
<nature>nature52</nature>
64
<nature>nature53</nature>
65
<nature>nature54</nature>
66
<nature>nature55</nature>
67
<nature>nature56</nature>
68
<nature>nature57</nature>
69
<nature>nature58</nature>
70
<nature>nature59</nature>
71
<nature>nature60</nature>
72
<nature>nature61</nature>
73
<nature>nature62</nature>
74
<nature>nature63</nature>
75
<nature>nature64</nature>
76
<nature>nature65</nature>
77
<nature>nature66</nature>
78
<nature>nature67</nature>
79
<nature>nature68</nature>
80
<nature>nature69</nature>
81
<nature>nature70</nature>
82
<nature>nature71</nature>
83
<nature>nature72</nature>
84
<nature>nature73</nature>
85
<nature>nature74</nature>
86
<nature>nature75</nature>
87
<nature>nature76</nature>
88
<nature>nature77</nature>
89
<nature>nature78</nature>
90
<nature>nature79</nature>
91
<nature>nature80</nature>
92
<nature>nature81</nature>
93
<nature>nature82</nature>
94
<nature>nature83</nature>
95
<nature>nature84</nature>
96
<nature>nature85</nature>
97
<nature>nature86</nature>
98
<nature>nature87</nature>
99
<nature>nature88</nature>
100
<nature>nature89</nature>
101
<nature>nature90</nature>
102
<nature>nature91</nature>
103
<nature>nature92</nature>
104
<nature>nature93</nature>
105
<nature>nature94</nature>
106
<nature>nature95</nature>
107
<nature>nature96</nature>
108
<nature>nature97</nature>
109
<nature>nature98</nature>
110
<nature>nature99</nature>
111
<nature>nature100</nature>
112
	</natures>
113
</projectDescription>
(-)src/org/eclipse/core/tests/resources/NatureTest.java (-1 / +71 lines)
Lines 17-24 Link Here
17
import org.eclipse.core.filesystem.IFileStore;
17
import org.eclipse.core.filesystem.IFileStore;
18
import org.eclipse.core.internal.resources.File;
18
import org.eclipse.core.internal.resources.File;
19
import org.eclipse.core.internal.resources.Project;
19
import org.eclipse.core.internal.resources.Project;
20
import org.eclipse.core.internal.utils.FileUtil;
20
import org.eclipse.core.resources.*;
21
import org.eclipse.core.resources.*;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.jobs.IJobManager;
23
import org.eclipse.core.runtime.jobs.IJobManager;
23
import org.eclipse.core.runtime.jobs.Job;
24
import org.eclipse.core.runtime.jobs.Job;
24
import org.eclipse.core.tests.internal.resources.SimpleNature;
25
import org.eclipse.core.tests.internal.resources.SimpleNature;
Lines 345-348 Link Here
345
		out.close();
346
		out.close();
346
	}
347
	}
347
348
349
	/**
350
	 * Changes project description and parallel checks {@link IProject#isNatureEnabled(String)},
351
	 * to check if natures value is cached properly.
352
	 * 
353
	 * See discussion on Bug 307587.
354
	 * @throws Exception
355
	 */
356
	public void testConcurrentNatures() throws Exception {
357
		final boolean finished[] = new boolean[] {false};
358
		final Project project = (Project) ResourcesPlugin.getWorkspace().getRoot().getProject(getUniqueString());
359
360
		ensureExistsInWorkspace(project, true);
361
362
		new Job("CheckNatureJob") {
363
			protected IStatus run(IProgressMonitor monitor) {
364
				try {
365
					if (finished[0] == false) {
366
						if (project.exists() && project.isOpen())
367
							project.isNatureEnabled(NATURE_SIMPLE);
368
						schedule();
369
					}
370
				} catch (CoreException e) {
371
					fail("CheckNatureJob failed", e);
372
				}
373
				return Status.OK_STATUS;
374
			}
375
		}.schedule();
376
377
		try {
378
			// Make sure enough time has past to bump file's
379
			// timestamp during the copy  
380
			Thread.sleep(1000);
381
		} catch (InterruptedException e) {
382
			fail("2.0", e);
383
		}
384
385
		IFileStore descStore = ((File) project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME)).getStore();
386
387
		// create a description with many natures, this will make updating description longer
388
		StringBuffer description = new StringBuffer();
389
		description.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><projectDescription><name></name><comment></comment><projects></projects><buildSpec></buildSpec><natures>");
390
		description.append("<nature>" + NATURE_SIMPLE + "</nature>");
391
		for (int i = 0; i < 100; i++) {
392
			description.append("<nature>nature" + i + "</nature>");
393
		}
394
		description.append("</natures></projectDescription>\n");
395
396
		// write the description
397
		OutputStream output = null;
398
		try {
399
			output = descStore.openOutputStream(EFS.NONE, getMonitor());
400
			output.write(description.toString().getBytes());
401
		} catch (CoreException e) {
402
			fail("1.0");
403
		} finally {
404
			FileUtil.safeClose(output);
405
		}
406
407
		try {
408
			project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
409
		} catch (CoreException e) {
410
			fail("3.0", e);
411
		}
412
413
		finished[0] = true;
414
415
		assertTrue("4.0", project.hasNature(NATURE_SIMPLE));
416
		assertTrue("5.0", project.isNatureEnabled(NATURE_SIMPLE));
417
	}
348
}
418
}

Return to bug 338077