public override bool Execute() { var logger = new MSBuildLoggerAdapter(Log); var config = TaskUtilities.TryGetConfig(AnalysisConfigDir, logger); var languageSettings = GetLanguageSpecificSettings(config); if (languageSettings == null) { // Early-out: we don't have any settings for the current language. // Preserve the default existing behaviour of only preserving the original list of additional files but clearing the analyzers. RuleSetFilePath = null; AdditionalFilePaths = OriginalAdditionalFiles; return(!Log.HasLoggedErrors); } TaskOutputs outputs; // We analyze test projects since MMF-2297 / SQ 8.9. C#/VB.NET plugin <= 8.20 bundled with SQ <= 8.8 would ignore results on test projects anyway. if (IsTestProject && (ExcludeTestProjects() || !IsTestAnalysisSupported())) { // Special case: to provide colorization etc for code in test projects, we need to run only the SonarC#/VB analyzers, with all of the non-utility rules turned off // See [MMF-486]: https://jira.sonarsource.com/browse/MMF-486 Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_ConfiguringTestProjectAnalysis); outputs = CreateDeactivatedProjectSettings(languageSettings); } else { if (ShouldMergeAnalysisSettings(Language, config, logger)) { Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_MergingSettings); outputs = CreateMergedAnalyzerSettings(languageSettings); } else { Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_OverwritingSettings); outputs = CreateLegacyProductProjectSettings(languageSettings); } } ApplyTaskOutput(outputs); return(!Log.HasLoggedErrors); bool ExcludeTestProjects() => config.GetAnalysisSettings(false).TryGetValue(ExcludeTestProjectsSettingId, out var excludeTestProjects) && excludeTestProjects.Equals("true", StringComparison.OrdinalIgnoreCase); bool IsTestAnalysisSupported() { var version = config.FindServerVersion(); return(SonarProduct.IsSonarCloud(config.SonarQubeHostUrl, version) || version >= new Version(8, 9)); } }
[DataRow(false, "https://sonarcloud.io", "9.0")] // SC is defined as "Version 8.0" public void IsSonarCloud(bool expected, string host, string version) => SonarProduct.IsSonarCloud(host, new Version(version)).Should().Be(expected);
private async Task <bool> IsSonarCloud() => SonarProduct.IsSonarCloud(this.serverUrl, await GetServerVersion());