Search in sources :

Example 6 with SonarQubeServer

use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.

the class ServerIssueUpdater method fetchAndMatchServerIssues.

public void fetchAndMatchServerIssues(Collection<VirtualFile> virtualFiles, ProgressIndicator indicator, boolean waitForCompletion) {
    if (!projectSettings.isBindingEnabled()) {
        // not in connected mode
        return;
    }
    try {
        SonarQubeServer server = projectBindingManager.getSonarQubeServer();
        ConnectedSonarLintEngine engine = projectBindingManager.getConnectedEngine();
        String moduleKey = projectSettings.getProjectKey();
        boolean downloadAll = virtualFiles.size() >= FETCH_ALL_ISSUES_THRESHOLD;
        String msg;
        if (downloadAll) {
            msg = "Fetching all server issues";
        } else {
            msg = "Fetching server issues";
        }
        if (waitForCompletion) {
            msg += " (waiting for results)";
        }
        console.debug(msg);
        indicator.setText(msg);
        // submit tasks
        List<Future<Void>> updateTasks = fetchAndMatchServerIssues(virtualFiles, server, engine, moduleKey, downloadAll);
        if (waitForCompletion) {
            waitForTasks(updateTasks);
        }
    } catch (InvalidBindingException e) {
    // ignore, do nothing
    }
}
Also used : InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)

Example 7 with SonarQubeServer

use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.

the class SonarQubeEventNotifications method register.

private void register(SonarLintProjectSettings settings) {
    unregister();
    if (settings.isBindingEnabled()) {
        SonarQubeServer server;
        try {
            server = bindingManager.getSonarQubeServer();
        } catch (InvalidBindingException e) {
            // do nothing
            return;
        }
        if (server.enableNotifications()) {
            NotificationConfiguration config = createConfiguration(settings, server);
            SonarQubeNotifications.get().register(config);
        }
    }
}
Also used : InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)

Example 8 with SonarQubeServer

use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.

the class SonarLintProjectBindPanel method setServerList.

/**
 * Sets new servers in the combo box, or disable it if there aren't any.
 * Will also enable or disable other components.
 */
private void setServerList(Collection<SonarQubeServer> servers, @Nullable String previousSelectedStorageId) {
    DefaultComboBoxModel<SonarQubeServer> model = (DefaultComboBoxModel<SonarQubeServer>) serverComboBox.getModel();
    if (servers.isEmpty()) {
        serverComboBox.setEnabled(false);
        SonarQubeServer s = SonarQubeServer.newBuilder().setName(SERVER_EMPTY_TEXT).build();
        serverComboBox.setPrototypeDisplayValue(s);
    // ensure this is called, even when nothing is selected
    } else {
        serverComboBox.setEnabled(bindEnable.isSelected());
        int i = 0;
        int selectedIndex = -1;
        for (SonarQubeServer s : servers) {
            if (previousSelectedStorageId != null && s.getName() != null && previousSelectedStorageId.equals(s.getName())) {
                selectedIndex = i;
            }
            serverComboBox.setPrototypeDisplayValue(null);
            // this won't call the change listener
            model.insertElementAt(s, i);
            i++;
        }
        // can be -1 (nothing selected)
        serverComboBox.setSelectedIndex(selectedIndex);
    }
    // ensure this is called, even when nothing is selected
    onServerSelected();
}
Also used : SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 9 with SonarQubeServer

use of org.sonarlint.intellij.config.global.SonarQubeServer in project sonarlint-intellij by SonarSource.

the class SonarLintProjectBindPanel method downloadProjectList.

/**
 * Assumes that it's bound and a server is selected
 */
@CheckForNull
private Map<String, RemoteModule> downloadProjectList() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    SonarQubeServer selectedServer = getSelectedServer();
    String storageId = getSelectedStorageId();
    if (selectedServer == null || storageId == null) {
        return null;
    }
    SonarLintEngineManager core = SonarLintUtils.get(SonarLintEngineManager.class);
    ConnectedSonarLintEngine engine = core.getConnectedEngine(storageId);
    ServerDownloadProjectTask downloadTask = new ServerDownloadProjectTask(project, engine, selectedServer);
    try {
        ProgressManager.getInstance().run(downloadTask);
        return downloadTask.getResult();
    } catch (Exception e) {
        String msg = e.getMessage() != null ? e.getMessage() : "Failed to download list of projects";
        Messages.showErrorDialog(rootPanel, msg, "Error Downloading Project List");
        return null;
    }
}
Also used : SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) ServerDownloadProjectTask(org.sonarlint.intellij.tasks.ServerDownloadProjectTask) SonarLintEngineManager(org.sonarlint.intellij.core.SonarLintEngineManager) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) CheckForNull(javax.annotation.CheckForNull)

Example 10 with SonarQubeServer

use of org.sonarlint.intellij.config.global.SonarQubeServer 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)

Aggregations

SonarQubeServer (org.sonarlint.intellij.config.global.SonarQubeServer)21 Test (org.junit.Test)12 SonarTest (org.sonarlint.intellij.SonarTest)6 InvalidBindingException (org.sonarlint.intellij.exception.InvalidBindingException)6 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)6 SonarApplication (org.sonarlint.intellij.SonarApplication)4 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 SonarLintProjectSettings (org.sonarlint.intellij.config.project.SonarLintProjectSettings)3 SonarLintConsole (org.sonarlint.intellij.ui.SonarLintConsole)3 CommitStepException (com.intellij.ide.wizard.CommitStepException)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 Before (org.junit.Before)2