@Override public void update(final AnActionEvent event) { super.update(event); Project project = null; try { project = DataKeys.PROJECT.getData(event.getDataContext()); if (project == null) { // check if we're loading... return; } final CheckStylePlugin checkStylePlugin = project.getComponent(CheckStylePlugin.class); if (checkStylePlugin == null) { throw new IllegalStateException("Couldn't get checkstyle plugin"); } final Presentation presentation = event.getPresentation(); // disable if no files are modified final List<VirtualFile> modifiedFiles = ChangeListManager.getInstance(project).getAffectedFiles(); if (modifiedFiles.isEmpty()) { presentation.setEnabled(false); } else { presentation.setEnabled(!checkStylePlugin.isScanInProgress()); } } catch (Throwable e) { LOG.warn("Button update failed.", e); } } }
@Override public final void actionPerformed(final AnActionEvent event) { Project project; try { project = DataKeys.PROJECT.getData(event.getDataContext()); if (project == null) { return; } final ToolWindow toolWindow = ToolWindowManager.getInstance(project) .getToolWindow(CheckStyleToolWindowPanel.ID_TOOLWINDOW); final ChangeListManager changeListManager = ChangeListManager.getInstance(project); project.getComponent(CheckStylePlugin.class).asyncScanFiles(changeListManager.getAffectedFiles(), getSelectedOverride(toolWindow)); } catch (Throwable e) { LOG.warn("Modified files scan failed", e); } }
@Override protected boolean isEnabled(AnActionEvent e, Project project, SonarLintStatus status) { if (status.isRunning()) { return false; } ChangeListManager changeListManager = ChangeListManager.getInstance(project); return !changeListManager.getAffectedFiles().isEmpty(); }
@Test public void testRun() { AnActionEvent event = mock(AnActionEvent.class); VirtualFile file = mock(VirtualFile.class); when(event.getProject()).thenReturn(project); when(changeListManager.getAffectedFiles()).thenReturn(Collections.singletonList(file)); action.actionPerformed(event); verify(submitter).submitFiles(eq(Collections.singletonList(file)), eq(TriggerType.CHANGED_FILES), any(AnalysisCallback.class), eq(false)); } }
@Test public void testEnabled() { when(status.isRunning()).thenReturn(true); assertThat(action.isEnabled(event, project, status)).isFalse(); when(status.isRunning()).thenReturn(false); when(changeListManager.getAffectedFiles()).thenReturn(Collections.emptyList()); assertThat(action.isEnabled(event, project, status)).isFalse(); when(status.isRunning()).thenReturn(false); when(changeListManager.getAffectedFiles()).thenReturn(Collections.singletonList(mock(VirtualFile.class))); assertThat(action.isEnabled(event, project, status)).isTrue(); }
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); if (project == null || ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace())) { return; } SonarLintSubmitter submitter = SonarLintUtils.get(project, SonarLintSubmitter.class); ChangeListManager changeListManager = ChangeListManager.getInstance(project); List<VirtualFile> affectedFiles = changeListManager.getAffectedFiles(); AnalysisCallback callback = new ShowAnalysisResultsCallable(project, affectedFiles, "SCM changed files"); submitter.submitFiles(affectedFiles, TriggerType.CHANGED_FILES, callback, false); } }
private static boolean performFirstCommitIfRequired(@NotNull final Project project, @NotNull VirtualFile root, @NotNull GitRepository repository, @NotNull ProgressIndicator indicator, @NotNull String url, @NotNull String commitMessage) { // check if there is no commits if (!repository.isFresh()) { return true; } try { indicator.setText("Adding files to git..."); // ask for files to add final List<VirtualFile> trackedFiles = ChangeListManager.getInstance(project).getAffectedFiles(); final Collection<VirtualFile> untrackedFiles = filterOutIgnored(project, repository.getUntrackedFilesHolder().retrieveUntrackedFiles()); untrackedFiles.removeAll(trackedFiles); GitFileUtils.addFiles(project, root, untrackedFiles); indicator.setText("Performing commit..."); GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT); handler.setStdoutSuppressed(false); handler.addParameters("-m", commitMessage); handler.endOptions(); handler.run(); } catch (VcsException e) { showErrorDialog(project, "Project was create on GitLab server, but files cannot be commited to it.", "Initial Commit Failure"); return false; } return true; }
ChangeListManager.getInstance(project).getAffectedFiles(); final Collection<VirtualFile> untrackedFiles = filterOutIgnored(project, repository.getUntrackedFilesHolder().retrieveUntrackedFiles());