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

Collapse All | Expand All

(-)src/org/eclipse/core/internal/resources/Project.java (-2 / +2 lines)
Lines 15-22 Link Here
15
 *******************************************************************************/
15
 *******************************************************************************/
16
package org.eclipse.core.internal.resources;
16
package org.eclipse.core.internal.resources;
17
17
18
import java.util.LinkedHashSet;
19
20
import java.net.URI;
18
import java.net.URI;
21
import java.util.*;
19
import java.util.*;
22
import org.eclipse.core.filesystem.*;
20
import org.eclipse.core.filesystem.*;
Lines 1158-1163 Link Here
1158
						}
1156
						}
1159
					}
1157
					}
1160
				}
1158
				}
1159
				//initialize this project preferences
1160
				((ProjectPreferences) Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE).node(getName())).initialize();
1161
				//creation of this project may affect overlapping resources
1161
				//creation of this project may affect overlapping resources
1162
				workspace.getAliasManager().updateAliases(this, getStore(), IResource.DEPTH_INFINITE, monitor);
1162
				workspace.getAliasManager().updateAliases(this, getStore(), IResource.DEPTH_INFINITE, monitor);
1163
			} catch (OperationCanceledException e) {
1163
			} catch (OperationCanceledException e) {
(-)src/org/eclipse/core/internal/resources/ProjectPreferences.java (-16 / +24 lines)
Lines 305-311 Link Here
305
			// Bug 108066: In case the node had existed before it was updated from
305
			// Bug 108066: In case the node had existed before it was updated from
306
			// file, the read() operation marks it dirty. Override the dirty flag
306
			// file, the read() operation marks it dirty. Override the dirty flag
307
			// since we know that the node is expected to be in sync with the file.
307
			// since we know that the node is expected to be in sync with the file.
308
			projectPrefs.dirty= false;
308
			projectPrefs.dirty = false;
309
309
310
			// make sure that we generate the appropriate resource change events
310
			// make sure that we generate the appropriate resource change events
311
			// if encoding settings have changed
311
			// if encoding settings have changed
Lines 348-368 Link Here
348
			addPreferenceChangeListener(workspace.getCharsetManager().getPreferenceChangeListener());
348
			addPreferenceChangeListener(workspace.getCharsetManager().getPreferenceChangeListener());
349
		}
349
		}
350
350
351
		if (segmentCount != 2)
351
		initialize();
352
			return;
353
354
		// else segmentCount == 2 so we initialize the children
355
		if (initialized)
356
			return;
357
		try {
358
			synchronized (this) {
359
				String[] names = computeChildren();
360
				for (int i = 0; i < names.length; i++)
361
					addChild(names[i], null);
362
			}
363
		} finally {
364
			initialized = true;
365
		}
366
	}
352
	}
367
353
368
	/*
354
	/*
Lines 471-476 Link Here
471
		return new ProjectPreferences(nodeParent, nodeName);
457
		return new ProjectPreferences(nodeParent, nodeName);
472
	}
458
	}
473
459
460
	protected void initialize() {
461
		if (segmentCount != 2)
462
			return;
463
464
		// if already initialized, then skip this initialization
465
		if (initialized)
466
			return;
467
		// initialize the children only if project is opened
468
		if (project.isOpen()) {
469
			try {
470
				synchronized (this) {
471
					String[] names = computeChildren();
472
					for (int i = 0; i < names.length; i++)
473
						addChild(names[i], null);
474
				}
475
			} finally {
476
				// mark as initialized so that subsequent project opening will not initialize preferences again
477
				initialized = true;
478
			}
479
		}
480
	}
481
474
	protected boolean isAlreadyLoaded(IEclipsePreferences node) {
482
	protected boolean isAlreadyLoaded(IEclipsePreferences node) {
475
		return loadedNodes.contains(node.absolutePath());
483
		return loadedNodes.contains(node.absolutePath());
476
	}
484
	}
(-)src/org/eclipse/core/tests/resources/session/AllTests.java (+1 lines)
Lines 51-56 Link Here
51
		suite.addTest(org.eclipse.core.tests.resources.regression.TestMultipleBuildersOfSameType.suite());
51
		suite.addTest(org.eclipse.core.tests.resources.regression.TestMultipleBuildersOfSameType.suite());
52
		suite.addTest(org.eclipse.core.tests.resources.usecase.SnapshotTest.suite());
52
		suite.addTest(org.eclipse.core.tests.resources.usecase.SnapshotTest.suite());
53
		suite.addTest(ProjectDescriptionDynamicTest.suite());
53
		suite.addTest(ProjectDescriptionDynamicTest.suite());
54
		suite.addTest(TestBug202384.suite());
54
		return suite;
55
		return suite;
55
	}
56
	}
56
}
57
}
(-)src/org/eclipse/core/tests/resources/session/TestBug202384.java (+111 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.session;
12
13
import junit.framework.Test;
14
import org.eclipse.core.resources.*;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.tests.resources.AutomatedTests;
17
import org.eclipse.core.tests.resources.WorkspaceSessionTest;
18
import org.eclipse.core.tests.session.WorkspaceSessionTestSuite;
19
20
/**
21
 * Test for bug 202384
22
 */
