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/events/LifecycleEvent.java (-1 / +1 lines)
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 457-463 Link Here
457
	public void handleEvent(LifecycleEvent event) {
457
	public void handleEvent(LifecycleEvent event) {
458
		//TODO are these the only events we care about?
458
		//TODO are these the only events we care about?
459
		switch (event.kind) {
459
		switch (event.kind) {
460
			case LifecycleEvent.PRE_PROJECT_CHANGE :
460
			case LifecycleEvent.POST_PROJECT_CHANGE :
461
			// if the project changes, its natures may have changed as well (content types may be associated to natures)
461
			// if the project changes, its natures may have changed as well (content types may be associated to natures)
462
			case LifecycleEvent.PRE_PROJECT_DELETE :
462
			case LifecycleEvent.PRE_PROJECT_DELETE :
463
			// if the project gets deleted, we may get confused if it is recreated again (content ids might match)
463
			// 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 125-131 Link Here
125
125
126
	public void handleEvent(LifecycleEvent event) {
126
	public void handleEvent(LifecycleEvent event) {
127
		switch (event.kind) {
127
		switch (event.kind) {
128
			case LifecycleEvent.PRE_PROJECT_CHANGE :
128
			case LifecycleEvent.POST_PROJECT_CHANGE :
129
			case LifecycleEvent.PRE_PROJECT_CLOSE :
129
			case LifecycleEvent.PRE_PROJECT_CLOSE :
130
			case LifecycleEvent.PRE_PROJECT_DELETE :
130
			case LifecycleEvent.PRE_PROJECT_DELETE :
131
			case LifecycleEvent.PRE_PROJECT_MOVE :
131
			case LifecycleEvent.PRE_PROJECT_MOVE :
(-)src/org/eclipse/core/internal/resources/Project.java (-3 / +3 lines)
Lines 1343-1349 Link Here
1343
				//see if we have an old .prj file
1343
				//see if we have an old .prj file
1344
				if (!hadSavedDescription)
1344
				if (!hadSavedDescription)
1345
					hadSavedDescription = workspace.getMetaArea().hasSavedProject(this);
1345
					hadSavedDescription = workspace.getMetaArea().hasSavedProject(this);
1346
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1347
				workspace.beginOperation(true);
1346
				workspace.beginOperation(true);
1348
				MultiStatus status = basicSetDescription(newDescription, updateFlags);
1347
				MultiStatus status = basicSetDescription(newDescription, updateFlags);
1349
				if (hadSavedDescription && !status.isOK())
1348
				if (hadSavedDescription && !status.isOK())
Lines 1361-1366 Link Here
1361
				if (!status.isOK())
1360
				if (!status.isOK())
1362
					throw new CoreException(status);
1361
					throw new CoreException(status);
1363
			} finally {
1362
			} finally {
1363
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1364
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1364
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1365
			}
1365
			}
1366
		} finally {
1366
		} finally {
Lines 1399-1411 Link Here
1399
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1399
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1400
			try {
1400
			try {
1401
				workspace.prepareOperation(rule, monitor);
1401
				workspace.prepareOperation(rule, monitor);
1402
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1403
				workspace.beginOperation(true);
1402
				workspace.beginOperation(true);
1404
				super.touch(Policy.subMonitorFor(monitor, Policy.opWork));
1403
				super.touch(Policy.subMonitorFor(monitor, Policy.opWork));
1405
			} catch (OperationCanceledException e) {
1404
			} catch (OperationCanceledException e) {
1406
				workspace.getWorkManager().operationCanceled();
1405
				workspace.getWorkManager().operationCanceled();
1407
				throw e;
1406
				throw e;
1408
			} finally {
1407
			} finally {
1408
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1409
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1409
				workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
1410
			}
1410
			}
1411
		} finally {
1411
		} finally {
Lines 1423-1429 Link Here
1423
			return;
1423
			return;
1424
		ProjectDescription.isReading = true;
1424
		ProjectDescription.isReading = true;
1425
		try {
1425
		try {
1426
			workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
1427
			ProjectDescription description = getLocalManager().read(this, false);
1426
			ProjectDescription description = getLocalManager().read(this, false);
1428
			//links can only be created if the project is open
1427
			//links can only be created if the project is open
1429
			IStatus result = null;
1428
			IStatus result = null;
Lines 1433-1438 Link Here
1433
			if (result != null && !result.isOK())
1432
			if (result != null && !result.isOK())
1434
				throw new CoreException(result);
1433
				throw new CoreException(result);
1435
		} finally {
1434
		} finally {
1435
			workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.POST_PROJECT_CHANGE, this));
1436
			ProjectDescription.isReading = false;
1436
			ProjectDescription.isReading = false;
1437
		}
1437
		}
1438
	}
1438
	}
(-)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/ConcurrentNatureTest.java (+88 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.tests.resources;
12
13
import java.io.FileInputStream;
14
import junit.framework.TestCase;
15
import org.eclipse.core.internal.resources.Project;
16
import org.eclipse.core.resources.*;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.tests.harness.FileSystemHelper;
19
20
/**
21
 * 
22
 */
23
public class ConcurrentNatureTest extends TestCase {
24
	//	private static final String projectName = "Project";
25
	private static String projectPath;
26
	private static final String nature = "org.eclipse.jdt.core.javanature";
27
	private static final String testProjectName = "testProject";
28
29
	protected void setUp() throws Exception {
30
		projectPath = FileLocator.resolve(Platform.getBundle("org.eclipse.core.tests.resources").getEntry("TestFiles/testProject")).getPath();
31
	}
32
33
	protected void tearDown() throws Exception {
34
		super.tearDown();
35
		ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
36
		FileSystemHelper.clear(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile());
37
	}
38
39
	private class CheckNatureThread extends Thread {
40
		private boolean finished[];
41
42
		public CheckNatureThread(boolean[] finished) {
43
			super();
44
			this.finished = finished;
45
		}
46
47
		public void run() {
48
			Project project = (Project) ResourcesPlugin.getWorkspace().getRoot().getProject(testProjectName);
49
50
			try {
51
				while (finished[0] == false) {
52
					if (project.exists() && project.isOpen())
53
						System.out.println("Nature enabled:" + project.isNatureEnabled(nature) + " simple check: " + project.hasNature(nature));
54
					sleep(5);
55
				}
56
			} catch (CoreException e) {
57
				e.printStackTrace();
58
				fail("CoreExp");
59
			} catch (InterruptedException e) {
60
				e.printStackTrace();
61
				fail("InterruptedExp");
62
			}
63
		}
64
65
	}
66
67
	public void testConcurrentNatures() throws Exception {
68
		boolean finished[] = new boolean[1];
69
		finished[0] = false;
70
		CheckNatureThread t = new CheckNatureThread(finished);
71
		Project project = (Project) ResourcesPlugin.getWorkspace().getRoot().getProject(testProjectName);
72
		if (!project.exists()) {
73
			project.create(null);
74
		}
75
		if (!project.isOpen()) {
76
			project.open(null);
77
		}
78
		t.start();
79
80
		IFile descriptionFile = project.getFile(".project");
81
82
		descriptionFile.setContents(new FileInputStream(projectPath + "/.project"), 0, null);
83
84
		finished[0] = true;
85
		assertTrue(project.hasNature(nature));
86
		assertTrue(project.isNatureEnabled(nature));
87
	}
88
}
(-)src/org/eclipse/core/tests/resources/NatureTest.java (-1 / +75 lines)
Lines 18-24 Link Here
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.resources.*;
20
import org.eclipse.core.resources.*;
21
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.jobs.IJobManager;
22
import org.eclipse.core.runtime.jobs.IJobManager;
23
import org.eclipse.core.runtime.jobs.Job;
23
import org.eclipse.core.runtime.jobs.Job;
24
import org.eclipse.core.tests.internal.resources.SimpleNature;
24
import org.eclipse.core.tests.internal.resources.SimpleNature;
Lines 29-34 Link Here
29
 * APIs on IWorkspace are tested by IWorkspaceTest.
29
 * APIs on IWorkspace are tested by IWorkspaceTest.
30
 */
30
 */
31
public class NatureTest extends ResourceTest {
31
public class NatureTest extends ResourceTest {
32
33
	private static final String nature = "org.eclipse.jdt.core.javanature";
34
	private static final String testProjectName = "testProject";
35
32
	/**
36
	/**
33
	 * Constructor for NatureTest.
37
	 * Constructor for NatureTest.
34
	 */
38
	 */
Lines 345-348 Link Here
345
		out.close();
349
		out.close();
346
	}
350
	}
347
351
352
	private class CheckNatureThread extends Thread {
353
		private boolean finished[];
354
355
		public CheckNatureThread(boolean[] finished) {
356
			super();
357
			this.finished = finished;
358
		}
359
360
		public void run() {
361
			Project project = (Project) ResourcesPlugin.getWorkspace().getRoot().getProject(testProjectName);
362
363
			try {
364
				while (finished[0] == false) {
365
					if (project.exists() && project.isOpen())
366
						project.isNatureEnabled(nature);
367
					sleep(5);
368
				}
369
			} catch (CoreException e) {
370
				e.printStackTrace();
371
				fail("3.0", e);
372
			} catch (InterruptedException e) {
373
				e.printStackTrace();
374
				fail("3.1", e);
375
			}
376
		}
377
378
	}
379
380
	/**
381
	 * Changes project description and parallel checks {@link IProject#isNatureEnabled(String)},
382
	 * to check if natures value is cached properly.
383
	 * 
384
	 * See discussion on Bug 307587.
385
	 * @throws Exception
386
	 */
387
	public void testConcurrentNatures() throws Exception {
388
		boolean finished[] = new boolean[1];
389
		finished[0] = false;
390
		CheckNatureThread t = new CheckNatureThread(finished);
391
		IWorkspace ws = ResourcesPlugin.getWorkspace();
392
		Project project = (Project) ws.getRoot().getProject(testProjectName);
393
		ensureExistsInWorkspace(project, true);
394
395
		t.start();
396
397
		java.io.File desc = null;
398
		try {
399
			IFileStore descStore = ((File) project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME)).getStore();
400
			desc = descStore.toLocalFile(EFS.NONE, getMonitor());
401
		} catch (CoreException e) {
402
			fail("1.0");
403
		}
404
405
		String projectTemplatePath = FileLocator.resolve(Platform.getBundle("org.eclipse.core.tests.resources").getEntry("TestFiles/testProject")).getPath();
406
407
		java.io.File descTemplate = new java.io.File(projectTemplatePath + "/" + IProjectDescription.DESCRIPTION_FILE_NAME);
408
409
		copy(descTemplate, desc);
410
411
		try {
412
			project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
413
		} catch (CoreException e) {
414
			fail("2.0", e);
415
		}
416
417
		finished[0] = true;
418
		assertTrue("2.1", project.hasNature(nature));
419
		assertTrue("2.1", project.isNatureEnabled(nature));
420
	}
421
348
}
422
}

Return to bug 307587