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 338076
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 20-26 Link Here
20
public class LifecycleEvent {
20
public class LifecycleEvent {
21
	//constants for kinds of internal workspace lifecycle events
21
	//constants for kinds of internal workspace lifecycle events
22
	public static final int PRE_PROJECT_CLOSE = 0x01;
22
	public static final int PRE_PROJECT_CLOSE = 0x01;
23
	public static final int PRE_PROJECT_CHANGE = 0x02;
23
	public static final int POST_PROJECT_CHANGE = 0x02;
24
	public static final int PRE_PROJECT_COPY = 0x04;
24
	public static final int PRE_PROJECT_COPY = 0x04;
25
	public static final int PRE_PROJECT_CREATE = 0x08;
25
	public static final int PRE_PROJECT_CREATE = 0x08;
26
26
(-)src/org/eclipse/core/internal/resources/ContentDescriptionManager.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
2
 * Copyright (c) 2004, 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 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 (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 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 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 (-4 / +4 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 1049-1055 Link Here
1049
				//see if we have an old .prj file
1049
				//see if we have an old .prj file
1050
				if (!hadSavedDescription)
1050
				if (!hadSavedDescription)
1051
					hadSavedDescription = workspace.getMetaArea().hasSavedProject(this);
1051
					hadSavedDescription = workspace.getMetaArea().hasSavedProject(this);
1052
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1053
				workspace.beginOperation(true);
1052
				workspace.beginOperation(true);
1054
				MultiStatus status = basicSetDescription(newDescription, updateFlags);
1053
				MultiStatus status = basicSetDescription(newDescription, updateFlags);
1055
				if (hadSavedDescription && !status.isOK())
1054
				if (hadSavedDescription && !status.isOK())
Lines 1067-1072 Link Here
1067
				if (!status.isOK())
1066
				if (!status.isOK())
1068
					throw new CoreException(status);
1067
					throw new CoreException(status);
1069
			} finally {
1068
			} finally {
1069
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1070
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1070
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1071
			}
1071
			}
1072
		} finally {
1072
		} finally {
Lines 1105-1117 Link Here
1105
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1105
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1106
			try {
1106
			try {
1107
				workspace.prepareOperation(rule, monitor);
1107
				workspace.prepareOperation(rule, monitor);
1108
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1109
				workspace.beginOperation(true);
1108
				workspace.beginOperation(true);
1110
				super.touch(Policy.subMonitorFor(monitor, Policy.opWork));
1109
				super.touch(Policy.subMonitorFor(monitor, Policy.opWork));
1111
			} catch (OperationCanceledException e) {
1110
			} catch (OperationCanceledException e) {
1112
				workspace.getWorkManager().operationCanceled();
1111
				workspace.getWorkManager().operationCanceled();
1113
				throw e;
1112
				throw e;
1114
			} finally {
1113
			} finally {
1114
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1115
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1115
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1116
			}
1116
			}
1117
		} finally {
1117
		} finally {
Lines 1129-1135 Link Here
1129
			return;
1129
			return;
1130
		ProjectDescription.isReading = true;
1130
		ProjectDescription.isReading = true;
1131
		try {
1131
		try {
1132
			workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1133
			ProjectDescription description = getLocalManager().read(this, false);
1132
			ProjectDescription description = getLocalManager().read(this, false);
1134
			//links can only be created if the project is open
1133
			//links can only be created if the project is open
1135
			IStatus result = null;
1134
			IStatus result = null;
Lines 1139-1144 Link Here
1139
			if (result != null && !result.isOK())
1138
			if (result != null && !result.isOK())
1140
				throw new CoreException(result);
1139
				throw new CoreException(result);
1141
		} finally {
1140
		} finally {
1141
			workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1142
			ProjectDescription.isReading = false;
1142
			ProjectDescription.isReading = false;
1143
		}
1143
		}
1144
	}
1144
	}
(-)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 / +77 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.tests.resources;
11
package org.eclipse.core.tests.resources;
12
12
13
import java.io.OutputStream;
13
import junit.framework.Test;
14
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
import junit.framework.TestSuite;
16
import org.eclipse.core.filesystem.EFS;
17
import org.eclipse.core.filesystem.IFileStore;
18
import org.eclipse.core.internal.resources.File;
19
import org.eclipse.core.internal.resources.Project;
20
import org.eclipse.core.internal.utils.FileUtil;
15
import org.eclipse.core.resources.*;
21
import org.eclipse.core.resources.*;
16
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.jobs.IJobManager;
23
import org.eclipse.core.runtime.jobs.IJobManager;
Lines 259-262 Link Here
259
			manager.endRule(ws.getRoot());
265
			manager.endRule(ws.getRoot());
260
		}
266
		}
261
	}
267
	}
268
269
	/**
270
	 * Changes project description and parallel checks {@link IProject#isNatureEnabled(String)},
271
	 * to check if natures value is cached properly.
272
	 * 
273
	 * See discussion on Bug 307587.
274
	 * @throws Exception
275
	 */
276
	public void testConcurrentNatures() throws Exception {
277
		final boolean finished[] = new boolean[] {false};
278
		final Project project = (Project) ResourcesPlugin.getWorkspace().getRoot().getProject(getUniqueString());
279
280
		ensureExistsInWorkspace(project, true);
281
282
		new Job("CheckNatureJob") {
283
			protected IStatus run(IProgressMonitor monitor) {
284
				try {
285
					if (finished[0] == false) {
286
						if (project.exists() && project.isOpen())
287
							project.isNatureEnabled(NATURE_SIMPLE);
288
						schedule();
289
					}
290
				} catch (CoreException e) {
291
					fail("CheckNatureJob failed", e);
292
				}
293
				return Status.OK_STATUS;
294
			}
295
		}.schedule();
296
297
		try {
298
			// Make sure enough time has past to bump file's
299
			// timestamp during the copy  
300
			Thread.sleep(1000);
301
		} catch (InterruptedException e) {
302
			fail("2.0", e);
303
		}
304
305
		IFileStore descStore = ((File) project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME)).getStore();
306
307
		// create a description with many natures, this will make updating description longer
308
		StringBuffer description = new StringBuffer();
309
		description.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><projectDescription><name></name><comment></comment><projects></projects><buildSpec></buildSpec><natures>");
310
		description.append("<nature>" + NATURE_SIMPLE + "</nature>");
311
		for (int i = 0; i < 100; i++) {
312
			description.append("<nature>nature" + i + "</nature>");
313
		}
314
		description.append("</natures></projectDescription>\n");
315
316
		// write the description
317
		OutputStream output = null;
318
		try {
319
			output = descStore.openOutputStream(EFS.NONE, getMonitor());
320
			output.write(description.toString().getBytes());
321
		} catch (CoreException e) {
322
			fail("1.0");
323
		} finally {
324
			FileUtil.safeClose(output);
325
		}
326
327
		try {
328
			project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
329
		} catch (CoreException e) {
330
			fail("3.0", e);
331
		}
332
333
		finished[0] = true;
334
335
		assertTrue("4.0", project.hasNature(NATURE_SIMPLE));
336
		assertTrue("5.0", project.isNatureEnabled(NATURE_SIMPLE));
337
	}
262
}
338
}

Return to bug 338076