Skip to content

Commit

Permalink
SLVS-1818 Upgrade SLCore to 10.14.0.80189 and adapt RPC changes for S…
Browse files Browse the repository at this point in the history
…QC multi-region
  • Loading branch information
georgii-borovinskikh-sonarsource committed Feb 4, 2025
1 parent 7434614 commit a52e452
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/EmbeddedSonarAnalyzer.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<EmbeddedSonarHtmlAnalyzerVersion>3.18.0.5605</EmbeddedSonarHtmlAnalyzerVersion>
<EmbeddedSonarSecretsJarVersion>2.20.0.5038</EmbeddedSonarSecretsJarVersion>
<!-- SLOOP: Binaries for SonarLint Out Of Process -->
<EmbeddedSloopVersion>10.13.0.79996</EmbeddedSloopVersion>
<EmbeddedSloopVersion>10.14.0.80189</EmbeddedSloopVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/SLCore.IntegrationTests/SLCoreTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void Start()
foldersProvider.GetWorkFolders().Returns(new SLCoreFolders(storageRoot, workDir, userHome));

var connectionProvider = Substitute.For<IServerConnectionsProvider>();
connectionProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfiguration>());
connectionProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfigurationDtoBase>());

var jarProvider = Substitute.For<ISLCoreEmbeddedPluginJarLocator>();
jarProvider.ListJarFiles().Returns(DependencyLocator.AnalyzerPlugins);
Expand Down
2 changes: 1 addition & 1 deletion src/SLCore.UnitTests/SLCoreInstanceHandleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private void SetUpSuccessfulInitialization(out ILifecycleManagementSLCoreService
constantsProvider.TelemetryConstants.Returns(TelemetryConstants);

foldersProvider.GetWorkFolders().Returns(new SLCoreFolders(StorageRoot, WorkDir, UserHome));
connectionsProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfiguration>
connectionsProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfigurationDtoBase>
{
{ SonarQubeConnection1.connectionId, SonarQubeConnection1 },
{ SonarQubeConnection2.connectionId, SonarQubeConnection2 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void Ctor_TransientSonarCloudConnectionDtoWithCredentials_SerializeAsExpe
"credentials": {
"username": "myUser",
"password": "password"
}
},
"region": "EU"
}
}
""";
Expand All @@ -105,7 +106,8 @@ public void Ctor_TransientSonarCloudConnectionDtoDtoWithToken_SerializeAsExpecte
"organization": "myOrg",
"credentials": {
"token": "myToken"
}
},
"region": "EU"
}
}
""";
Expand All @@ -114,4 +116,37 @@ public void Ctor_TransientSonarCloudConnectionDtoDtoWithToken_SerializeAsExpecte

serializedString.Should().Be(expectedString);
}


[DataRow(SonarCloudRegion.EU, """
{
"transientConnection": {
"organization": "myOrg",
"credentials": {
"token": "myToken"
},
"region": "EU"
}
}
""")]
[DataRow(SonarCloudRegion.US, """
{
"transientConnection": {
"organization": "myOrg",
"credentials": {
"token": "myToken"
},
"region": "US"
}
}
""")]
[DataTestMethod]
public void Ctor_TransientSonarCloudConnectionWithRegion_SerializeAsExpected(SonarCloudRegion region, string expectedString)
{
var testSubject = new ValidateConnectionParams(new TransientSonarCloudConnectionDto("myOrg", Either<TokenDto, UsernamePasswordDto>.CreateLeft(new TokenDto("myToken")), region));

var serializedString = JsonConvert.SerializeObject(testSubject, Formatting.Indented);

serializedString.Should().Be(expectedString);
}
}
12 changes: 11 additions & 1 deletion src/SLCore.UnitTests/Service/Lifecycle/InitializeParamsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public void Serialize_AsExpected()
[Language.CPP],
["csharp"],
[new SonarQubeConnectionConfigurationDto("con1", true, "localhost")],
[new SonarCloudConnectionConfigurationDto("con2", false, "organization1")],
[
new SonarCloudConnectionConfigurationDto("con2", false, "organization1"),
new SonarCloudConnectionConfigurationDto("con3", true, "organization2", SonarCloudRegion.US)
],
"userHome",
new Dictionary<string, StandaloneRuleConfigDto>
{
Expand Down Expand Up @@ -107,8 +110,15 @@ [new SonarCloudConnectionConfigurationDto("con2", false, "organization1")],
"sonarCloudConnections": [
{
"organization": "organization1",
"region": "EU",
"connectionId": "con2",
"disableNotification": false
},
{
"organization": "organization2",
"region": "US",
"connectionId": "con3",
"disableNotification": true
}
],
"sonarlintUserHome": "userHome",
Expand Down
2 changes: 1 addition & 1 deletion src/SLCore.UnitTests/State/AliveConnectionTrackerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private static void VerifyLockTakenAndReleased(Mock<IAsyncLock> asyncLock, Mock<
}

private static void ConfigureConnectionProvider(out Mock<IServerConnectionsProvider> connectionProvider,
params ServerConnectionConfiguration[] connections)
params ServerConnectionConfigurationDtoBase[] connections)
{
connectionProvider = new Mock<IServerConnectionsProvider>();
connectionProvider.Setup(x => x.GetServerConnections()).Returns(connections.ToDictionary(x => x.connectionId, x => x));
Expand Down
4 changes: 2 additions & 2 deletions src/SLCore.UnitTests/State/ServerConnectionsProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void GetServerConnections_CorrectlyReturnsSonarCloudConnection()
var serverConnections = testSubject.GetServerConnections();

serverConnections.Should().HaveCount(1);
serverConnections[connection.Id].Should().BeOfType<SonarCloudConnectionConfigurationDto>().Which.organization.Should().Be(organizationKey);
serverConnections[connection.Id].Should().BeEquivalentTo(new SonarCloudConnectionConfigurationDto("https://sonarcloud.io/organizations/org", false, "org", SonarCloudRegion.EU));
}

