Search in sources :

Example 11 with SonarQubeServer

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

the class SonarLintProjectConfigurable method reset.

@Override
public void reset() {
    if (panel == null) {
        return;
    }
    List<SonarQubeServer> currentServers = null;
    // try get the global settings that are currently being configured in the configurable, if it is open
    DataContext ctx = DataManager.getInstance().getDataContextFromFocus().getResult();
    if (ctx != null) {
        Settings allSettings = Settings.KEY.getData(ctx);
        if (allSettings != null) {
            final SonarLintGlobalConfigurable globalConfigurable = allSettings.find(SonarLintGlobalConfigurable.class);
            if (globalConfigurable != null) {
                currentServers = globalConfigurable.getCurrentSettings();
            }
        }
    }
    // get saved settings if needed
    if (currentServers == null) {
        currentServers = SonarLintUtils.get(SonarLintGlobalSettings.class).getSonarQubeServers();
    }
    panel.load(currentServers, projectSettings);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) SonarLintGlobalConfigurable(org.sonarlint.intellij.config.global.SonarLintGlobalConfigurable) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) Settings(com.intellij.openapi.options.ex.Settings) SonarLintGlobalSettings(org.sonarlint.intellij.config.global.SonarLintGlobalSettings)

Example 12 with SonarQubeServer

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

the class AuthStep method fetchInformation.

private void fetchInformation() throws CommitStepException {
    SonarQubeServer tmpServer = model.createServerWithoutOrganization();
    InformationFetchTask task = new InformationFetchTask(tmpServer);
    ProgressManager.getInstance().run(task);
    if (task.getException() == null) {
        model.setOrganizationList(task.organizations());
        if (task.organizations().size() == 1) {
            model.setOrganization(task.organizations().iterator().next().getKey());
        } else if (task.organizations().isEmpty()) {
            model.setOrganization(null);
        }
        model.setNotificationsSupported(task.notificationsSupported());
        return;
    }
    String msg = "Failed to fetch information from the server. Please check the configuration and try again.";
    if (task.getException().getMessage() != null) {
        msg = msg + " Error: " + task.getException().getMessage();
    }
    throw new CommitStepException(msg);
}
Also used : InformationFetchTask(org.sonarlint.intellij.tasks.InformationFetchTask) CommitStepException(com.intellij.ide.wizard.CommitStepException) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer)

Example 13 with SonarQubeServer

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

the class AuthStep method checkConnection.

private void checkConnection() throws CommitStepException {
    SonarQubeServer tmpServer = model.createServerWithoutOrganization();
    ConnectionTestTask test = new ConnectionTestTask(tmpServer);
    ProgressManager.getInstance().run(test);
    ValidationResult r = test.result();
    String msg = "Failed to connect to the server. Please check the configuration.";
    if (test.getException() != null) {
        if (test.getException().getMessage() != null) {
            msg = msg + " Error: " + test.getException().getMessage();
        }
        throw new CommitStepException(msg);
    } else if (!r.success()) {
        throw new CommitStepException(msg + " Cause: " + r.message());
    }
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) ConnectionTestTask(org.sonarlint.intellij.tasks.ConnectionTestTask) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)

Example 14 with SonarQubeServer

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

the class ProjectBindingManager method getSonarQubeServer.

public synchronized SonarQubeServer getSonarQubeServer() throws InvalidBindingException {
    String serverId = projectSettings.getServerId();
    List<SonarQubeServer> servers = globalSettings.getSonarQubeServers();
    Optional<SonarQubeServer> server = servers.stream().filter(s -> s.getName().equals(serverId)).findAny();
    return server.orElseThrow(() -> new InvalidBindingException("SonarQube server configuration does not exist for server id: " + serverId));
}
Also used : SonarLintConsole(org.sonarlint.intellij.ui.SonarLintConsole) List(java.util.List) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) SonarLintGlobalSettings(org.sonarlint.intellij.config.global.SonarLintGlobalSettings) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) Project(com.intellij.openapi.project.Project) Optional(java.util.Optional) Nullable(javax.annotation.Nullable) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) AbstractProjectComponent(com.intellij.openapi.components.AbstractProjectComponent) InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer)

Example 15 with SonarQubeServer

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

the class WizardModelTest method testExportSonarCloud.

@Test
public void testExportSonarCloud() {
    WizardModel model = new WizardModel();
    model.setName("name");
    model.setOrganization("org");
    model.setToken("token");
    model.setPassword(new char[] { 'p', 'a', 's', 's' });
    model.setServerType(WizardModel.ServerType.SONARCLOUD);
    SonarQubeServer server = model.createServer();
    assertThat(server.getHostUrl()).isEqualTo("https://sonarcloud.io");
    assertThat(server.getLogin()).isNull();
    assertThat(server.getPassword()).isNull();
    assertThat(server.getToken()).isEqualTo("token");
    assertThat(server.getOrganizationKey()).isEqualTo("org");
}
Also used : SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) Test(org.junit.Test)

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