Search in sources :

Example 1 with ScanScope

use of org.infernus.idea.checkstyle.model.ScanScope in project checkstyle-idea by jshiell.

the class CheckStyleConfigPanel method getPluginConfiguration.

public PluginConfiguration getPluginConfiguration() {
    final String checkstyleVersion = (String) csVersionDropdown.getSelectedItem();
    ScanScope scanScope = (ScanScope) scopeDropdown.getSelectedItem();
    if (scanScope == null) {
        scanScope = ScanScope.getDefaultValue();
    }
    // we don't know the scanBeforeCheckin flag at this point
    return PluginConfigurationBuilder.defaultConfiguration(project).withCheckstyleVersion(checkstyleVersion).withScanScope(scanScope).withSuppressErrors(suppressErrorsCheckbox.isSelected()).withCopyLibraries(copyLibsCheckbox.isSelected()).withLocations(new TreeSet<>(locationModel.getLocations())).withThirdPartyClassPath(getThirdPartyClasspath()).withActiveLocation(locationModel.getActiveLocation()).build();
}
Also used : ScanScope(org.infernus.idea.checkstyle.model.ScanScope)

Example 2 with ScanScope

use of org.infernus.idea.checkstyle.model.ScanScope 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 3 with ScanScope

use of org.infernus.idea.checkstyle.model.ScanScope 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)

Example 4 with ScanScope

use of org.infernus.idea.checkstyle.model.ScanScope in project checkstyle-idea by jshiell.

the class ScanModule method update.

@Override
public final void update(final AnActionEvent event) {
    super.update(event);
    try {
        final Presentation presentation = event.getPresentation();
        final Project project = DataKeys.PROJECT.getData(event.getDataContext());
        if (project == null) {
            // check if we're loading...
            presentation.setEnabled(false);
            return;
        }
        final VirtualFile[] selectedFiles = FileEditorManager.getInstance(project).getSelectedFiles();
        if (selectedFiles.length == 0) {
            return;
        }
        final Module module = ModuleUtil.findModuleForFile(selectedFiles[0], project);
        if (module == null) {
            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();
        VirtualFile[] moduleFiles = null;
        final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        if (scope == ScanScope.Everything) {
            moduleFiles = moduleRootManager.getContentRoots();
        } else {
            moduleFiles = moduleRootManager.getSourceRoots(scope.includeTestClasses());
        }
        // disable if no files are selected or scan in progress
        if (containsAtLeastOneFile(moduleFiles)) {
            presentation.setEnabled(!checkStylePlugin.isScanInProgress());
        } else {
            presentation.setEnabled(false);
        }
    } catch (Throwable e) {
        CheckStylePlugin.processErrorAndLog("Current Module button update", e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ScanScope(org.infernus.idea.checkstyle.model.ScanScope) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Presentation(com.intellij.openapi.actionSystem.Presentation) Module(com.intellij.openapi.module.Module) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin)

Example 5 with ScanScope

use of org.infernus.idea.checkstyle.model.ScanScope in project checkstyle-idea by jshiell.

the class ScanProject method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent event) {
    try {
        final Project project = DataKeys.PROJECT.getData(event.getDataContext());
        if (project == null) {
            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();
        final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(CheckStyleToolWindowPanel.ID_TOOLWINDOW);
        toolWindow.activate(() -> {
            try {
                setProgressText(toolWindow, "plugin.status.in-progress.project");
                Runnable scanAction = null;
                if (scope == ScanScope.Everything) {
                    scanAction = new ScanEverythingAction(project, getSelectedOverride(toolWindow));
                } else {
                    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
                    final VirtualFile[] sourceRoots = projectRootManager.getContentSourceRoots();
                    if (sourceRoots.length > 0) {
                        scanAction = new ScanSourceRootsAction(project, sourceRoots, getSelectedOverride(toolWindow));
                    }
                }
                if (scanAction != null) {
                    ApplicationManager.getApplication().runReadAction(scanAction);
                }
            } catch (Throwable e) {
                CheckStylePlugin.processErrorAndLog("Project scan", e);
            }
        });
    } catch (Throwable e) {
        CheckStylePlugin.processErrorAndLog("Project 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) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin)

Aggregations

ScanScope (org.infernus.idea.checkstyle.model.ScanScope)9 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 CheckStylePlugin (org.infernus.idea.checkstyle.CheckStylePlugin)6 Presentation (com.intellij.openapi.actionSystem.Presentation)3 ToolWindow (com.intellij.openapi.wm.ToolWindow)3 Module (com.intellij.openapi.module.Module)2 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 NotNull (org.jetbrains.annotations.NotNull)1