use of org.infernus.idea.checkstyle.CheckStylePlugin in project checkstyle-idea by jshiell.
the class ScanFilesBeforeCheckinHandler method settings.
private Optional<PluginConfigurationManager> settings() {
final Project project = checkinPanel.getProject();
if (project == null) {
LOG.warn("Could not get project for check-in panel");
return empty();
}
final CheckStylePlugin plugin = project.getComponent(CheckStylePlugin.class);
if (plugin == null) {
LOG.warn("Could not get CheckStyle Plug-in, skipping");
return empty();
}
return ofNullable(plugin.configurationManager());
}
use of org.infernus.idea.checkstyle.CheckStylePlugin in project checkstyle-idea by jshiell.
the class ScanFilesBeforeCheckinHandler method beforeCheckin.
@Override
public ReturnResult beforeCheckin(@Nullable final CommitExecutor executor, final PairConsumer<Object, Object> additionalDataConsumer) {
final Project project = checkinPanel.getProject();
if (project == null) {
LOG.warn("Could not get project for check-in panel, skipping");
return COMMIT;
}
final CheckStylePlugin plugin = project.getComponent(CheckStylePlugin.class);
if (plugin == null) {
LOG.warn("Could not get CheckStyle Plug-in, skipping");
return COMMIT;
}
if (plugin.configurationManager().getCurrent().isScanBeforeCheckin()) {
try {
final Map<PsiFile, List<Problem>> scanResults = new HashMap<>();
new Task.Modal(project, message("handler.before.checkin.scan.text"), false) {
public void run(@NotNull final ProgressIndicator progressIndicator) {
progressIndicator.setText(message("handler.before.checkin.scan.in-progress"));
progressIndicator.setIndeterminate(true);
scanResults.putAll(plugin.scanFiles(new ArrayList<>(checkinPanel.getVirtualFiles())));
}
}.queue();
return processScanResults(scanResults, executor, plugin);
} catch (ProcessCanceledException e) {
return CANCEL;
}
} else {
return COMMIT;
}
}
use of org.infernus.idea.checkstyle.CheckStylePlugin in project checkstyle-idea by jshiell.
the class ScanCurrentFile method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent event) {
final Project project = DataKeys.PROJECT.getData(event.getDataContext());
if (project == null) {
return;
}
try {
final CheckStylePlugin checkStylePlugin = project.getComponent(CheckStylePlugin.class);
if (checkStylePlugin == null) {
throw new IllegalStateException("Couldn't get checkstyle plugin");
}
final ScanScope scope = checkStylePlugin.configurationManager().getCurrent().getScanScope();
final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(CheckStyleToolWindowPanel.ID_TOOLWINDOW);
toolWindow.activate(() -> {
try {
setProgressText(toolWindow, "plugin.status.in-progress.current");
final VirtualFile selectedFile = getSelectedFile(project, scope);
if (selectedFile != null) {
project.getComponent(CheckStylePlugin.class).asyncScanFiles(Arrays.asList(selectedFile), getSelectedOverride(toolWindow));
}
} catch (Throwable e) {
CheckStylePlugin.processErrorAndLog("Current File scan", e);
}
});
} catch (Throwable e) {
CheckStylePlugin.processErrorAndLog("Current File scan", e);
}
}
use of org.infernus.idea.checkstyle.CheckStylePlugin in project checkstyle-idea by jshiell.
the class ScanModifiedFiles method update.
@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);
}
}
use of org.infernus.idea.checkstyle.CheckStylePlugin in project checkstyle-idea by jshiell.
the class ScanModule method actionPerformed.
@Override
public final void actionPerformed(final AnActionEvent event) {
try {
final Project project = DataKeys.PROJECT.getData(event.getDataContext());
if (project == null) {
return;
}
final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(CheckStyleToolWindowPanel.ID_TOOLWINDOW);
final VirtualFile[] selectedFiles = FileEditorManager.getInstance(project).getSelectedFiles();
if (selectedFiles.length == 0) {
setProgressText(toolWindow, "plugin.status.in-progress.no-file");
return;
}
final Module module = ModuleUtil.findModuleForFile(selectedFiles[0], project);
if (module == null) {
setProgressText(toolWindow, "plugin.status.in-progress.no-module");
return;
}
final CheckStylePlugin checkStylePlugin = project.getComponent(CheckStylePlugin.class);
if (checkStylePlugin == null) {
throw new IllegalStateException("Couldn't get checkstyle plugin");
}
final ScanScope scope = checkStylePlugin.configurationManager().getCurrent().getScanScope();
toolWindow.activate(() -> {
try {
setProgressText(toolWindow, "plugin.status.in-progress.module");
Runnable scanAction = null;
if (scope == ScanScope.Everything) {
scanAction = new ScanEverythingAction(module, getSelectedOverride(toolWindow));
} else {
final VirtualFile[] moduleSourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(scope.includeTestClasses());
if (moduleSourceRoots.length > 0) {
scanAction = new ScanSourceRootsAction(project, moduleSourceRoots, getSelectedOverride(toolWindow));
}
}
if (scanAction != null) {
ApplicationManager.getApplication().runReadAction(scanAction);
}
} catch (Throwable e) {
CheckStylePlugin.processErrorAndLog("Current Module scan", e);
}
});
} catch (Throwable e) {
CheckStylePlugin.processErrorAndLog("Current Module scan", e);
}
}
Aggregations