From 89fbbbae771be984ba21fa21bf3ae0bc62b85e97 Mon Sep 17 00:00:00 2001 From: Pavel Mikula Date: Wed, 7 Apr 2021 18:05:11 +0200 Subject: [PATCH 1/3] Remove duplicate test categorization description --- .../Targets/SonarQube.Integration.targets | 60 ++++++------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets b/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets index 8037de372..11802e559 100644 --- a/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets +++ b/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets @@ -4,59 +4,46 @@ - + From a4fce6c37d775c660c44bb3cad33cd09ebf67e52 Mon Sep 17 00:00:00 2001 From: Pavel Mikula Date: Wed, 7 Apr 2021 18:28:41 +0200 Subject: [PATCH 2/3] Remove unused class --- .../WellKnownProjectProperties.cs | 164 ------------------ 1 file changed, 164 deletions(-) delete mode 100644 Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/WellKnownProjectProperties.cs diff --git a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/WellKnownProjectProperties.cs b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/WellKnownProjectProperties.cs deleted file mode 100644 index a39dbbcec..000000000 --- a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/WellKnownProjectProperties.cs +++ /dev/null @@ -1,164 +0,0 @@ -/* - * SonarScanner for MSBuild - * Copyright (C) 2016-2021 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 System.Collections.Generic; - -namespace SonarScanner.MSBuild.Tasks.IntegrationTests -{ - /// - /// Dictionary with strongly-typed accessors for some well-known properties - /// - internal class WellKnownProjectProperties : Dictionary - { - #region Public properties - - public string SonarQubeExclude - { - get => GetValueOrNull(TargetProperties.SonarQubeExcludeMetadata); - set => this[TargetProperties.SonarQubeExcludeMetadata] = value; - } - - public string SonarQubeTargetsPath - { - get => GetValueOrNull(TargetProperties.SonarQubeTargetsPath); - set => this[TargetProperties.SonarQubeTargetsPath] = value; - } - - public string SonarQubeOutputPath - { - get => GetValueOrNull(TargetProperties.SonarQubeOutputPath); - set => this[TargetProperties.SonarQubeOutputPath] = value; - } - - public string SonarQubeConfigPath - { - get => GetValueOrNull(TargetProperties.SonarQubeConfigPath); - set => this[TargetProperties.SonarQubeConfigPath] = value; - } - - public string SonarQubeTempPath - { - get => GetValueOrNull(TargetProperties.SonarQubeTempPath); - set => this[TargetProperties.SonarQubeTempPath] = value; - } - - public string RunCodeAnalysis - { - get => GetValueOrNull(TargetProperties.RunCodeAnalysis); - set => this[TargetProperties.RunCodeAnalysis] = value; - } - - public string CodeAnalysisLogFile - { - get => GetValueOrNull(TargetProperties.CodeAnalysisLogFile); - set => this[TargetProperties.CodeAnalysisLogFile] = value; - } - - public string CodeAnalysisRuleset - { - get => GetValueOrNull(TargetProperties.CodeAnalysisRuleset); - set => this[TargetProperties.CodeAnalysisRuleset] = value; - } - - public string ResolvedCodeAnalysisRuleset - { - get => GetValueOrNull(TargetProperties.ResolvedCodeAnalysisRuleset); - set => this[TargetProperties.ResolvedCodeAnalysisRuleset] = value; - } - - public string ErrorLog - { - get => GetValueOrNull(TargetProperties.ErrorLog); - set => this[TargetProperties.ErrorLog] = value; - } - - public string WarningsAsErrors - { - get => GetValueOrNull(TargetProperties.WarningsAsErrors); - set => this[TargetProperties.WarningsAsErrors] = value; - } - - public string TreatWarningsAsErrors - { - get => GetValueOrNull(TargetProperties.TreatWarningsAsErrors); - set => this[TargetProperties.TreatWarningsAsErrors] = value; - } - - public string WarningLevel - { - get => GetValueOrNull(TargetProperties.WarningLevel); - set => this[TargetProperties.WarningLevel] = value; - } - - public string AssemblyName - { - get => GetValueOrNull(TargetProperties.AssemblyName); - set => this[TargetProperties.AssemblyName] = value; - } - - public string TeamBuildLegacyBuildDirectory - { - get => GetValueOrNull(TargetProperties.BuildDirectory_Legacy); - set => this[TargetProperties.BuildDirectory_Legacy] = value; - } - - public string TeamBuild2105BuildDirectory - { - get => GetValueOrNull(TargetProperties.BuildDirectory_TFS2015); - set => this[TargetProperties.BuildDirectory_TFS2015] = value; - } - - public string BuildingInsideVS - { - get => GetValueOrNull(TargetProperties.BuildingInsideVS); - set => this[TargetProperties.BuildingInsideVS] = value; - } - - public string MSBuildExtensionsPath - { - get => GetValueOrNull(TargetProperties.MSBuildExtensionsPath); - set => this[TargetProperties.MSBuildExtensionsPath] = value; - } - - public string SonarTestProject - { - get => GetValueOrNull(TargetProperties.SonarQubeTestProject); - set => this[TargetProperties.SonarQubeTestProject] = value; - } - - public string ProjectTypeGuids - { - get => GetValueOrNull(TargetProperties.ProjectTypeGuids); - set => this[TargetProperties.ProjectTypeGuids] = value; - } - - #endregion Public properties - - #region Private methods - - private string GetValueOrNull(string key) - { - TryGetValue(key, out string value); - return value; - } - - #endregion Private methods - } -} From 7db430d2f4f5ec6e36792ef33c54387197fe8515 Mon Sep 17 00:00:00 2001 From: Pavel Mikula Date: Wed, 7 Apr 2021 18:38:52 +0200 Subject: [PATCH 3/3] Implement --- .../Infrastructure/TargetConstants.cs | 2 ++ .../CaptureDataTargetsFileTemplate.xml | 2 ++ ...nner.MSBuild.Tasks.IntegrationTests.csproj | 1 - .../TargetsTests/RoslynTargetsTests.cs | 20 +++++++++++++++++++ .../Targets/SonarQube.Integration.targets | 4 ++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/TargetConstants.cs b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/TargetConstants.cs index 4c0c979f4..34b3a478e 100644 --- a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/TargetConstants.cs +++ b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Infrastructure/TargetConstants.cs @@ -87,6 +87,8 @@ internal static class TargetProperties public const string AssemblyName = "AssemblyName"; + public const string RunAnalyzers = "RunAnalyzers"; + public const string RunAnalyzersDuringBuild = "RunAnalyzersDuringBuild"; public const string TreatWarningsAsErrors = "TreatWarningsAsErrors"; public const string WarningsAsErrors = "WarningsAsErrors"; public const string WarningLevel = "WarningLevel"; diff --git a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Resources/CaptureDataTargetsFileTemplate.xml b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Resources/CaptureDataTargetsFileTemplate.xml index b72472105..530295d73 100644 --- a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Resources/CaptureDataTargetsFileTemplate.xml +++ b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/Resources/CaptureDataTargetsFileTemplate.xml @@ -11,6 +11,8 @@ + + diff --git a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/SonarScanner.MSBuild.Tasks.IntegrationTests.csproj b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/SonarScanner.MSBuild.Tasks.IntegrationTests.csproj index d76fc54e9..ae02593ba 100644 --- a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/SonarScanner.MSBuild.Tasks.IntegrationTests.csproj +++ b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/SonarScanner.MSBuild.Tasks.IntegrationTests.csproj @@ -150,7 +150,6 @@ - True diff --git a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/TargetsTests/RoslynTargetsTests.cs b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/TargetsTests/RoslynTargetsTests.cs index 3d909ebf7..b52c9fa72 100644 --- a/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/TargetsTests/RoslynTargetsTests.cs +++ b/Tests/SonarScanner.MSBuild.Tasks.IntegrationTests/TargetsTests/RoslynTargetsTests.cs @@ -158,6 +158,7 @@ public void Settings_ValidSetup_LegacyServer_Override_Analyzers() AssertExpectedAdditionalFiles(result, "should.not.be.removed.additional1.txt", "should.not.be.removed.additional2.txt"); AssertExpectedAnalyzers(result, @"c:\data\new.analyzer1.dll", @"c:\new.analyzer2.dll"); AssertWarningsAreNotTreatedAsErrorsNorIgnored(result); + AssertRunAnalyzersIsEnabled(result); } [TestMethod] @@ -246,6 +247,7 @@ public void Settings_ValidSetup_NonLegacyServer_MergeSettings() @"original\should.be.preserved\analyzer3.dll"); AssertWarningsAreNotTreatedAsErrorsNorIgnored(result); + AssertRunAnalyzersIsEnabled(result); } [TestMethod] @@ -356,6 +358,8 @@ public void Settings_TempFolderIsNotSet() pre-existing.ruleset CS101 true + false + false @@ -377,8 +381,11 @@ public void Settings_TempFolderIsNotSet() result.AssertExpectedItemGroupCount(TargetProperties.AnalyzerItemType, 0); result.AssertExpectedItemGroupCount(TargetProperties.AdditionalFilesItemType, 0); + // Properties are not overriden result.AssertExpectedCapturedPropertyValue(TargetProperties.TreatWarningsAsErrors, "true"); result.AssertExpectedCapturedPropertyValue(TargetProperties.WarningsAsErrors, "CS101"); + result.AssertExpectedCapturedPropertyValue(TargetProperties.RunAnalyzers, "false"); + result.AssertExpectedCapturedPropertyValue(TargetProperties.RunAnalyzersDuringBuild, "false"); } [TestMethod] @@ -661,6 +668,15 @@ private static void AssertWarningsAreNotTreatedAsErrorsNorIgnored(BuildLog actua actualResult.AssertExpectedCapturedPropertyValue(TargetProperties.WarningLevel, "4"); } + /// + /// Checks that VS2019 properties are set to run the analysis. + /// + private static void AssertRunAnalyzersIsEnabled(BuildLog actualResult) + { + actualResult.AssertExpectedCapturedPropertyValue(TargetProperties.RunAnalyzers, "true"); + actualResult.AssertExpectedCapturedPropertyValue(TargetProperties.RunAnalyzersDuringBuild, "true"); + } + /// /// Checks that a SonarQubeSetting does not exist /// @@ -750,6 +766,9 @@ private BuildLog Execute_Settings_ValidSetup(string msBuildLanguage, bool isTest {msBuildLanguage} {isTestProject} c:\should.be.overridden.ruleset + + false + false @@ -773,6 +792,7 @@ private BuildLog Execute_Settings_ValidSetup(string msBuildLanguage, bool isTest AssertErrorLogIsSetBySonarQubeTargets(result); AssertWarningsAreNotTreatedAsErrorsNorIgnored(result); + AssertRunAnalyzersIsEnabled(result); var capturedProjectSpecificConfDir = result.GetCapturedPropertyValue(TargetProperties.ProjectSpecificConfDir); result.MessageLog.Should().Contain($@"Sonar: ({Path.GetFileName(filePath)}) Analysis configured successfully with {capturedProjectSpecificConfDir}\SonarProjectConfig.xml."); diff --git a/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets b/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets index 11802e559..bdb1a8b95 100644 --- a/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets +++ b/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets @@ -414,6 +414,10 @@ false + + true + true + 4