Search in sources :

Example 1 with ServerUpdateTask

use of org.sonarlint.intellij.tasks.ServerUpdateTask 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 ServerUpdateTask

use of org.sonarlint.intellij.tasks.ServerUpdateTask in project sonarlint-intellij by SonarSource.

the class SonarQubeServerMgmtPanel method updateServerBinding.

public static void updateServerBinding(SonarQubeServer server, ConnectedSonarLintEngine engine, boolean onlyProjects) {
    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    Map<String, List<Project>> projectsPerModule = new HashMap<>();
    for (Project p : openProjects) {
        SonarLintProjectSettings projectSettings = SonarLintUtils.get(p, SonarLintProjectSettings.class);
        String moduleKey = projectSettings.getProjectKey();
        if (projectSettings.isBindingEnabled() && server.getName().equals(projectSettings.getServerId()) && moduleKey != null) {
            List<Project> projects = projectsPerModule.computeIfAbsent(moduleKey, k -> new ArrayList<>());
            projects.add(p);
        }
    }
    ServerUpdateTask task = new ServerUpdateTask(engine, server, projectsPerModule, onlyProjects);
    ProgressManager.getInstance().run(task.asBackground());
}
Also used : Project(com.intellij.openapi.project.Project) ServerUpdateTask(org.sonarlint.intellij.tasks.ServerUpdateTask) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) JBList(com.intellij.ui.components.JBList) JList(javax.swing.JList)

Aggregations

ServerUpdateTask (org.sonarlint.intellij.tasks.ServerUpdateTask)2 Project (com.intellij.openapi.project.Project)1 JBList (com.intellij.ui.components.JBList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JList (javax.swing.JList)1 SonarQubeServer (org.sonarlint.intellij.config.global.SonarQubeServer)1 SonarLintProjectSettings (org.sonarlint.intellij.config.project.SonarLintProjectSettings)1 ProjectBindingManager (org.sonarlint.intellij.core.ProjectBindingManager)1 InvalidBindingException (org.sonarlint.intellij.exception.InvalidBindingException)1 ProjectConfigurationListener (org.sonarlint.intellij.messages.ProjectConfigurationListener)1 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)1