Search in sources :

Example 1 with RemoteResourceMappingContext

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

the class GitModelSynchronize method fireSynchronizeAction.

private static void fireSynchronizeAction(final IWorkbenchWindow window, final GitSynchronizeDataSet gsdSet, final ResourceMapping[] mappings) {
    final GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsdSet);
    Job syncJob = new WorkspaceJob(UIText.GitModelSynchronize_fetchGitDataJobName) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            subscriber.init(monitor);
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.SYNCHRONIZE_READ_DATA.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    syncJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            RemoteResourceMappingContext remoteContext = new GitSubscriberResourceMappingContext(subscriber, gsdSet);
            SubscriberScopeManager manager = new SubscriberScopeManager(subscriber.getName(), mappings, subscriber, remoteContext, true);
            GitSubscriberMergeContext context = new GitSubscriberMergeContext(subscriber, manager, gsdSet);
            final GitModelSynchronizeParticipant participant = new GitModelSynchronizeParticipant(context);
            TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] { participant });
            IWorkbenchPart activePart = null;
            if (window != null)
                activePart = window.getActivePage().getActivePart();
            participant.run(activePart);
        }
    });
    syncJob.setUser(true);
    syncJob.schedule();
}
Also used : GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) SubscriberScopeManager(org.eclipse.team.core.subscribers.SubscriberScopeManager) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ISynchronizeParticipant(org.eclipse.team.ui.synchronize.ISynchronizeParticipant) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)

Example 2 with RemoteResourceMappingContext

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

the class GitSubscriberResourceMappingContextTest method hasLocalAndRemoteChangeInSubFolder.

@Test
public void hasLocalAndRemoteChangeInSubFolder() throws Exception {
    File file1 = testRepo.createFile(iProject, "folder/file1.sample");
    testRepo.appendContentAndCommit(iProject, file1, "initial content", "first commit in master");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    setContentsAndCommit(iFile1, "changed content in branch", "first commit in BRANCH");
    testRepo.checkoutBranch(MASTER);
    setContentsAndCommit(iFile1, "changed content in master", "second commit in MASTER");
    RemoteResourceMappingContext context = prepareContext(MASTER, BRANCH);
    assertTrue(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) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 3 with RemoteResourceMappingContext

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

the class GitSubscriberResourceMappingContextTest method hasRemoteChanges.

@Test
public void hasRemoteChanges() throws Exception {
    File file1 = testRepo.createFile(iProject, "file1.sample");
    File file2 = testRepo.createFile(iProject, "file2.sample");
    testRepo.appendContentAndCommit(iProject, file1, "initial content - file 1", "first file - initial commit MASTER");
    testRepo.appendContentAndCommit(iProject, file2, "initial content - file 2", "second file - initial commit MASTER");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    IFile iFile2 = testRepo.getIFile(iProject, file2);
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    setContentsAndCommit(iFile1, "change in branch - file 1", "branch commit - file1");
    setContentsAndCommit(iFile2, "change in branch - file 2", "branch commit - file2");
    testRepo.checkoutBranch(MASTER);
    RemoteResourceMappingContext context = prepareContext(MASTER, BRANCH);
    assertFalse(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasRemoteChange(iFile1, new NullProgressMonitor()));
    assertFalse(context.hasLocalChange(iFile2, new NullProgressMonitor()));
    assertTrue(context.hasRemoteChange(iFile2, new NullProgressMonitor()));
    setContents(iFile1, "change in master - file 1");
    refresh(context, iFile1);
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasRemoteChange(iFile1, new NullProgressMonitor()));
    setContents(iFile2, "change in branch - file 2");
    refresh(context, iFile2);
    assertTrue(context.hasLocalChange(iFile2, new NullProgressMonitor()));
    assertTrue(context.hasRemoteChange(iFile2, new NullProgressMonitor()));
    setContentsAndCommit(iFile1, "change in branch - file 1", "change in master (same as in branch) - file 2");
    refresh(context, iFile1);
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasRemoteChange(iFile1, 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 4 with RemoteResourceMappingContext

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

the class GitSubscriberResourceMappingContextTest method hasLocalChangeWhenRefreshingParentFolder.

@Test
public void hasLocalChangeWhenRefreshingParentFolder() throws Exception {
    IFolder folder = iProject.getFolder("newfolder");
    folder.create(false, true, null);
    IFile file = folder.getFile("a.txt");
    file.create(new ByteArrayInputStream("a".getBytes("UTF-8")), false, null);
    RemoteResourceMappingContext context = prepareContext(MASTER, MASTER);
    refresh(context, file);
    assertTrue(context.hasLocalChange(file, new NullProgressMonitor()));
    file.delete(false, null);
    // Refresh of folder, not file directly
    refresh(context, folder);
    assertFalse(context.hasLocalChange(file, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 5 with RemoteResourceMappingContext

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

the class GitSubscriberResourceMappingContextTest method hasLocalChangeWithFileRemoval.

@Test
public void hasLocalChangeWithFileRemoval() throws Exception {
    File file1 = testRepo.createFile(iProject, "a.txt");
    File file2 = testRepo.createFile(iProject, "b.txt");
    File file3 = testRepo.createFile(iProject, "c.txt");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    IFile iFile2 = testRepo.getIFile(iProject, file2);
    IFile iFile3 = testRepo.getIFile(iProject, file3);
    RemoteResourceMappingContext context = prepareContext(MASTER, MASTER);
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasLocalChange(iFile2, new NullProgressMonitor()));
    assertTrue(context.hasLocalChange(iFile3, new NullProgressMonitor()));
    iFile1.delete(false, null);
    refresh(context, iFile1, iFile2, iFile3);
    assertTrue(context.hasLocalChange(iFile2, new NullProgressMonitor()));
    assertTrue(context.hasLocalChange(iFile3, 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)

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