diff options
author | Andrey Loskutov | 2015-09-27 18:17:30 +0000 |
---|---|---|
committer | Andrey Loskutov | 2015-10-10 13:30:08 +0000 |
commit | ff08a72948c9ffec3c1f7858cec0330f2a4d6aac (patch) | |
tree | 32d6589480f79e73055aa960f74e80f2a21b5b51 /org.eclipse.egit.core.test | |
parent | e6189f813c3169b54ff2ba554110f0fc667c068d (diff) | |
download | egit-ff08a72948c9ffec3c1f7858cec0330f2a4d6aac.tar.gz egit-ff08a72948c9ffec3c1f7858cec0330f2a4d6aac.tar.xz egit-ff08a72948c9ffec3c1f7858cec0330f2a4d6aac.zip |
[nested projects] Allow EGit request inner most projects in some cases
Currently Eclipse resources API offers the choice of having very fast
but unpredictable results (getFileForLocation()) or very slow but
deterministic (findFilesForLocationURI()) while requesting a file via
IPath key in context of nested projects. The "unpredictability" of the
fast API is not documented and has side effects only if workspace
contains nested projects - in this case if the file is located in many
projects, it is not guaranteed, file handle from which project will be
returned (it is related to project names, see bug 476585).
During the fix for bug 440722, by choosing the very fast file lookup for
ResourceUtil we unintentionally changed the EGit behavior so that in
case nested projects were involved, EGit sometimes could not use the
file from the inner most project, but from parent one.
This fix offers an explicit option for clients which would prefer to see
resources from inner most projects independently how long it takes to
resolve them. Some of the affected ResourceUtil API clients are changed
to always request files inner most projects: mostly editor related code.
Bug: 476857
Change-Id: I5f076bbf6bb74392265d6ec1c9c80965111005ef
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r-- | org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ResourceUtilTest.java | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ResourceUtilTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ResourceUtilTest.java index e58648bdfc..810b1723b8 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ResourceUtilTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ResourceUtilTest.java @@ -31,6 +31,11 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +/** + * NB: most of the tests here will break after bug 476585 will be fixed in + * Eclipse 4.6, since the Resources API will always return inner most project + * per default. + */ public class ResourceUtilTest extends GitTestCase { private Repository repository; @@ -50,33 +55,38 @@ public class ResourceUtilTest extends GitTestCase { @Test public void getResourceForLocationShouldReturnFile() throws Exception { IFile file = project.createFile("file", new byte[] {}); - IResource resource = ResourceUtil.getResourceForLocation(file.getLocation()); + IResource resource = ResourceUtil.getResourceForLocation(file.getLocation(), false); assertThat(resource, instanceOf(IFile.class)); } @Test public void getResourceForLocationShouldReturnFolder() throws Exception { IFolder folder = project.createFolder("folder"); - IResource resource = ResourceUtil.getResourceForLocation(folder.getLocation()); + IResource resource = ResourceUtil.getResourceForLocation(folder.getLocation(), false); assertThat(resource, instanceOf(IFolder.class)); } @Test public void getResourceForLocationShouldReturnNullForInexistentFile() throws Exception { IPath location = project.getProject().getLocation().append("inexistent"); - IResource resource = ResourceUtil.getResourceForLocation(location); + IResource resource = ResourceUtil.getResourceForLocation(location, false); assertThat(resource, nullValue()); } @Test public void getFileForLocationShouldReturnExistingFileInCaseOfNestedProject() throws Exception { - TestProject nested = new TestProject(true, "Project-1/Project-0"); + TestProject nested = new TestProject(true, "Project-1/Project-2"); connect(nested.getProject()); IFile file = nested.createFile("a.txt", new byte[] {}); IPath location = file.getLocation(); - IFile result = ResourceUtil.getFileForLocation(location); + IFile result = ResourceUtil.getFileForLocation(location, false); + assertThat(result, notNullValue()); + assertTrue("Returned IFile should exist", result.exists()); + assertThat(result.getProject(), is(project.getProject())); + + result = ResourceUtil.getFileForLocation(location, true); assertThat(result, notNullValue()); assertTrue("Returned IFile should exist", result.exists()); assertThat(result.getProject(), is(nested.getProject())); @@ -85,15 +95,20 @@ public class ResourceUtilTest extends GitTestCase { @Test public void getFileForLocationShouldReturnExistingFileInCaseOfNestedNotClosedProject() throws Exception { - TestProject nested = new TestProject(true, "Project-1/Project-0"); + TestProject nested = new TestProject(true, "Project-1/Project-2"); connect(nested.getProject()); TestProject nested2 = new TestProject(true, - "Project-1/Project-0/Project"); + "Project-1/Project-2/Project-3"); connect(nested2.getProject()); IFile file = nested2.createFile("a.txt", new byte[] {}); IPath location = file.getLocation(); nested2.project.close(new NullProgressMonitor()); - IFile result = ResourceUtil.getFileForLocation(location); + IFile result = ResourceUtil.getFileForLocation(location, false); + assertThat(result, notNullValue()); + assertTrue("Returned IFile should exist", result.exists()); + assertThat(result.getProject(), is(project.getProject())); + + result = ResourceUtil.getFileForLocation(location, true); assertThat(result, notNullValue()); assertTrue("Returned IFile should exist", result.exists()); assertThat(result.getProject(), is(nested.getProject())); @@ -102,14 +117,31 @@ public class ResourceUtilTest extends GitTestCase { @Test public void getFileForLocationShouldNotUseFilesWithoutRepositoryMapping() throws Exception { - TestProject nested = new TestProject(true, "Project-1/Project-0"); + TestProject nested = new TestProject(true, "Project-1/Project-2"); IFile file = nested.createFile("a.txt", new byte[] {}); IPath location = file.getLocation(); - IFile result = ResourceUtil.getFileForLocation(location); + IFile result = ResourceUtil.getFileForLocation(location, false); + assertThat(result, notNullValue()); + assertTrue("Returned IFile should exist", result.exists()); + assertThat(result.getProject(), is(project.getProject())); + + result = ResourceUtil.getFileForLocation(location, true); assertThat(result, notNullValue()); assertTrue("Returned IFile should exist", result.exists()); assertThat(result.getProject(), is(project.getProject())); + + connect(nested.getProject()); + + result = ResourceUtil.getFileForLocation(location, false); + assertThat(result, notNullValue()); + assertTrue("Returned IFile should exist", result.exists()); + assertThat(result.getProject(), is(project.getProject())); + + result = ResourceUtil.getFileForLocation(location, true); + assertThat(result, notNullValue()); + assertTrue("Returned IFile should exist", result.exists()); + assertThat(result.getProject(), is(nested.getProject())); } private void connect(IProject p) throws CoreException { |