use of com.oxygenxml.git.service.GitOperationScheduler in project oxygen-git-client-addon by oxygenxml.
the class EditorPageMenuGitActionsProvider method getActionsForCurrentEditorPage.
/**
* Get the Git-specific action for the current editor page.
*
* @param editorURL Editor URL
*
* @return the Git-specific action for the current editor page.
*/
public List<AbstractAction> getActionsForCurrentEditorPage(URL editorURL) {
List<AbstractAction> actions = new ArrayList<>();
File file = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().locateFile(editorURL);
if (file == null) {
return Collections.emptyList();
}
boolean isFromGitRepo = FileUtil.isFromGitRepo(file);
if (isFromGitRepo) {
GitOperationScheduler gitOpScheduler = GitOperationScheduler.getInstance();
AbstractAction showHistoryAction = new AbstractAction(translator.getTranslation(Tags.SHOW_HISTORY)) {
@Override
public void actionPerformed(ActionEvent e) {
gitOpScheduler.schedule(() -> ProjectAndEditorPageMenuActionsUtil.showHistory(file, historyCtrl, getViewsToSetCursorOn()));
}
};
AbstractAction showBlameAction = new AbstractAction(translator.getTranslation(Tags.SHOW_BLAME)) {
@Override
public void actionPerformed(ActionEvent e) {
gitOpScheduler.schedule(() -> ProjectAndEditorPageMenuActionsUtil.showBlame(file, historyCtrl, getViewsToSetCursorOn()));
}
};
showBlameAction.setEnabled(true);
showHistoryAction.setEnabled(true);
actions.add(showHistoryAction);
actions.add(showBlameAction);
}
return actions;
}
use of com.oxygenxml.git.service.GitOperationScheduler in project oxygen-git-client-addon by oxygenxml.
the class ProjectMenuGitActionsProvider method createAllActions.
/**
* Create all actions.
*/
private void createAllActions() {
GitOperationScheduler gitOpScheduler = GitOperationScheduler.getInstance();
gitDiffAction = new AbstractAction(translator.getTranslation(Tags.GIT_DIFF)) {
@Override
public void actionPerformed(ActionEvent e) {
gitOpScheduler.schedule(ProjectMenuGitActionsProvider.this::doGitDiff);
}
};
commitAction = new AbstractAction(translator.getTranslation(Tags.COMMIT)) {
@Override
public void actionPerformed(ActionEvent e) {
gitOpScheduler.schedule(ProjectMenuGitActionsProvider.this::doPrepareCommit);
}
};
showHistoryAction = new AbstractAction(translator.getTranslation(Tags.SHOW_HISTORY)) {
@Override
public void actionPerformed(ActionEvent e) {
gitOpScheduler.schedule(() -> ProjectAndEditorPageMenuActionsUtil.showHistory(pluginWS.getProjectManager().getSelectedFiles()[0], historyCtrl, getViewsToSetCursorOn()));
}
};
showBlameAction = new AbstractAction(translator.getTranslation(Tags.SHOW_BLAME)) {
@Override
public void actionPerformed(ActionEvent e) {
gitOpScheduler.schedule(() -> ProjectAndEditorPageMenuActionsUtil.showBlame(pluginWS.getProjectManager().getSelectedFiles()[0], historyCtrl, getViewsToSetCursorOn()));
}
};
}
use of com.oxygenxml.git.service.GitOperationScheduler in project oxygen-git-client-addon by oxygenxml.
the class HistoryContextualActionsTest method testCheckoutFileAction.
/**
* <p>
* <b>Description:</b> Tests the
* com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter.createCheckoutFileAction(
* String, FileStatus, boolean) API.
* </p>
*
* <p>
* <b>Bug ID:</b> EXM-46986
* </p>
*
* @author Alex_Smarandache
*
* @throws Exception
*/
@Test
public void testCheckoutFileAction() throws Exception {
URL script = getClass().getClassLoader().getResource("scripts/history_script_actions.txt");
File wcTree = new File("target/gen/GitHistoryActionsTest_testHistoryContextualActions");
RepoGenerationScript.generateRepository(script, wcTree);
GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
Iterator<CommitCharacteristics> iterator = commitsCharacteristics.iterator();
CommitCharacteristics commitCharacteristic = iterator.next();
HistoryViewContextualMenuPresenter presenter = new HistoryViewContextualMenuPresenter(null);
List<FileStatus> changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
List<Action> actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, true);
actions.removeIf(e -> e == null || !e.getValue(Action.NAME).toString().contains("Reset_file"));
String[] checkoutFile = new String[2];
try (MockedStatic<GitAccess> git = Mockito.mockStatic(GitAccess.class)) {
GitAccess gitAcc = Mockito.mock(GitAccess.class);
Mockito.doAnswer((Answer<Void>) invocation -> {
checkoutFile[0] = invocation.getArgument(0);
checkoutFile[1] = invocation.getArgument(1);
return null;
}).when(gitAcc).checkoutCommitForFile(Mockito.any(String.class), Mockito.any(String.class));
git.when(GitAccess::getInstance).thenReturn(gitAcc);
try (MockedStatic<GitOperationScheduler> sch = Mockito.mockStatic(GitOperationScheduler.class)) {
GitOperationScheduler scheduler = Mockito.mock(GitOperationScheduler.class);
Mockito.when(scheduler.schedule(Mockito.any(Runnable.class))).thenAnswer((Answer<ScheduledFuture<?>>) invocation -> {
((Runnable) invocation.getArgument(0)).run();
return null;
});
sch.when(GitOperationScheduler::getInstance).thenReturn(scheduler);
actions.get(0).actionPerformed(null);
}
}
assertEquals(checkoutFile[0], changedFiles.get(0).getFileLocation());
assertEquals(checkoutFile[1], commitCharacteristic.getCommitId());
}
Aggregations