View | Details | Raw Unified | Return to bug 266907
Collapse All | Expand All

(-)src/org/eclipse/core/tests/resources/session/AllTests.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 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 40-45 Link Here
40
		suite.addTest(ProjectPreferenceSessionTest.suite());
40
		suite.addTest(ProjectPreferenceSessionTest.suite());
41
		suite.addTest(TestBug113943.suite());
41
		suite.addTest(TestBug113943.suite());
42
		suite.addTest(TestCreateLinkedResourceInHiddenProject.suite());
42
		suite.addTest(TestCreateLinkedResourceInHiddenProject.suite());
43
		suite.addTest(Bug_266907.suite());
43
		// this one comes from org.eclipse.core.tests.resources.saveparticipant
44
		// this one comes from org.eclipse.core.tests.resources.saveparticipant
44
		// comment this out until we have a better solution for running these tests
45
		// comment this out until we have a better solution for running these tests
45
		// (keeping their contents inside this plugin as subdirs and dynamically installing
46
		// (keeping their contents inside this plugin as subdirs and dynamically installing
(-)src/org/eclipse/core/tests/resources/session/Bug_266907.java (+130 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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 java.io.*;
14
import junit.framework.Test;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.NullProgressMonitor;
18
import org.eclipse.core.tests.resources.WorkspaceSessionTest;
19
import org.eclipse.core.tests.session.WorkspaceSessionTestSuite;
20
21
/**
22
 * Tests for bug 266907
23
 */
24
public class Bug_266907 extends WorkspaceSessionTest {
25
26
	private static final String PROJECT_NAME = "Project";
27
	private static final String FILE_NAME = "File";
28
	private static final String MARKER_ATTRIBUTE_NAME = "AttributeName";
29
	private static final String MARKER_ATTRIBUTE = "Attribute";
30
31
	public static Test suite() {
32
		return new WorkspaceSessionTestSuite(PI_RESOURCES_TESTS, Bug_266907.class);
33
	}
34
35
	public Bug_266907(String name) {
36
		super(name);
37
	}
38
39
	public void test1stSession() {
40
		final IWorkspace workspace = getWorkspace();
41
		IProject project = workspace.getRoot().getProject(PROJECT_NAME);
42
		try {
43
			project.create(getMonitor());
44
			project.open(getMonitor());
45
		} catch (CoreException e1) {
46
			fail("1.0", e1);
47
		}
48
49
		IFile f = project.getFile(FILE_NAME);
50
		try {
51
			f.create(getContents("content"), true, getMonitor());
52
		} catch (CoreException e1) {
53
			fail("2.0", e1);
54
		}
55
56
		try {
57
			IMarker marker = f.createMarker(IMarker.BOOKMARK);
58
			marker.setAttribute(MARKER_ATTRIBUTE_NAME, MARKER_ATTRIBUTE);
59
		} catch (CoreException e2) {
60
			fail("3.0", e2);
61
		}
62
63
		// remember the location of .project to delete is at the end
64
		File dotProject = project.getFile(".project").getLocation().toFile();
65
66
		try {
67
			workspace.save(true, getMonitor());
68
		} catch (CoreException e) {
69
			fail("4.0", e);
70
		}
71
72
		// move .project to a temp location
73
		File dotProjectCopy = getTempDir().append("dotProjectCopy").toFile();
74
		try {
75
			dotProjectCopy.createNewFile();
76
			transferStreams(new FileInputStream(dotProject), new FileOutputStream(dotProjectCopy), null, new NullProgressMonitor());
77
			dotProject.delete();
78
		} catch (FileNotFoundException e) {
79
			fail("5.0", e);
80
		} catch (IOException e) {
81
			fail("5.1", e);
82
		}
83
	}
84
85
	public void test2ndSession() {
86
		final IWorkspace workspace = getWorkspace();
87
		IProject project = workspace.getRoot().getProject(PROJECT_NAME);
88
89
		// the project should be closed cause .project is removed
90
		assertTrue("1.0", !project.isAccessible());
91
92
		// recreate .project
93
		File dotProject = project.getFile(".project").getLocation().toFile();
94
		File dotProjectCopy = getTempDir().append("dotProjectCopy").toFile();
95
		try {
96
			dotProject.createNewFile();
97
			transferStreams(new FileInputStream(dotProjectCopy), new FileOutputStream(dotProject), null, new NullProgressMonitor());
98
			dotProjectCopy.delete();
99
		} catch (IOException e1) {
100
			fail("2.0", e1);
101
		}
102
103
		try {
104
			project.open(getMonitor());
105
		} catch (CoreException e) {
106
			fail("3.0", e);
107
		}
108
109
		assertTrue("4.0", project.isAccessible());
110
111
		IFile file = project.getFile(FILE_NAME);
112
		IMarker[] markers = null;
113
		try {
114
			markers = file.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
115
		} catch (CoreException e) {
116
			fail("5.0", e);
117
		}
118
119
		assertNotNull("6.0", markers);
120
		assertEquals("6.1", markers.length, 1);
121
122
		Object attribute = null;
123
		try {
124
			attribute = markers[0].getAttribute(MARKER_ATTRIBUTE_NAME);
125
		} catch (CoreException e) {
126
			fail("7.0", e);
127
		}
128
		assertEquals("8.0", attribute, MARKER_ATTRIBUTE);
129
	}
130
}
(-)src/org/eclipse/core/internal/resources/SaveManager.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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 813-819 Link Here
813
		}
813
		}
814
		project.internalSetDescription(description, false);
814
		project.internalSetDescription(description, false);
815
		if (failure != null) {
815
		if (failure != null) {
816
			//close the project
816
			// write the project tree ...
817
			writeTree(project, IResource.DEPTH_INFINITE);
818
			// ... and close the project
817
			project.internalClose();
819
			project.internalClose();
818
			throw failure;
820
			throw failure;
819
		}
821
		}

Return to bug 266907