@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); } } }
@Nullable @Override public LocalChangeList getIdeChangeFor(@NotNull P4ChangelistId changelistId) throws InterruptedException { String ideId = cache.getMappedIdeChangeListId(changelistId); if (ideId != null) { return ChangeListManager.getInstance(project).getChangeList(ideId); } return null; }
@Override public final void actionPerformed(final AnActionEvent event) { Project project = null; 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(filesFor(changeListManager .getDefaultChangeList()), getSelectedOverride(toolWindow)); } catch (Throwable e) { LOG.warn("Modified files scan failed", e); } }
ChangeListManager.getInstance(project).scheduleUpdate(true);
@NotNull private static Collection<VirtualFile> filterOutIgnored(@NotNull Project project, @NotNull Collection<VirtualFile> files) { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project); return ContainerUtil.filter(files, new Condition<VirtualFile>() { @Override public boolean value(VirtualFile file) { return !changeListManager.isIgnoredFile(file) && !vcsManager.isIgnored(file); } }); }
@NotNull private static Collection<VirtualFile> filterOutIgnored( @NotNull Project project, @NotNull Collection<VirtualFile> files) { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); final FileIndexFacade fileIndex = FileIndexFacade.getInstance(project); return Collections2.filter( files, file -> !changeListManager.isIgnoredFile(file) && !fileIndex.isExcludedFile(file)); }
protected void updateChangeListManager() { ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); changeListManager.ensureUpToDate(false); }
@Override protected void activate() { tempFileWatchDog.start(); if (myVFSListener == null) { myVFSListener = new P4VFSListener(getProject(), this); } // VcsCompat.getInstance().setupPlugin(myProject); ChangeListManager.getInstance(myProject).addChangeListListener(changelistListener); projectMessageBusConnection = myProject.getMessageBus().connect(); appMessageBusConnection = ApplicationManager.getApplication().getMessageBus().connect(); // If additional actions need to happen at plugin startup time, add them here to execute in // a background thread. }
@Override public void deactivate() { myConfigurable.disposeUIResources(); tempFileWatchDog.stop(); tempFileWatchDog.cleanUpTempDir(); if (myVFSListener != null) { Disposer.dispose(myVFSListener); myVFSListener = null; } if (projectMessageBusConnection != null) { projectMessageBusConnection.disconnect(); projectMessageBusConnection = null; } if (appMessageBusConnection != null) { appMessageBusConnection.disconnect(); appMessageBusConnection = null; } // This can cause an error if the project isn't setup. So put it at the end. if (!myProject.isDisposed()) { ChangeListManager.getInstance(myProject).removeChangeListListener(changelistListener); } super.deactivate(); }
private boolean stash() { if (!syncResult.hasLocalRepository()) { LOG.error("unexpected null local repro in call to stash"); return false; } final ChangeListManager changeListManager = ChangeListManager.getInstance(project); if (changeListManager.isFreezedWithNotification("Can not stash changes now")) { return false; } final GitLineHandler handler = new GitLineHandler(project, sourceRepository.getRoot(), GitCommand.STASH); handler.addParameters("save"); handler.addParameters("--keep-index"); String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()); stashMessage = "Cloud Debugger saved changes from branch " + originalBranchName + " at " + date; handler.addParameters(stashMessage); AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { GitHandlerUtil.doSynchronously( handler, GitBundle.getString("stashing.title"), handler.printableCommandLine()); } finally { token.finish(); } return true; }
public MockLocalChangeList addIdeChangelist(String name, String comment, boolean isDefault) { MockLocalChangeList ideChangeList = new MockLocalChangeList() .withName(name) .withComment(comment) .withIsDefault(isDefault); ChangeListManager cm = getMockChangelistManager(); if (isDefault) { when(cm.getDefaultChangeList()).thenReturn(ideChangeList); } when(cm.getChangeList(name)).thenReturn(ideChangeList); when(cm.findChangeList(name)).thenReturn(ideChangeList); List<LocalChangeList> currentChanges = cm.getChangeLists(); if (currentChanges == null) { currentChanges = new ArrayList<>(); } else { currentChanges = new ArrayList<>(currentChanges); } currentChanges.add(ideChangeList); when(cm.getChangeLists()).thenReturn(currentChanges); when(cm.getChangeListsCopy()).thenReturn(currentChanges); return ideChangeList; }
@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)); } }
vcs.getMockChangelistManager().getDefaultChangeList(), changeList);
@Nullable @Override public synchronized LocalChangeList findChangeList(String name) { if (name == null) { return null; } for (LocalChangeList change : changes) { if (name.equals(change.getName())) { return change; } } return clMgr.findChangeList(name); }
@Override public boolean value(VirtualFile file) { return !changeListManager.isIgnoredFile(file) && !vcsManager.isIgnored(file); } });
@Override public void rollbackIfUnchanged(VirtualFile file) { if (file == null || project.isDisposed()) { return; } ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (registry == null || registry.isDisposed()) { LOG.info("Skipping revert for " + file + ": plugin not in a valid state"); return; } FilePath fp = VcsUtil.getFilePath(file); if (fp == null) { LOG.info("Skipping revert for " + file + ": no FilePath found"); return; } ClientConfigRoot root = registry.getClientFor(file); if (root == null) { LOG.info("SKipping revert for " + file + ": no P4 root found"); return; } P4ServerComponent .perform(project, root.getClientConfig(), new RevertFileAction(fp, true)) .whenCompleted((r) -> ChangeListManager.getInstance(project).scheduleUpdate(true)); }
public ChangeListManager getMockChangelistManager() { return ChangeListManager.getInstance(idea.getMockProject()); }
@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 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 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(); final LocalChangeList changeList = ChangeListManager.getInstance(project).getDefaultChangeList(); if (changeList == null || changeList.getChanges() == null || changeList.getChanges().size() == 0) { presentation.setEnabled(false); } else { presentation.setEnabled(!checkStylePlugin.isScanInProgress()); } } catch (Throwable e) { LOG.warn("Button update failed.", e); } } }