-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stale resource link flags after project re-open
Whenever a project is closed, its resource tree is saved. This includes linked resources in the project. When the project is re-opened, link changes in the .project file are not reflected on the projects resource tree. The old resource tree is read, new information is stored in ProjectDescription.linkDescriptions, but the old linked resources are not touched. This change adjusts Project.open() and Project.close() to set resp. clear the M_LINK flag of linked resources in the project. Fixes: #470 Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
- Loading branch information
1 parent
39d33ea
commit 13b3ddd
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...g.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectLinksTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Simeon Andreev and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Simeon Andreev - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.core.tests.resources; | ||
|
||
import java.nio.file.*; | ||
import java.util.List; | ||
import org.eclipse.core.resources.*; | ||
import org.eclipse.core.runtime.IPath; | ||
|
||
/** | ||
* | ||
*/ | ||
public class ProjectLinksTest extends ResourceTest { | ||
|
||
private IProject project; | ||
private Path tmpFolder; | ||
private IPath tmpPath; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
tmpPath = getRandomLocation(); | ||
tmpFolder = Paths.get(tmpPath.toOSString()); | ||
Files.createDirectory(tmpFolder); | ||
|
||
IWorkspaceRoot root = getWorkspace().getRoot(); | ||
project = root.getProject(getUniqueString()); | ||
|
||
project.create(getMonitor()); | ||
project.open(getMonitor()); | ||
project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); | ||
} | ||
|
||
@Override | ||
protected void tearDown() throws Exception { | ||
try { | ||
Files.deleteIfExists(tmpFolder); | ||
project.delete(true, getMonitor()); | ||
} finally { | ||
super.tearDown(); | ||
} | ||
} | ||
|
||
/** | ||
* Tests that link information is updated after closing a project, deleting a | ||
* link in the {@code .project} file and then opening the project. | ||
*/ | ||
public void testCloseProjectDeleteLinksAndOpen_GH470() throws Exception { | ||
IFile dotProject = project.getFile(".project"); | ||
Path dotProjectPath = Paths.get(dotProject.getLocationURI()); | ||
List<String> dotProjectContentsWithoutLink = Files.readAllLines(dotProjectPath); | ||
|
||
String linkedFolderName = "test"; | ||
IFolder folder = project.getFolder(linkedFolderName); | ||
folder.createLink(tmpPath, IResource.NONE, getMonitor()); | ||
project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); | ||
|
||
assertTrue("Failed to create linked folder in test project", folder.isLinked()); | ||
|
||
project.close(getMonitor()); | ||
|
||
Files.write(dotProjectPath, dotProjectContentsWithoutLink); | ||
|
||
project.open(getMonitor()); | ||
project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); | ||
|
||
folder = project.getFolder(linkedFolderName); | ||
assertFalse("Expected folder to not be linked after re-opening project", folder.isLinked()); | ||
} | ||
|
||
/** | ||
* Tests that link information is correct after closing a project and then | ||
* opening the project. | ||
*/ | ||
public void testCloseAndOpenProject() throws Exception { | ||
String linkedFolderName = "test"; | ||
IFolder folder = project.getFolder(linkedFolderName); | ||
folder.createLink(tmpPath, IResource.NONE, getMonitor()); | ||
project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); | ||
|
||
assertTrue("Failed to create linked folder in test project", folder.isLinked()); | ||
|
||
project.close(getMonitor()); | ||
|
||
project.open(getMonitor()); | ||
project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); | ||
|
||
folder = project.getFolder(linkedFolderName); | ||
assertTrue("Expected folder to be linked after re-opening project", folder.isLinked()); | ||
} | ||
} |