View | Details | Raw Unified | Return to bug 226264 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/tests/resources/regression/AllTests.java (+1 lines)
Lines 50-55 Link Here
50
		suite.addTest(Bug_147232.suite());
50
		suite.addTest(Bug_147232.suite());
51
		suite.addTest(Bug_160251.suite());
51
		suite.addTest(Bug_160251.suite());
52
		suite.addTest(Bug_165892.suite());
52
		suite.addTest(Bug_165892.suite());
53
		suite.addTest(Bug_226264.suite());
53
		suite.addTest(IFileTest.suite());
54
		suite.addTest(IFileTest.suite());
54
		suite.addTest(IFolderTest.suite());
55
		suite.addTest(IFolderTest.suite());
55
		suite.addTest(IProjectTest.suite());
56
		suite.addTest(IProjectTest.suite());
(-)src/org/eclipse/core/tests/resources/regression/Bug_226264.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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.regression;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.tests.resources.ResourceTest;
18
19
public class Bug_226264 extends ResourceTest {
20
	/**
21
	 * Constructor for Bug_226264.
22
	 */
23
	public Bug_226264() {
24
		super();
25
	}
26
27
	/**
28
	 * Constructor for Bug_226264.
29
	 * @param name
30
	 */
31
	public Bug_226264(String name) {
32
		super(name);
33
	}
34
35
	public static Test suite() {
36
		return new TestSuite(Bug_226264.class);
37
	}
38
39
	public void testBug() throws CoreException {
40
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
41
		final IProject project1 = workspace.getRoot().getProject("Project1");
42
		project1.create(null);
43
		project1.open(null);
44
45
		final IProject project2 = workspace.getRoot().getProject("Project2");
46
		project2.create(null);
47
		project2.open(null);
48
49
		final WorkspaceJob job = new WorkspaceJob("job") {
50
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
51
				project2.delete(true, null);
52
				return Status.OK_STATUS;
53
			}
54
		};
55
56
		// the listener will schedule another project delete
57
		workspace.addResourceChangeListener(new IResourceChangeListener() {
58
			public void resourceChanged(IResourceChangeEvent event) {
59
				if (event.getResource() == project1) {
60
					// because notification is run in a protected block,
61
					// this job will start after the notification
62
					job.schedule();
63
				}
64
			}
65
		}, IResourceChangeEvent.PRE_DELETE);
66
67
		// delete project
68
		project1.delete(true, null);
69
70
		try {
71
			job.join();
72
		} catch (InterruptedException e) {
73
			fail("1.0", e);
74
		}
75
76
		assertTrue("2.0: " + job.getResult().toString(), job.getResult().isOK());
77
78
		assertDoesNotExistInWorkspace("3.0", project1);
79
		assertDoesNotExistInWorkspace("4.0", project2);
80
	}
81
}
(-)src/org/eclipse/core/internal/resources/Resource.java (-8 / +38 lines)
Lines 692-697 Link Here
692
				if (!exists())
692
				if (!exists())
693
					return;
693
					return;
694
				workspace.beginOperation(true);
694
				workspace.beginOperation(true);
695
				broadcastPreDeleteEvent();
695
				final IFileStore originalStore = getStore();
696
				final IFileStore originalStore = getStore();
696
				boolean wasLinked = isLinked();
697
				boolean wasLinked = isLinked();
697
				message = Messages.resources_deleteProblem;
698
				message = Messages.resources_deleteProblem;
Lines 1397-1402 Link Here
1397
				// and assert for programming errors. See checkMoveRequirements for more information.
1398
				// and assert for programming errors. See checkMoveRequirements for more information.
1398
				assertMoveRequirements(destination, getType(), updateFlags);
1399
				assertMoveRequirements(destination, getType(), updateFlags);
1399
				workspace.beginOperation(true);
1400
				workspace.beginOperation(true);
1401
				broadcastPreMoveEvent(destResource, updateFlags);
1400
				IFileStore originalStore = getStore();
1402
				IFileStore originalStore = getStore();
1401
				message = Messages.resources_moveProblem;
1403
				message = Messages.resources_moveProblem;
1402
				MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, null);
1404
				MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, null);
Lines 1713-1719 Link Here
1713
					tree.standardDeleteFolder((IFolder) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000));
1715
					tree.standardDeleteFolder((IFolder) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000));
1714
				break;
1716
				break;
1715
			case IResource.PROJECT :
1717
			case IResource.PROJECT :
