use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class ProjectUtilTest method testFindProjectFilesNested.
@Test
public void testFindProjectFilesNested() throws Exception {
project2 = new TestProject(true, "Project-1/Project-Nested");
File workingDir = gitDir.getParentFile();
Collection<File> nestedResult = new ArrayList<File>();
boolean nestedFound = ProjectUtil.findProjectFiles(nestedResult, workingDir, true, new NullProgressMonitor());
assertTrue("Expected to find projects", nestedFound);
assertEquals(2, nestedResult.size());
assertThat(nestedResult, hasItem(new File(workingDir, "Project-1/.project")));
assertThat(nestedResult, hasItem(new File(workingDir, "Project-1/Project-Nested/.project")));
Collection<File> noNestedResult = new ArrayList<File>();
boolean noNestedFound = ProjectUtil.findProjectFiles(noNestedResult, workingDir, false, new NullProgressMonitor());
assertTrue("Expected to find projects", noNestedFound);
assertEquals(1, noNestedResult.size());
assertThat(noNestedResult, hasItem(new File(workingDir, "Project-1/.project")));
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class ProjectUtilTest method testGetProjectsContains.
@Test
public void testGetProjectsContains() throws Exception {
TestProject prj2 = new TestProject(true, "Project-1-sub");
try {
repository.createFile(project.getProject(), "xxx");
repository.createFile(project.getProject(), "zzz");
repository.createFile(prj2.getProject(), "zzz");
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
prj2.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
IProject[] projectsContaining = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-1/xxx"));
IProject[] projectsEmpty = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("yyy"));
IProject[] projectSelf = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-1"));
Set<String> files = new TreeSet<String>();
files.add("Project-1/xxx");
files.add("Project-1/zzz");
IProject[] multiFile = ProjectUtil.getProjectsContaining(repository.getRepository(), files);
files.clear();
files.add("Project-1/xxx");
files.add("Project-1-sub/zzz");
IProject[] multiProject = ProjectUtil.getProjectsContaining(repository.getRepository(), files);
IProject[] nonExistProject = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-2"));
assertEquals(1, projectsContaining.length);
assertEquals(0, projectsEmpty.length);
assertEquals(1, projectSelf.length);
assertEquals(1, multiFile.length);
assertEquals(2, multiProject.length);
assertEquals(0, nonExistProject.length);
IProject p = projectsContaining[0];
assertEquals("Project-1", p.getDescription().getName());
} finally {
prj2.dispose();
}
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class ResourceUtilTest method getFileForLocationShouldReturnExistingFileInCaseOfNestedNotClosedProject.
@Ignore
@Test
public void getFileForLocationShouldReturnExistingFileInCaseOfNestedNotClosedProject() throws Exception {
TestProject nested = new TestProject(true, "Project-1/Project-2");
connect(nested.getProject());
TestProject nested2 = new TestProject(true, "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, 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()));
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class ResourceUtilTest method getFileForLocationShouldNotUseFilesWithoutRepositoryMapping.
@Ignore
@Test
public void getFileForLocationShouldNotUseFilesWithoutRepositoryMapping() throws Exception {
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, 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()));
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveButDoNotRenameProjectOutsideWorkspaceContainingGitRepo.
/**
* Move a project outside the workspace containing a Git repository, but do not rename it.
* <p>
* Note the similarity of the code with {@link #testMoveAndRenameProjectContainingGitRepo()}
*
* @throws Exception
*/
@Test
public void testMoveButDoNotRenameProjectOutsideWorkspaceContainingGitRepo() throws Exception {
ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").delete(true, null);
ResourcesPlugin.getWorkspace().getRoot().getProject("P2").delete(true, null);
TestProject project = initRepoInsideProjectOutsideWorkspace();
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
addToIndexOperation.execute(null);
IProjectDescription description = project.getProject().getDescription();
description.setLocationURI(URIUtil.toURI(new Path(new File(project.getWorkspaceSupplement(), "P2").getAbsolutePath())));
project.getProject().move(description, IResource.FORCE | IResource.SHALLOW, null);
IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject(// same name
"Project-1");
assertNotNull(RepositoryMapping.getMapping(project2.getProject()));
Repository movedRepo = RepositoryMapping.getMapping(project2).getRepository();
assertEquals("P2", movedRepo.getDirectory().getParentFile().getName());
DirCache dc = movedRepo.readDirCache();
assertEquals(1, dc.getEntryCount());
assertEquals("file.txt", dc.getEntry(0).getPathString());
assertFalse(ResourcesPlugin.getWorkspace().getRoot().getProject("P2").exists());
}
Aggregations