Search in sources :

Example 11 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class GitSubscriberResourceMappingContextTest method hasRemoteChangeInNewFolder.

@Test
public void hasRemoteChangeInNewFolder() throws Exception {
    File file1 = testRepo.createFile(iProject, "file1.sample");
    String initialContent1 = "some content for the first file";
    testRepo.appendContentAndCommit(iProject, file1, initialContent1, "first file - initial commit");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    iProject.getFolder("folder").create(true, true, new NullProgressMonitor());
    File file2 = testRepo.createFile(iProject, "folder/file2.sample");
    String initialContent2 = "some content for the second file";
    testRepo.appendContentAndCommit(iProject, file2, initialContent2, "second file - initial commit");
    IFile iFile2 = testRepo.getIFile(iProject, file2);
    testRepo.checkoutBranch(MASTER);
    RemoteResourceMappingContext context = prepareContext(MASTER, BRANCH);
    assertFalse(context.hasRemoteChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasRemoteChange(iFile2, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 12 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class GitSubscriberResourceMappingContextTest method hasDeletion.

@Test
public void hasDeletion() throws Exception {
    File file1 = testRepo.createFile(iProject, "file1.sample");
    testRepo.appendContentAndCommit(iProject, file1, "initial content", "first commit in master");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    iFile1.delete(true, new NullProgressMonitor());
    try (Git git = new Git(testRepo.getRepository())) {
        git.add().addFilepattern(iProject.getName() + '/' + iFile1.getName()).setUpdate(true).call();
    }
    testRepo.commit("Deleted file1.sample");
    RemoteResourceMappingContext context = prepareContext(BRANCH, MASTER);
    boolean hasFile1 = false;
    for (IResource member : context.fetchMembers(iProject, new NullProgressMonitor())) {
        if (iFile1.getName().equals(member.getName())) {
            hasFile1 = true;
            break;
        }
    }
    assertTrue(hasFile1);
    assertFalse(context.hasRemoteChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) Git(org.eclipse.jgit.api.Git) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Example 13 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class MockLogicalResourceMapping method getTraversals.

@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    SubMonitor sm = SubMonitor.convert(monitor, 3);
    Set<IFile> result = new LinkedHashSet<IFile>();
    result.add(file);
    try {
        List<IFile> dependencies = getDependencies(file, file.getParent());
        result.addAll(dependencies);
        sm.worked(1);
        if (context instanceof RemoteResourceMappingContext) {
            RemoteResourceMappingContext rmc = (RemoteResourceMappingContext) context;
            IStorage baseContents = rmc.fetchBaseContents(file, sm.newChild(1));
            if (baseContents != null) {
                result.addAll(getDependencies(baseContents, file.getParent()));
            }
            IStorage remoteContents = rmc.fetchRemoteContents(file, sm.newChild(1));
            if (remoteContents != null) {
                result.addAll(getDependencies(remoteContents, file.getParent()));
            }
        }
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.egit.ui.test", "Exception while computing logical model", e));
    }
    final IResource[] resourceArray = result.toArray(new IResource[result.size()]);
    return new ResourceTraversal[] { new ResourceTraversal(resourceArray, IResource.DEPTH_ONE, IResource.NONE) };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) IFile(org.eclipse.core.resources.IFile) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) IStorage(org.eclipse.core.resources.IStorage) CoreException(org.eclipse.core.runtime.CoreException) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IResource(org.eclipse.core.resources.IResource)

Aggregations

RemoteResourceMappingContext (org.eclipse.core.resources.mapping.RemoteResourceMappingContext)13 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 Test (org.junit.Test)11 File (java.io.File)10 IResource (org.eclipse.core.resources.IResource)3 IFolder (org.eclipse.core.resources.IFolder)2 Git (org.eclipse.jgit.api.Git)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 IContainer (org.eclipse.core.resources.IContainer)1 IStorage (org.eclipse.core.resources.IStorage)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 ResourceTraversal (org.eclipse.core.resources.mapping.ResourceTraversal)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1