1716
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, this));
1717
				if (!hook.deleteProject(tree, (IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / 2)))
1718
				if (!hook.deleteProject(tree, (IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / 2)))
1718
					tree.standardDeleteProject((IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000));
1719
					tree.standardDeleteProject((IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000));
1719
				break;
1720
				break;
Lines 1725-1731 Link Here
1725
				System.arraycopy(roots, 0, projects, 0, roots.length);
1726
				System.arraycopy(roots, 0, projects, 0, roots.length);
1726
1727
1727
				for (int i = 0; i < projects.length; i++) {
1728
				for (int i = 0; i < projects.length; i++) {
1728
					workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, projects[i]));
1729
					if (!hook.deleteProject(tree, projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length / 2)))
1729
					if (!hook.deleteProject(tree, projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length / 2)))
1730
						tree.standardDeleteProject(projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length));
1730
						tree.standardDeleteProject(projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length));
1731
				}
1731
				}
Lines 1741-1754 Link Here
1741
		IMoveDeleteHook hook = workspace.getMoveDeleteHook();
1741
		IMoveDeleteHook hook = workspace.getMoveDeleteHook();
1742
		switch (getType()) {
1742
		switch (getType()) {
1743
			case IResource.FILE :
1743
			case IResource.FILE :
1744
				if (isLinked())
1745
					workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags));
1746
				if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
1744
				if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
1747
					tree.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
1745
					tree.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
1748
				break;
1746
				break;
1749
			case IResource.FOLDER :
1747
			case IResource.FOLDER :
1750
				if (isLinked())
1751
					workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags));
1752
				if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
1748
				if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
1753
					tree.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
1749
					tree.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
1754
				break;
1750
				break;
Lines 1757-1764 Link Here
1757
				// if there is no change in name, there is nothing to do so return.
1753
				// if there is no change in name, there is nothing to do so return.
1758
				if (getName().equals(destination.getName()))
1754
				if (getName().equals(destination.getName()))
1759
					return false;
1755
					return false;
1760
				//we are deleting the source project so notify.
1761
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_MOVE, this, destination, updateFlags));
1762
				IProjectDescription description = project.getDescription();
1756
				IProjectDescription description = project.getDescription();
1763
				description.setName(destination.getName());
1757
				description.setName(destination.getName());
1764
				if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
1758
				if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
Lines 1770-1773 Link Here
1770
		}
1764
		}
1771
		return true;
1765
		return true;
1772
	}
1766
	}
1767
	
1768
	private void broadcastPreDeleteEvent() throws CoreException {
1769
		switch (getType()) {
1770
			case IResource.PROJECT :
1771
				workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, this));
1772
				break;
1773
			case IResource.ROOT :
1774
				// when the root is deleted, all its children including hidden projects
1775
				// have to be deleted
1776
				IResource[] roots = ((Container) this).getChildren(IContainer.INCLUDE_HIDDEN);
1777
				IProject[] projects = new IProject[roots.length];
1778
				System.arraycopy(roots, 0, projects, 0, roots.length);
1779
				for (int i = 0; i < projects.length; i++) {
1780
					workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, projects[i]));
1781
				}
1782
		}
1783
	}
1784
	
1785
	private void broadcastPreMoveEvent(final IResource destination, int updateFlags) throws CoreException {
1786
		switch (getType()) {
1787
			case IResource.FILE :
1788
				if (isLinked())
1789
					workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags));
1790
				break;
1791
			case IResource.FOLDER :
1792
				if (isLinked())
1793
					workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags));
1794
				break;
1795
			case IResource.PROJECT :
1796
				if (!getName().equals(destination.getName())) {
1797
					// if there is a change in name, we are deleting the source project so notify.
1798
					workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_MOVE, this, destination, updateFlags));
1799
				}
1800
				break;
1801
		}
1802
	}
1773
}
1803
}
(-)src/org/eclipse/core/internal/resources/Workspace.java (+1 lines)
Lines 1865-1870 Link Here
1865
	}
1865
	}
1866
1866
1867
	public void setTreeLocked(boolean locked) {
1867
	public void setTreeLocked(boolean locked) {
1868
		Assert.isTrue(!locked || treeLocked == null, "The workspace tree is already locked"); //$NON-NLS-1$
1868
		treeLocked = locked ? Thread.currentThread() : null;
1869
		treeLocked = locked ? Thread.currentThread() : null;
1869
	}
1870
	}
1870
1871

Return to bug 226264