[TestMethod]
Expand All @@ -99,7 +99,7 @@ public void GetServerConnections_CorrectlyReturnsSonarCloudNotifications(bool is
var serverConnections = testSubject.GetServerConnections();

serverConnections.Should().HaveCount(1);
serverConnections[connection.Id].Should().BeOfType<SonarCloudConnectionConfigurationDto>().Which.disableNotification.Should().Be(!isSmartNotificationsEnabled);
serverConnections[connection.Id].Should().BeEquivalentTo(new SonarCloudConnectionConfigurationDto("https://sonarcloud.io/organizations/org", !isSmartNotificationsEnabled, "org", SonarCloudRegion.EU));
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models
{
public record ServerConnectionConfiguration(string connectionId, bool disableNotification);
}
namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models;

public record ServerConnectionConfigurationDtoBase(string connectionId, bool disableNotification);
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models
{
public record SonarCloudConnectionConfigurationDto(string connectionId, bool disableNotification, string organization)
: ServerConnectionConfiguration(connectionId, disableNotification);
}
namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models;

public record SonarCloudConnectionConfigurationDto(string connectionId, bool disableNotification, string organization, SonarCloudRegion region = SonarCloudRegion.EU)
: ServerConnectionConfigurationDtoBase(connectionId, disableNotification);
29 changes: 29 additions & 0 deletions src/SLCore/Service/Connection/Models/SonarCloudRegion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2025 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models;

[JsonConverter(typeof(StringEnumConverter))]
public enum SonarCloudRegion {
EU, US
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models
{
public record SonarQubeConnectionConfigurationDto(string connectionId, bool disableNotification, string serverUrl)
: ServerConnectionConfiguration(connectionId, disableNotification);
}
namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models;

public record SonarQubeConnectionConfigurationDto(string connectionId, bool disableNotification, string serverUrl)
: ServerConnectionConfigurationDtoBase(connectionId, disableNotification);
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ namespace SonarLint.VisualStudio.SLCore.Service.Connection.Models;
public record TransientSonarCloudConnectionDto(
string organization,
[property: JsonConverter(typeof(EitherJsonConverter<TokenDto, UsernamePasswordDto>))]
Either<TokenDto, UsernamePasswordDto> credentials);
Either<TokenDto, UsernamePasswordDto> credentials,
SonarCloudRegion region = SonarCloudRegion.EU);
8 changes: 4 additions & 4 deletions src/SLCore/State/ServerConnectionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace SonarLint.VisualStudio.SLCore.State;

internal interface IServerConnectionsProvider
{
Dictionary<string, ServerConnectionConfiguration> GetServerConnections();
Dictionary<string, ServerConnectionConfigurationDtoBase> GetServerConnections();
}

[Export(typeof(IServerConnectionsProvider))]
Expand All @@ -41,15 +41,15 @@ public ServerConnectionsProvider(IServerConnectionsRepository serverConnectionsR
this.serverConnectionsRepository = serverConnectionsRepository;
}

public Dictionary<string, ServerConnectionConfiguration> GetServerConnections()
public Dictionary<string, ServerConnectionConfigurationDtoBase> GetServerConnections()
{
var succeeded = serverConnectionsRepository.TryGetAll(out var serverConnections);
return succeeded ? GetServerConnectionConfigurations(serverConnections).ToDictionary(conf => conf.connectionId) : [];
}

private static List<ServerConnectionConfiguration> GetServerConnectionConfigurations(IReadOnlyList<ServerConnection> serverConnections)
private static List<ServerConnectionConfigurationDtoBase> GetServerConnectionConfigurations(IReadOnlyList<ServerConnection> serverConnections)
{
var serverConnectionConfigurations = new List<ServerConnectionConfiguration>();
var serverConnectionConfigurations = new List<ServerConnectionConfigurationDtoBase>();
foreach (var serverConnection in serverConnections)
{
switch (serverConnection)
Expand Down

0 comments on commit a52e452

Please sign in to comment.