internal /* for testing */ static bool ShouldMergeAnalysisSettings(string language, AnalysisConfig config, Common.ILogger logger) { Debug.Assert(!string.IsNullOrEmpty(language)); Debug.Assert(config != null); // See https://github.com/SonarSource/sonar-scanner-msbuild/issues/561 // Legacy behaviour is to overwrite. // The new (SQ 7.4+) behaviour is to merge only if sonar.[LANGUAGE].roslyn.ignoreIssues is false. var serverVersion = config?.FindServerVersion(); if (serverVersion == null || serverVersion < new Version("7.4")) { logger.LogInfo(Resources.AnalyzerSettings_ExternalIssueNotSupported, SonarProduct.GetSonarProductToLog(config?.SonarQubeHostUrl)); return(false); } var settingName = $"sonar.{language}.roslyn.ignoreIssues"; var settingInFile = config.GetSettingOrDefault(settingName, includeServerSettings: true, defaultValue: "false"); if (bool.TryParse(settingInFile, out var ignoreExternalRoslynIssues)) { logger.LogDebug(Resources.AnalyzerSettings_ImportAllSettingValue, settingName, ignoreExternalRoslynIssues.ToString().ToLowerInvariant()); return(!ignoreExternalRoslynIssues); } else { logger.LogWarning(Resources.AnalyzerSettings_InvalidValueForImportAll, settingName, settingInFile); return(false); } }
public bool ProcessCoverageReports() { if (!this.succesfullyInitialised) { throw new InvalidOperationException(Resources.EX_CoverageReportProcessorNotInitialised); } if (config.GetSettingOrDefault(SonarProperties.VsTestReportsPaths, true, null) != null) { Logger.LogInfo(Resources.TRX_DIAG_SkippingCoverageCheckPropertyProvided); } else { // Fetch all of the report URLs Logger.LogInfo(Resources.PROC_DIAG_FetchingCoverageReportInfoFromServer); if (TryGetTrxFiles(this.config, this.settings, out var trxPaths) && trxPaths.Any()) { using (StreamWriter sw = File.AppendText(propertiesFilePath)) { sw.WriteLine($"{SonarProperties.VsTestReportsPaths}={string.Join(",", trxPaths.Select(c => c.Replace(@"\", @"\\")))}"); } } } var success = TryGetVsCoverageFiles(this.config, this.settings, out var vscoveragePaths); if (success && vscoveragePaths.Any() && TryConvertCoverageReports(vscoveragePaths, out var coverageReportPaths) && coverageReportPaths.Any() && config.GetSettingOrDefault(SonarProperties.VsCoverageXmlReportsPaths, true, null) == null) { using (StreamWriter sw = File.AppendText(propertiesFilePath)) { sw.WriteLine($"{SonarProperties.VsCoverageXmlReportsPaths}={string.Join(",", coverageReportPaths.Select(c => c.Replace(@"\", @"\\")))}"); } } return(success); }
public bool ProcessCoverageReports() { if (!this.succesfullyInitialised) { throw new InvalidOperationException(Resources.EX_CoverageReportProcessorNotInitialised); } Debug.Assert(this.config != null, "Expecting the config to not be null. Did you call Initialize() ?"); if (config.GetSettingOrDefault(SonarProperties.VsTestReportsPaths, true, null) != null) { Logger.LogInfo(Resources.TRX_DIAG_SkippingCoverageCheckPropertyProvided); } else { // Fetch all of the report URLs Logger.LogInfo(Resources.PROC_DIAG_FetchingCoverageReportInfoFromServer); if (TryGetTrxFiles(this.config, this.settings, out var trxPaths) && trxPaths.Any()) { this.config.LocalSettings.Add(new Property { Id = SonarProperties.VsTestReportsPaths, Value = string.Join(",", trxPaths) }); } } var success = TryGetVsCoverageFiles(this.config, this.settings, out var vscoveragePaths); if (success && vscoveragePaths.Any() && TryConvertCoverageReports(vscoveragePaths, out var coverageReportPaths) && coverageReportPaths.Any() && config.GetSettingOrDefault(SonarProperties.VsCoverageXmlReportsPaths, true, null) == null) { this.config.LocalSettings.Add(new Property { Id = SonarProperties.VsCoverageXmlReportsPaths, Value = string.Join(",", coverageReportPaths) }); } return(success); }
public void ProcessCoverageReports_VsCoverageXmlPathProvided_NotCoverageXmlFileAlreadyPresent_ShouldTryConverting() { // Arrange var mockSearchFallback = new MockSearchFallback(); var testDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); var testResultsDir = Path.Combine(testDir, "TestResults"); var analysisConfig = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; var testLogger = new TestLogger(); Directory.CreateDirectory(testResultsDir); var coverageDir = Path.Combine(testResultsDir, "dummy", "In"); Directory.CreateDirectory(coverageDir); TestUtils.CreateTextFile(testResultsDir, "dummy.trx", TRX_PAYLOAD); TestUtils.CreateTextFile(coverageDir, "dummy.coverage", ""); var converter = new MockReportConverter(); converter.CanConvert = true; var testSubject = new BuildVNextCoverageReportProcessor(converter, testLogger, mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; var coveragePathValue = "ThisIsADummyPath"; analysisConfig.LocalSettings.Add(new Property { Id = SonarProperties.VsCoverageXmlReportsPaths, Value = coveragePathValue }); testSubject.Initialise(analysisConfig, settings, testDir + "\\sonar-project.properties"); // Act var result = testSubject.ProcessCoverageReports(); // Assert result.Should().BeTrue(); converter.AssertExpectedNumberOfConversions(1); Assert.AreEqual(analysisConfig.GetSettingOrDefault(SonarProperties.VsCoverageXmlReportsPaths, true, null), coveragePathValue); }