### Eclipse Workspace Patch 1.0 #P org.eclipse.core.tests.resources Index: src/org/eclipse/core/tests/resources/NatureTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java,v retrieving revision 1.11 diff -u -r1.11 NatureTest.java --- src/org/eclipse/core/tests/resources/NatureTest.java 17 Jul 2006 15:00:15 -0000 1.11 +++ src/org/eclipse/core/tests/resources/NatureTest.java 25 Jan 2008 12:10:30 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,7 +13,9 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.jobs.IJobManager; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.tests.internal.resources.SimpleNature; /** @@ -214,4 +216,47 @@ } } } + + /** + * Test addition of nature that requires the workspace root. + * See bugs 127562 and 128709. + */ + public void testBug127562Nature() { + IWorkspace ws = ResourcesPlugin.getWorkspace(); + IProject project = ws.getRoot().getProject("Project"); + ensureExistsInWorkspace(project, true); + + String[][] valid = getValidNatureSets(); + for (int i = 0; i < valid.length; i++) { + setNatures("valid: " + i, project, valid[i], false); + } + + // add with AVOID_NATURE_CONFIG + String[] currentSet = new String[] {NATURE_127562}; + setNatures("1.0", project, currentSet, false, true); + + // configure the nature using a conflicting scheduling rule + IJobManager manager = Job.getJobManager(); + try { + manager.beginRule(ws.getRuleFactory().modifyRule(project), null); + project.getNature(NATURE_127562).configure(); + fail("2.0"); + } catch (CoreException ex) { + fail("2.1"); + } catch (IllegalArgumentException ex) { + // should throw this kind of exception + } finally { + manager.endRule(ws.getRuleFactory().modifyRule(project)); + } + + // configure the nature using a non-conflicting scheduling rule + try { + manager.beginRule(ws.getRoot(), null); + project.getNature(NATURE_127562).configure(); + } catch (CoreException ex) { + fail("3.0"); + } finally { + manager.endRule(ws.getRoot()); + } + } } Index: src/org/eclipse/core/tests/resources/ResourceTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceTest.java,v retrieving revision 1.23 diff -u -r1.23 ResourceTest.java --- src/org/eclipse/core/tests/resources/ResourceTest.java 12 Sep 2007 14:46:34 -0000 1.23 +++ src/org/eclipse/core/tests/resources/ResourceTest.java 25 Jan 2008 12:10:30 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -54,6 +54,8 @@ protected static final String NATURE_MUD = "org.eclipse.core.tests.resources.mudNature"; //simpleNature protected static final String NATURE_SIMPLE = "org.eclipse.core.tests.resources.simpleNature"; + //nature for regression tests of bug 127562 + protected static final String NATURE_127562 = "org.eclipse.core.tests.resources.bug127562Nature"; //snowNature, requires: waterNature, one-of: otherSet protected static final String NATURE_SNOW = "org.eclipse.core.tests.resources.snowNature"; //waterNature, one-of: stateSet Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/plugin.xml,v retrieving revision 1.74 diff -u -r1.74 plugin.xml --- plugin.xml 17 Apr 2007 15:51:29 -0000 1.74 +++ plugin.xml 25 Jan 2008 12:10:30 -0000 @@ -254,5 +254,14 @@ + + + + + + Index: src/org/eclipse/core/tests/resources/regression/Bug_127562.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_127562.java,v retrieving revision 1.3 diff -u -r1.3 Bug_127562.java --- src/org/eclipse/core/tests/resources/regression/Bug_127562.java 17 Jul 2006 15:00:15 -0000 1.3 +++ src/org/eclipse/core/tests/resources/regression/Bug_127562.java 25 Jan 2008 12:10:30 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -47,7 +47,7 @@ public void run(IProgressMonitor monitor) throws CoreException { project.setDescription(finalDescription, getMonitor()); } - }, getWorkspace().getRuleFactory().modifyRule(project), IResource.NONE, getMonitor()); + }, getWorkspace().getRoot(), IResource.NONE, getMonitor()); } catch (CoreException e) { fail("4.99", e); } Index: src/org/eclipse/core/tests/internal/resources/Bug127562Nature.java =================================================================== RCS file: src/org/eclipse/core/tests/internal/resources/Bug127562Nature.java diff -N src/org/eclipse/core/tests/internal/resources/Bug127562Nature.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/core/tests/internal/resources/Bug127562Nature.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.core.tests.internal.resources; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; + +/** + * This nature will try to modify resources outside the project scope. + */ +public class Bug127562Nature extends TestNature { + /** + * Constructor for SimpleNature. + */ + public Bug127562Nature() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.core.resources.IProjectNature#configure() + */ + public void configure() throws CoreException { + super.configure(); + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("Project" + System.currentTimeMillis()); + p.create(null); + } + + /* (non-Javadoc) + * @see org.eclipse.core.resources.IProjectNature#deconfigure() + */ + public void deconfigure() throws CoreException { + super.deconfigure(); + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("Project" + System.currentTimeMillis()); + p.create(null); + } +} #P org.eclipse.core.resources Index: src/org/eclipse/core/internal/resources/Project.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java,v retrieving revision 1.146 diff -u -r1.146 Project.java --- src/org/eclipse/core/internal/resources/Project.java 6 Dec 2007 20:38:15 -0000 1.146 +++ src/org/eclipse/core/internal/resources/Project.java 25 Jan 2008 12:10:33 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -980,7 +980,11 @@ monitor = Policy.monitorFor(monitor); try { monitor.beginTask(Messages.resources_setDesc, Policy.totalWork); - final ISchedulingRule rule = workspace.getRoot(); + ISchedulingRule rule = null; + if ((updateFlags & IResource.AVOID_NATURE_CONFIG) != 0) + rule = workspace.getRuleFactory().modifyRule(this); + else + rule = workspace.getRoot(); try { //need to use root rule because nature configuration calls third party code workspace.prepareOperation(rule, monitor); Index: src/org/eclipse/core/resources/team/ResourceRuleFactory.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/team/ResourceRuleFactory.java,v retrieving revision 1.11 diff -u -r1.11 ResourceRuleFactory.java --- src/org/eclipse/core/resources/team/ResourceRuleFactory.java 1 Mar 2007 19:47:55 -0000 1.11 +++ src/org/eclipse/core/resources/team/ResourceRuleFactory.java 25 Jan 2008 12:10:33 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -145,9 +145,6 @@ * @see IProjectDescription#DESCRIPTION_FILE_NAME */ public ISchedulingRule modifyRule(IResource resource) { - //modifying the project description requires the root - if (resource.getType() == IResource.PROJECT) - return workspace.getRoot(); IPath path = resource.getFullPath(); //modifying the project description may cause linked resources to be created or deleted if (path.segmentCount() == 2 && path.segment(1).equals(IProjectDescription.DESCRIPTION_FILE_NAME)) Index: src/org/eclipse/core/resources/IProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/IProject.java,v retrieving revision 1.42 diff -u -r1.42 IProject.java --- src/org/eclipse/core/resources/IProject.java 30 Nov 2007 16:13:28 -0000 1.42 +++ src/org/eclipse/core/resources/IProject.java 25 Jan 2008 12:10:33 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -699,6 +699,10 @@ * *

*

+ * The scheduling rule for the operation is the root rule + * required when added and removed natures are configured and de-configured. + *

+ *

* This method changes resources; these changes will be reported * in a subsequent resource change event, including an indication * that the project's content has changed. @@ -730,7 +734,6 @@ * @see IProjectNature#configure() * @see IProjectNature#deconfigure() * @see #setDescription(IProjectDescription,int,IProgressMonitor) - * @see IResourceRuleFactory#modifyRule(IResource) */ public void setDescription(IProjectDescription description, IProgressMonitor monitor) throws CoreException; @@ -784,6 +787,13 @@ * removed, but they will not be configured or de-configured. *

*

+ * The scheduling rule required for this operation depends on the + * AVOID_NATURE_CONFIG flag. If the flag is specified the + * {@link IResourceRuleFactory#modifyRule} is used since added and removed natures + * won't be configured and de-configured. If the flag is not specified, the root rule is used + * what is required when natures are configured and de-configured. + *

+ *

* Update flags other than FORCE, KEEP_HISTORY, * and AVOID_NATURE_CONFIG are ignored. *