Skip to content

Commit

Permalink
Add check for SQ version to fill the Combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
ugras-ergun-sonarsource committed Nov 21, 2023
1 parent c131345 commit 43f7f59
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,52 @@ public void MefCtor_CheckExports()
MefTestHelpers.CheckTypeCanBeImported<ConnectedModeFeaturesConfiguration, IConnectedModeFeaturesConfiguration>(
MefTestHelpers.CreateExport<ISonarQubeService>());
}


[TestMethod]
public void IsAcceptTransitionAvailable_NoServerInfo_ReturnsFalse()
{
var testSubject = CreateTestSubject(null);

testSubject.IsAcceptTransitionAvailable().Should().BeFalse();
}

[DataRow(1, 2, 3)]
[DataRow(1231923123, 31312, 0)]
[DataRow(9, 7, 3)]
[DataRow(9, 6, 9)]
[DataRow(0, 0, 0)]
[DataTestMethod]
public void IsAcceptTransitionAvailable_AnySonarCloudVersion_ReturnsTrue(int major, int minor, int build)
{
var testSubject = CreateTestSubject(new ServerInfo(new Version(major, minor, build), ServerType.SonarCloud));

testSubject.IsAcceptTransitionAvailable().Should().BeTrue();
}

[DataRow(0, 0, 0, false)]
[DataRow(10, 0, 0, false)]
[DataRow(10, 5, 0, true)]
[DataRow(10, 4, 0, true)]
[DataRow(10, 3, 0, false)]
[DataRow(12, 0, 0, true)]
[DataRow(10, 0, 99, false)]
[DataRow(9, 10, 0, false)]
[DataTestMethod]
public void IsAcceptTransitionAvailable_SonarQube_RespectsMinimumVersion(int major, int minor, int build, bool expectedResult)
{
var testSubject = CreateTestSubject(new ServerInfo(new Version(major, minor, build), ServerType.SonarQube));

testSubject.IsAcceptTransitionAvailable().Should().Be(expectedResult);
}

[TestMethod]
public void IsNewCctAvailable_NoServerInfo_ReturnsTrue()
{
var testSubject = CreateTestSubject(null);

testSubject.IsNewCctAvailable().Should().BeTrue();
}

[DataRow(1, 2, 3)]
[DataRow(1231923123, 31312, 0)]
[DataRow(9, 7, 3)]
Expand Down Expand Up @@ -82,7 +119,7 @@ public void IsHotspotsAnalysisEnabled_NoServerInfo_ReturnsFalse()

testSubject.IsHotspotsAnalysisEnabled().Should().BeFalse();
}

[DataRow(1, 2, 3)]
[DataRow(1231923123, 31312, 0)]
[DataRow(9, 7, 3)]
Expand Down
25 changes: 20 additions & 5 deletions src/Core/Configuration/ConnectedModeFeaturesConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@ namespace SonarLint.VisualStudio.Core.Configuration
public interface IConnectedModeFeaturesConfiguration
{
/// <summary>
/// Indicates whether Local Hotspot Analysis is supported in the current Connected Mode state
/// Indicates whether Local Hotspot Analysis is supported in the current Connected Mode state
/// </summary>
/// <returns>True if connected to SCloud or SQube 9.7 and above, False otherwise</returns>

bool IsHotspotsAnalysisEnabled();

/// <summary>
/// Indicates whether the new Clean Code Taxonomy should be used in the current Connected Mode state
/// </summary>
/// <returns>False if connected to SQube 10.1.X and below, True otherwise (including Standalone)</returns>
bool IsNewCctAvailable();

/// <summary>
/// Indicates whether the Accept transition is supportted in current server
/// </summary>
/// <returns>True if connected to SCloud or SQube 10.4 and above, False otherwise</returns>
bool IsAcceptTransitionAvailable();
}

[Export(typeof(IConnectedModeFeaturesConfiguration))]
Expand All @@ -47,6 +54,7 @@ public class ConnectedModeFeaturesConfiguration : IConnectedModeFeaturesConfigur
{
private readonly Version minimalSonarQubeVersionForHotspots = new Version(9, 7);
private readonly Version minimalSonarQubeVersionForNewTaxonomy = new Version(10, 2);
private readonly Version minimalSonarQubeVersionForAccept = new Version(10, 4);
private readonly ISonarQubeService sonarQubeService;

[ImportingConstructor]
Expand All @@ -58,15 +66,15 @@ public ConnectedModeFeaturesConfiguration(ISonarQubeService sonarQubeService)
public bool IsNewCctAvailable()
{
var serverInfo = sonarQubeService.GetServerInfo();

// use new cct in standalone, connected to SC or connected to SQ >=10.2
return serverInfo == null || IsSupportedForVersion(serverInfo, minimalSonarQubeVersionForNewTaxonomy);
}

public bool IsHotspotsAnalysisEnabled()
{
var serverInfo = sonarQubeService.GetServerInfo();

// analyze hotspots connected to SC or connected to SQ >= 9.7
return serverInfo != null && IsSupportedForVersion(serverInfo, minimalSonarQubeVersionForHotspots);
}
Expand All @@ -75,5 +83,12 @@ private static bool IsSupportedForVersion(ServerInfo serverInfo, Version minimum
serverInfo.ServerType == ServerType.SonarCloud
|| (serverInfo.ServerType == ServerType.SonarQube &&
serverInfo.Version >= minimumVersion);

public bool IsAcceptTransitionAvailable()
{
var serverInfo = sonarQubeService.GetServerInfo();

return serverInfo != null && IsSupportedForVersion(serverInfo, minimalSonarQubeVersionForAccept);
}
}
}

0 comments on commit 43f7f59

Please sign in to comment.