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 (-3 / +3 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 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 (-18 / +23 lines)
Lines 343-363 Link Here
343
		if (segmentCount > 2)
343
		if (segmentCount > 2)
344
			qualifier = getSegment(path, 2);
344
			qualifier = getSegment(path, 2);
345
345
346
		if (segmentCount != 2)
346
		initialize();
347
			return;
348
349
		// else segmentCount == 2 so we initialize the children
350
		if (initialized)
351
			return;
352
		try {
353
			synchronized (this) {
354
				String[] names = computeChildren();
355
				for (int i = 0; i < names.length; i++)
356
					addChild(names[i], null);
357
			}
358
		} finally {
359
			initialized = true;
360
		}
361
	}
347
	}
362
348
363
	/*
349
	/*
Lines 479-484 Link Here
479
		return super.internalPut(key, newValue);
465
		return super.internalPut(key, newValue);
480
	}
466
	}
481
467
468
	protected void initialize() {
469
		if (segmentCount != 2)
470
			return;
471
472
		// if already initialized, then skip this initialization
473
		if (initialized)
474
			return;
475
		// initialize the children only if project is opened
476
		if (project.isOpen()) {
477
			try {
478
				synchronized (this) {
479
					String[] names = computeChildren();
480
					for (int i = 0; i < names.length; i++)
481
						addChild(names[i], null);
482
				}
483
			} finally {
484
				// mark as initialized so that subsequent project opening will not initialize preferences again
485
				initialized = true;
486
			}
487
		}
488
	}
489
482
	protected boolean isAlreadyLoaded(IEclipsePreferences node) {
490
	protected boolean isAlreadyLoaded(IEclipsePreferences node) {
483
		return loadedNodes.contains(node.absolutePath());
491
		return loadedNodes.contains(node.absolutePath());
484
	}
492
	}
Lines 513-521 Link Here
513
			FileUtil.safeClose(input);
521
			FileUtil.safeClose(input);
514
		}
522
		}
515
		convertFromProperties(this, fromDisk, true);
523
		convertFromProperties(this, fromDisk, true);
516
	}
517
518
	protected void loaded() {
519
		loadedNodes.add(absolutePath());
524
		loadedNodes.add(absolutePath());
520
	}
525
	}
521
526
(-)src/org/eclipse/core/tests/resources/session/AllTests.java (+1 lines)
Lines 52-57 Link Here
52
		suite.addTest(org.eclipse.core.tests.resources.regression.TestMultipleBuildersOfSameType.suite());
52
		suite.addTest(org.eclipse.core.tests.resources.regression.TestMultipleBuildersOfSameType.suite());
53
		suite.addTest(org.eclipse.core.tests.resources.usecase.SnapshotTest.suite());
53
		suite.addTest(org.eclipse.core.tests.resources.usecase.SnapshotTest.suite());
54
		suite.addTest(ProjectDescriptionDynamicTest.suite());
54
		suite.addTest(ProjectDescriptionDynamicTest.suite());
55
		suite.addTest(TestBug202384.suite());
55
		return suite;
56
		return suite;
56
	}
57
	}
57
}
58
}
(-)src/org/eclipse/core/tests/resources/session/TestBug202384.java (+111 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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 created 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