Search in sources :

Example 16 with TestProject

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")));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TestProject(org.eclipse.egit.core.test.TestProject) ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 17 with TestProject

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();
    }
}
Also used : TestProject(org.eclipse.egit.core.test.TestProject) TreeSet(java.util.TreeSet) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 18 with TestProject

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()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TestProject(org.eclipse.egit.core.test.TestProject) IPath(org.eclipse.core.runtime.IPath) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with TestProject

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()));
}
Also used : IFile(org.eclipse.core.resources.IFile) TestProject(org.eclipse.egit.core.test.TestProject) IPath(org.eclipse.core.runtime.IPath) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with TestProject

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());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) DirCache(org.eclipse.jgit.dircache.DirCache) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestProject(org.eclipse.egit.core.test.TestProject) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Aggregations

TestProject (org.eclipse.egit.core.test.TestProject)27 IFile (org.eclipse.core.resources.IFile)17 Test (org.junit.Test)17 TestRepository (org.eclipse.egit.core.test.TestRepository)11 DirCache (org.eclipse.jgit.dircache.DirCache)11 File (java.io.File)9 AddToIndexOperation (org.eclipse.egit.core.op.AddToIndexOperation)9 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Repository (org.eclipse.jgit.lib.Repository)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Theory (org.junit.experimental.theories.Theory)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)4 Path (org.eclipse.core.runtime.Path)4 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 Ignore (org.junit.Ignore)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 IResource (org.eclipse.core.resources.IResource)2