Search in sources :

Example 21 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitControllerBase method consumeEvents.

/**
 * An exception was intercepted. Make sure we notify any started() events that haven't been notified of failed().
 *
 * @param t Caught exception.
 */
private void consumeEvents(Throwable t) {
    if (!events.isEmpty()) {
        skipEventTracking = true;
        try {
            // Operations in progress, no failed issued for them.
            while (!events.isEmpty()) {
                GitEventInfo pop = events.pop();
                gitAccess.fireOperationFailed(pop, t);
            }
        } finally {
            skipEventTracking = false;
        }
    }
}
Also used : GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo)

Example 22 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitControllerTest method testFailPushNotification.

/**
 * For asynchronous tasks we always issue fail events when exceptions are thrown.
 *
 * @throws Exception If it fails.
 */
@Test
public void testFailPushNotification() throws Exception {
    GitAccess mock = Mockito.mock(GitAccess.class);
    // When Push will be invoked a runtime exception is thrown.
    GitController ctrl = new GitController(mock);
    StringBuilder b = new StringBuilder();
    ctrl.addGitListener(new GitEventListener() {

        @Override
        public void operationSuccessfullyEnded(GitEventInfo info) {
            b.append("E: " + info.toString()).append("\n");
        }

        @Override
        public void operationFailed(GitEventInfo info, Throwable t) {
            b.append("F: ").append(info.toString()).append("\n");
            b.append("   ").append(t.getClass()).append("\n");
        }

        @Override
        public void operationAboutToStart(GitEventInfo info) {
            b.append("S: ").append(info.toString()).append("\n");
        }
    });
    Future<?> push = ctrl.push();
    push.get();
    Assert.assertEquals("Not the expected events", "S: Status: null, message: Push_In_Progress GitEventInfo [Operation: PUSH].\n" + "F: Status: null, message: Push_failed: null GitEventInfo [Operation: PUSH].\n" + "   class java.lang.NullPointerException\n" + "", b.toString());
}
Also used : GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) GitController(com.oxygenxml.git.view.event.GitController) Test(org.junit.Test)

Example 23 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class StatusCacheTest method testGitEvent.

/**
 * <p><b>Description:</b> A git event resets the cache.</p>
 * <p><b>Bug ID:</b> EXM-49363</p>
 *
 * @author alex_jitianu
 *
 * @throws Exception If it fails.
 */
public void testGitEvent() throws Exception {
    OxygenGitPluginExtension extension = new OxygenGitPluginExtension();
    PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
    JFrame mockFrame = new JFrame();
    Mockito.when(pluginWorkspace.getParentFrame()).thenReturn(mockFrame);
    // These operations do not affect a status.
    List<GitOperation> exceptions = Arrays.asList(GitOperation.DELETE_BRANCH, GitOperation.PUSH);
    extension.applicationStarted((StandalonePluginWorkspace) pluginWorkspace);
    Arrays.stream(GitOperation.values()).forEach(op -> {
        GitStatus status = GitAccess.getInstance().getStatus();
        GitEventAdapter listener = new GitEventAdapter() {

            @Override
            public void operationSuccessfullyEnded(GitEventInfo info) {
                // When a normal listener receives a git event, if it requests the status it
                // should receive a newly computed status, not the stale one from cache.
                assertStatus(exceptions, op, status);
            }
        };
        GitListeners.getInstance().addGitListener(listener);
        GitListeners.getInstance().fireOperationSuccessfullyEnded(new GitEventInfo(op));
        GitListeners.getInstance().removeGitListener(listener);
        assertStatus(exceptions, op, status);
    });
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) GitOperation(com.oxygenxml.git.view.event.GitOperation) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) JFrame(javax.swing.JFrame) OxygenGitPluginExtension(com.oxygenxml.git.OxygenGitPluginExtension)

Aggregations

GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)23 WorkingCopyGitEventInfo (com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)19 BranchGitEventInfo (com.oxygenxml.git.view.event.BranchGitEventInfo)18 FileGitEventInfo (com.oxygenxml.git.view.event.FileGitEventInfo)18 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)11 IOException (java.io.IOException)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 StashApplyStatus (com.oxygenxml.git.view.stash.StashApplyStatus)3 ArrayList (java.util.ArrayList)3 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)3 Repository (org.eclipse.jgit.lib.Repository)3 GitController (com.oxygenxml.git.view.event.GitController)2 GitOperation (com.oxygenxml.git.view.event.GitOperation)2 StashApplyFailureWithStatusException (com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException)2 StashApplyFailureException (org.eclipse.jgit.api.errors.StashApplyFailureException)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)2 OxygenGitPluginExtension (com.oxygenxml.git.OxygenGitPluginExtension)1 SSHCapableUserCredentialsProvider (com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider)1 GitEventAdapter (com.oxygenxml.git.service.GitEventAdapter)1