Search in sources :

Example 1 with ProjectConfigurationListener

use of org.sonarlint.intellij.messages.ProjectConfigurationListener in project sonarlint-intellij by SonarSource.

the class SonarLintProjectConfigurable method onSave.

/**
 * When we save the binding, we need to:
 * - Send a message for listeners interested in it
 * - If we are bound to a module, update it (even if we detected no changes)
 * - Clear all issues and submit an analysis on all open files
 */
private void onSave() {
    SonarLintProjectNotifications.get(project).reset();
    ProjectConfigurationListener projectListener = project.getMessageBus().syncPublisher(ProjectConfigurationListener.TOPIC);
    if (projectSettings.isBindingEnabled() && projectSettings.getProjectKey() != null && projectSettings.getServerId() != null) {
        ProjectBindingManager bindingManager = SonarLintUtils.get(project, ProjectBindingManager.class);
        try {
            SonarQubeServer server = bindingManager.getSonarQubeServer();
            ConnectedSonarLintEngine engine = bindingManager.getConnectedEngineSkipChecks();
            String moduleKey = projectSettings.getProjectKey();
            ServerUpdateTask task = new ServerUpdateTask(engine, server, Collections.singletonMap(moduleKey, Collections.singletonList(project)), true);
            ProgressManager.getInstance().run(task.asModal());
        } catch (InvalidBindingException e) {
        // nothing to do, SonarLintEngineManager should have already shown a warning
        }
    }
    projectListener.changed(projectSettings);
}
Also used : ServerUpdateTask(org.sonarlint.intellij.tasks.ServerUpdateTask) ProjectConfigurationListener(org.sonarlint.intellij.messages.ProjectConfigurationListener) InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) ProjectBindingManager(org.sonarlint.intellij.core.ProjectBindingManager) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)

Example 2 with ProjectConfigurationListener

use of org.sonarlint.intellij.messages.ProjectConfigurationListener in project sonarlint-intellij by SonarSource.

the class ExcludeFileAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (project == null || project.isDisposed() || files == null || files.length == 0) {
        return;
    }
    SonarLintProjectSettings settings = SonarLintUtils.get(project, SonarLintProjectSettings.class);
    List<String> exclusions = new ArrayList<>(settings.getFileExclusions());
    List<String> newExclusions = Arrays.stream(files).map(vf -> toExclusion(project, vf)).filter(exclusion -> !exclusion.item().isEmpty()).map(ExclusionItem::toStringWithType).filter(path -> !exclusions.contains(path)).collect(Collectors.toList());
    if (!newExclusions.isEmpty()) {
        exclusions.addAll(newExclusions);
        settings.setFileExclusions(exclusions);
        ProjectConfigurationListener projectListener = project.getMessageBus().syncPublisher(ProjectConfigurationListener.TOPIC);
        projectListener.changed(settings);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) ProjectConfigurationListener(org.sonarlint.intellij.messages.ProjectConfigurationListener) Arrays(java.util.Arrays) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExclusionItem(org.sonarlint.intellij.config.project.ExclusionItem) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Project(com.intellij.openapi.project.Project) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) ProjectConfigurationListener(org.sonarlint.intellij.messages.ProjectConfigurationListener) ArrayList(java.util.ArrayList) ExclusionItem(org.sonarlint.intellij.config.project.ExclusionItem)

Aggregations

ProjectConfigurationListener (org.sonarlint.intellij.messages.ProjectConfigurationListener)2 ActionPlaces (com.intellij.openapi.actionSystem.ActionPlaces)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 SonarQubeServer (org.sonarlint.intellij.config.global.SonarQubeServer)1 ExclusionItem (org.sonarlint.intellij.config.project.ExclusionItem)1 SonarLintProjectSettings (org.sonarlint.intellij.config.project.SonarLintProjectSettings)1 ProjectBindingManager (org.sonarlint.intellij.core.ProjectBindingManager)1 InvalidBindingException (org.sonarlint.intellij.exception.InvalidBindingException)1 ServerUpdateTask (org.sonarlint.intellij.tasks.ServerUpdateTask)1 SonarLintUtils (org.sonarlint.intellij.util.SonarLintUtils)1 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)1