Search in sources :

Example 1 with CheckStylePlugin

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());
}
Also used : Project(com.intellij.openapi.project.Project) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin)

Example 2 with CheckStylePlugin

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;
    }
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 3 with CheckStylePlugin

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ScanScope(org.infernus.idea.checkstyle.model.ScanScope) ToolWindow(com.intellij.openapi.wm.ToolWindow) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin)

Example 4 with CheckStylePlugin

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Presentation(com.intellij.openapi.actionSystem.Presentation) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin)

Example 5 with CheckStylePlugin

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ToolWindow(com.intellij.openapi.wm.ToolWindow) ScanScope(org.infernus.idea.checkstyle.model.ScanScope) Module(com.intellij.openapi.module.Module) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin)

Aggregations

CheckStylePlugin (org.infernus.idea.checkstyle.CheckStylePlugin)25 Project (com.intellij.openapi.project.Project)24 ToolWindow (com.intellij.openapi.wm.ToolWindow)16 Content (com.intellij.ui.content.Content)10 CheckStyleToolWindowPanel (org.infernus.idea.checkstyle.toolwindow.CheckStyleToolWindowPanel)10 Presentation (com.intellij.openapi.actionSystem.Presentation)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 ScanScope (org.infernus.idea.checkstyle.model.ScanScope)6 Module (com.intellij.openapi.module.Module)2 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 LocalChangeList (com.intellij.openapi.vcs.changes.LocalChangeList)1 PsiFile (com.intellij.psi.PsiFile)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 ConfigurationLocation (org.infernus.idea.checkstyle.model.ConfigurationLocation)1