diff options
author | Pawel Pogorzelski | 2010-05-13 11:54:45 +0000 |
---|---|---|
committer | Pawel Pogorzelski | 2010-05-13 11:54:45 +0000 |
commit | 0b1d425c86b5ef5c30d75506e1539f5de47bceae (patch) | |
tree | f5ac4958b95a6b8cd0876f8362a07aab08b9bc2e | |
parent | 12d86a176c8c7787cb64c69c052c5020d4f0cd8c (diff) | |
download | eclipse.platform.resources-0b1d425c86b5ef5c30d75506e1539f5de47bceae.tar.gz eclipse.platform.resources-0b1d425c86b5ef5c30d75506e1539f5de47bceae.tar.xz eclipse.platform.resources-0b1d425c86b5ef5c30d75506e1539f5de47bceae.zip |
Bug 297871 - Project natures are not updated in project model in some cases.V20100513-0800
3 files changed, 103 insertions, 5 deletions
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java index acac16d9f..f67c66fa0 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -402,7 +402,11 @@ public class File extends Resource implements IFile { String name = path.segment(1); // is this a project description file? if (count == 2 && name.equals(IProjectDescription.DESCRIPTION_FILE_NAME)) { - ((Project) getProject()).updateDescription(); + Project project = (Project) getProject(); + project.updateDescription(); + // Discard stale project natures on ProjectInfo + ProjectInfo projectInfo = (ProjectInfo) project.getResourceInfo(false, true); + projectInfo.discardNatures(); return; } // check to see if we are in the .settings directory diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectInfo.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectInfo.java index e67d5ba88..af16c9f26 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectInfo.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -31,6 +31,14 @@ public class ProjectInfo extends ResourceInfo { protected IContentTypeMatcher matcher = null; /** + * Discards stale natures on this project after project description + * has changed. + */ + public synchronized void discardNatures() { + natures = null; + } + + /** * Discards any stale state on this project after it has been moved. Builder * instances must be cleared because they reference the old project handle. */ diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java index 76aed0b89..cfb811734 100644 --- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java +++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -10,10 +10,15 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import java.io.*; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.internal.resources.File; +import org.eclipse.core.internal.resources.Project; import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.jobs.IJobManager; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.tests.internal.resources.SimpleNature; @@ -259,4 +264,85 @@ public class NatureTest extends ResourceTest { manager.endRule(ws.getRoot()); } } + + public void testBug297871() { + IWorkspace ws = ResourcesPlugin.getWorkspace(); + Project project = (Project) ws.getRoot().getProject("Project"); + ensureExistsInWorkspace(project, true); + + java.io.File desc = null; + try { + IFileStore descStore = ((File) project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME)).getStore(); + desc = descStore.toLocalFile(EFS.NONE, getMonitor()); + } catch (CoreException e) { + fail("1.0"); + } + + java.io.File descTmp = new java.io.File(desc.getPath() + ".tmp"); + try { + copy(desc, descTmp); + } catch (IOException e) { + fail("2.0", e); + } + + setNatures("valid ", project, new String[] {NATURE_EARTH}, false); + + try { + assertNotNull(project.getNature(NATURE_EARTH)); + } catch (CoreException e) { + fail("3.0", e); + } + + try { + assertTrue(project.hasNature(NATURE_EARTH)); + } catch (CoreException e) { + fail("4.0", e); + } + + try { + // Make sure enough time has past to bump file's + // timestamp during the copy + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + fail("5.0", e); + } + + try { + copy(descTmp, desc); + } catch (IOException e) { + fail("6.0", e); + } + + try { + project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); + } catch (CoreException e) { + fail("7.0", e); + } + + try { + assertNull(project.getNature(NATURE_EARTH)); + } catch (CoreException e) { + fail("8.0", e); + } + + try { + assertFalse(project.hasNature(NATURE_EARTH)); + } catch (CoreException e) { + fail("9.0", e); + } + } + + private void copy(java.io.File src, java.io.File dst) throws IOException { + InputStream in = new FileInputStream(src); + OutputStream out = new FileOutputStream(dst); + + byte[] buffer = new byte[1024]; + int read; + while ((read = in.read(buffer)) > 0) { + out.write(buffer, 0, read); + } + in.close(); + out.close(); + } + } |