diff --git a/backend/core/src/main/java/org/sonarsource/sonarlint/core/embedded/server/RequestHandlerBindingAssistant.java b/backend/core/src/main/java/org/sonarsource/sonarlint/core/embedded/server/RequestHandlerBindingAssistant.java index 5d230eb4ec..e6c4bd9ab0 100644 --- a/backend/core/src/main/java/org/sonarsource/sonarlint/core/embedded/server/RequestHandlerBindingAssistant.java +++ b/backend/core/src/main/java/org/sonarsource/sonarlint/core/embedded/server/RequestHandlerBindingAssistant.java @@ -31,6 +31,7 @@ import javax.inject.Singleton; import org.sonarsource.sonarlint.core.BindingCandidatesFinder; import org.sonarsource.sonarlint.core.BindingSuggestionProvider; +import org.sonarsource.sonarlint.core.SonarCloudActiveEnvironment; import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger; import org.sonarsource.sonarlint.core.commons.progress.ExecutorServiceShutdownWatchable; import org.sonarsource.sonarlint.core.commons.progress.SonarLintCancelMonitor; @@ -56,9 +57,11 @@ public class RequestHandlerBindingAssistant { private final ConfigurationRepository configurationRepository; private final UserTokenService userTokenService; private final ExecutorServiceShutdownWatchable executorService; + private final String sonarCloudUrl; - public RequestHandlerBindingAssistant(BindingSuggestionProvider bindingSuggestionProvider, BindingCandidatesFinder bindingCandidatesFinder, SonarLintRpcClient client, - ConnectionConfigurationRepository connectionConfigurationRepository, ConfigurationRepository configurationRepository, UserTokenService userTokenService) { + public RequestHandlerBindingAssistant(BindingSuggestionProvider bindingSuggestionProvider, BindingCandidatesFinder bindingCandidatesFinder, + SonarLintRpcClient client, ConnectionConfigurationRepository connectionConfigurationRepository, ConfigurationRepository configurationRepository, + UserTokenService userTokenService, SonarCloudActiveEnvironment sonarCloudActiveEnvironment) { this.bindingSuggestionProvider = bindingSuggestionProvider; this.bindingCandidatesFinder = bindingCandidatesFinder; this.client = client; @@ -67,6 +70,7 @@ public RequestHandlerBindingAssistant(BindingSuggestionProvider bindingSuggestio this.userTokenService = userTokenService; this.executorService = new ExecutorServiceShutdownWatchable<>(new ThreadPoolExecutor(0, 1, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), r -> new Thread(r, "Show Issue or Hotspot Request Handler"))); + this.sonarCloudUrl = sonarCloudActiveEnvironment.getUri().toString(); } interface Callback { @@ -81,7 +85,7 @@ void assistConnectionAndBindingIfNeededAsync(AssistCreatingConnectionParams conn private void assistConnectionAndBindingIfNeeded(AssistCreatingConnectionParams connectionParams, String projectKey, Callback callback, SonarLintCancelMonitor cancelMonitor) { - String serverUrl = connectionParams.getServerUrl(); + String serverUrl = getServerUrl(connectionParams); LOG.debug("Assist connection and binding if needed for project {} and server {}", projectKey, serverUrl); try { var connectionsMatchingOrigin = connectionConfigurationRepository.findByUrl(serverUrl); @@ -105,6 +109,10 @@ private void assistConnectionAndBindingIfNeeded(AssistCreatingConnectionParams c } } + private String getServerUrl(AssistCreatingConnectionParams connectionParams) { + return connectionParams.getConnection().isLeft() ? connectionParams.getConnection().getLeft().getServerUrl() : sonarCloudUrl; + } + private AssistCreatingConnectionResponse assistCreatingConnectionAndWaitForRepositoryUpdate( AssistCreatingConnectionParams connectionParams, SonarLintCancelMonitor cancelMonitor) { var assistNewConnectionResult = assistCreatingConnection(connectionParams, cancelMonitor); @@ -194,7 +202,7 @@ private void revokeToken(AssistCreatingConnectionParams connectionParams, SonarL String tokenName = connectionParams.getTokenName(); String tokenValue = connectionParams.getTokenValue(); if (tokenName != null && tokenValue != null) { - var revokeTokenParams = new RevokeTokenParams(connectionParams.getServerUrl(), tokenName, tokenValue); + var revokeTokenParams = new RevokeTokenParams(getServerUrl(connectionParams), tokenName, tokenValue); userTokenService.revokeToken(revokeTokenParams, cancelMonitor); } } diff --git a/backend/core/src/test/java/org/sonarsource/sonarlint/core/embedded/server/ShowIssueRequestHandlerTests.java b/backend/core/src/test/java/org/sonarsource/sonarlint/core/embedded/server/ShowIssueRequestHandlerTests.java index f50cfc58d3..537d840bd6 100644 --- a/backend/core/src/test/java/org/sonarsource/sonarlint/core/embedded/server/ShowIssueRequestHandlerTests.java +++ b/backend/core/src/test/java/org/sonarsource/sonarlint/core/embedded/server/ShowIssueRequestHandlerTests.java @@ -272,6 +272,6 @@ private static ShowIssueRequestHandler getShowIssueRequestHandler(TelemetryServi var userTokenService = mock(UserTokenService.class); SonarCloudActiveEnvironment sonarCloudActiveEnvironment = SonarCloudActiveEnvironment.prod(); return new ShowIssueRequestHandler(sonarLintClient, serverApiProvider, telemetryService, - new RequestHandlerBindingAssistant(bindingSuggestionProvider, bindingCandidatesFinder, sonarLintClient, repository, configurationRepository, userTokenService), pathTranslationService, sonarCloudActiveEnvironment); + new RequestHandlerBindingAssistant(bindingSuggestionProvider, bindingCandidatesFinder, sonarLintClient, repository, configurationRepository, userTokenService, sonarCloudActiveEnvironment), pathTranslationService, sonarCloudActiveEnvironment); } } diff --git a/medium-tests/src/test/java/mediumtest/issues/OpenIssueInIdeMediumTests.java b/medium-tests/src/test/java/mediumtest/issues/OpenIssueInIdeMediumTests.java index a56e02d9c5..bb3a14bcc7 100644 --- a/medium-tests/src/test/java/mediumtest/issues/OpenIssueInIdeMediumTests.java +++ b/medium-tests/src/test/java/mediumtest/issues/OpenIssueInIdeMediumTests.java @@ -317,7 +317,7 @@ void it_should_assist_creating_the_connection_when_server_url_unknown() throws E ArgumentCaptor captor = ArgumentCaptor.captor(); verify(fakeClient, timeout(1000)).assistCreatingConnection(captor.capture(), any()); assertThat(captor.getAllValues()) - .extracting(AssistCreatingConnectionParams::getServerUrl, + .extracting(connectionParams -> connectionParams.getConnection().getLeft().getServerUrl(), connectionParams -> connectionParams.getConnection().getLeft() != null, AssistCreatingConnectionParams::getTokenName, AssistCreatingConnectionParams::getTokenValue)