23
public class TestBug202384 extends WorkspaceSessionTest {
24
	public TestBug202384() {
25
		super();
26
	}
27
28
	public TestBug202384(String name) {
29
		super(name);
30
	}
31
32
	public void testInitializeWorkspace() {
33
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
34
		IProject project = workspace.getRoot().getProject("project");
35
		ensureExistsInWorkspace(project, true);
36
		try {
37
			project.setDefaultCharset("UTF-8", getMonitor());
38
		} catch (CoreException e1) {
39
			fail("1.0", e1);
40
		}
41
		try {
42
			assertEquals("UTF-8", project.getDefaultCharset());
43
		} catch (CoreException e) {
44
			fail("2.0", e);
45
		}
46
		try {
47
			project.close(getMonitor());
48
		} catch (CoreException e) {
49
			fail("3.0", e);
50
		}
51
		assertFalse(project.isOpen());
52
		try {
53
			workspace.save(true, getMonitor());
54
		} catch (CoreException e) {
55
			fail("4.0", e);
56
		}
57
	}
58
59
	public void testStartWithClosedProject() {
60
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
61
		IProject project = workspace.getRoot().getProject("project");
62
		assertFalse(project.isOpen());
63
		try {
64
			//ProjectPreferences should get created on getDefaultCharset but not
65
			//initialized hence it is not possible to read correct encoding
66
			assertNull(project.getDefaultCharset(false));
67
		} catch (CoreException e) {
68
			fail("1.0", e);
69
		}
70
		try {
71
			//opening project should re-initialize already loaded ProjectPreferences
72
			//because project resources are now available
73
			project.open(getMonitor());
74
		} catch (CoreException e) {
75
			fail("2.0", e);
76
		}
77
		try {
78
			//correct values should be available after re-initialization
79
			assertEquals("UTF-8", project.getDefaultCharset());
80
		} catch (CoreException e) {
81
			fail("3.0", e);
82
		}
83
		try {
84
			workspace.save(true, getMonitor());
85
		} catch (CoreException e) {
86
			fail("4.0", e);
87
		}
88
	}
89
90
	public void testStartWithOpenProject() {
91
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
92
		IProject project = workspace.getRoot().getProject("project");
93
		assertTrue(project.isOpen());
94
		try {
95
			//correct values should be available if ProjectPreferences got
96
			//initialized upon creation
97
			assertEquals("UTF-8", project.getDefaultCharset(false));
98
		} catch (CoreException e) {
99
			fail("1.0", e);
100
		}
101
		try {
102
			workspace.save(true, getMonitor());
103
		} catch (CoreException e) {
104
			fail("2.0", e);
105
		}
106
	}
107
108
	public static Test suite() {
109
		return new WorkspaceSessionTestSuite(AutomatedTests.PI_RESOURCES_TESTS, TestBug202384.class);
110
	}
111
}

Return to bug 202384