Skip to content

Commit b3dda00

Browse files
SCAN4NET-67 Bump version to 8.0.3 and cherry pick commits (#2192)
Co-authored-by: Cristian <67206480+CristianAmbrosini@users.noreply.github.com>
1 parent eac03da commit b3dda00

File tree

19 files changed

+684
-516
lines changed

19 files changed

+684
-516
lines changed

AssemblyInfo.Shared.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
using System.Resources;
2323
using System.Runtime.InteropServices;
2424

25-
[assembly: AssemblyVersion("8.0.2")]
26-
[assembly: AssemblyFileVersion("8.0.2.0")]
27-
[assembly: AssemblyInformationalVersion("Version:8.0.2.0 Branch:not-set Sha1:not-set")]
25+
[assembly: AssemblyVersion("8.0.3")]
26+
[assembly: AssemblyFileVersion("8.0.3.0")]
27+
[assembly: AssemblyInformationalVersion("Version:8.0.3.0 Branch:not-set Sha1:not-set")]
2828
[assembly: AssemblyConfiguration("")]
2929
[assembly: AssemblyCompany("SonarSource and Microsoft")]
3030
[assembly: AssemblyCopyright("Copyright © SonarSource and Microsoft 2015-2023")]

Tests/SonarScanner.MSBuild.Common.Test/ProjectInfo/ProjectInfoExtensionsTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
*/
2020

2121
using System;
22+
using System.IO;
2223
using FluentAssertions;
2324
using Microsoft.VisualStudio.TestTools.UnitTesting;
25+
using TestUtilities;
2426

2527
namespace SonarScanner.MSBuild.Common.Test;
2628

2729
[TestClass]
2830
public class ProjectInfoExtensionsTests
2931
{
32+
public TestContext TestContext { get; set; }
33+
3034
[TestMethod]
3135
public void TryGetAnalysisSetting_WhenProjectInfoIsNull_ThrowsArgumentNullException()
3236
{
@@ -136,4 +140,39 @@ public void GetProjectGuidAsString_WhenProjectInfoIsNull_ThrowsArgumentNullExcep
136140
// Assert
137141
action.Should().ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("projectInfo");
138142
}
143+
144+
[TestMethod]
145+
public void GetAllAnalysisFilesTest()
146+
{
147+
var dir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);
148+
var filesToAnalyze = Path.Combine(dir, TestUtils.FilesToAnalyze);
149+
var logger = new TestLogger();
150+
var projectInfo = new ProjectInfo
151+
{
152+
AnalysisResults =
153+
[
154+
new AnalysisResult
155+
{
156+
Id = TestUtils.FilesToAnalyze,
157+
Location = filesToAnalyze,
158+
}
159+
]
160+
};
161+
File.WriteAllLines(
162+
filesToAnalyze,
163+
[
164+
"C:\\foo",
165+
"C:\\bar",
166+
"not:allowed",
167+
"C:\\baz",
168+
]);
169+
170+
var result = projectInfo.GetAllAnalysisFiles(logger);
171+
172+
result.Should().HaveCount(3);
173+
result[0].Name.Should().Be("foo");
174+
result[1].Name.Should().Be("bar");
175+
result[2].Name.Should().Be("baz");
176+
logger.AssertSingleDebugMessageExists("Could not add 'not:allowed' to the analysis. The given path's format is not supported.");
177+
}
139178
}

Tests/SonarScanner.MSBuild.PreProcessor.Test/AnalysisConfigGeneratorTests.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,77 @@ public void GenerateFile_ExcludeCoverage_Exclusions_MultipleSpecified()
384384
.Which.Value.Should().Be("coverage1.xml,coverage2.xml,coverage3.xml,coverage4.xml");
385385
}
386386

387+
[DataTestMethod]
388+
[DataRow("coverage.xml", "", "", "", "coverage.xml", "")]
389+
[DataRow("coverage.xml", "", "local.cs,local.js", "", "local.cs,local.js,coverage.xml", "")]
390+
[DataRow("coverage.xml", "", "", "server.cs,server.js", "server.cs,server.js,coverage.xml", "server.cs,server.js")]
391+
[DataRow("coverage.xml", "", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js,coverage.xml", "server.cs,server.js")]
392+
[DataRow("", "", "", "", "", "")]
393+
[DataRow("", "", "local.cs,local.js", "", "local.cs,local.js", "")]
394+
[DataRow("", "", "", "server.cs,server.js", "", "server.cs,server.js")]
395+
[DataRow("", "", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js", "server.cs,server.js")]
396+
[DataRow("", "coverage.xml", "", "", "coverage.xml", "")]
397+
[DataRow("", "coverage.xml", "local.cs,local.js", "", "local.cs,local.js,coverage.xml", "")]
398+
[DataRow("", "coverage.xml", "", "server.cs,server.js", "server.cs,server.js,coverage.xml", "server.cs,server.js")]
399+
[DataRow("", "coverage.xml", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js,coverage.xml", "server.cs,server.js")]
400+
[DataRow("localCoverage.xml", "serverCoverage.xml", "", "", "localCoverage.xml", "")]
401+
[DataRow("localCoverage.xml", "serverCoverage.xml", "local.cs,local.js", "", "local.cs,local.js,localCoverage.xml", "")]
402+
[DataRow("localCoverage.xml", "serverCoverage.xml", "", "server.cs,server.js", "server.cs,server.js,localCoverage.xml", "server.cs,server.js")]
403+
[DataRow("localCoverage.xml", "serverCoverage.xml", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js,localCoverage.xml", "server.cs,server.js")]
404+
public void GenerateFile_ExcludeCoverage(
405+
string localCoverageReportPath,
406+
string serverCoverageReportPath,
407+
string localExclusions,
408+
string serverExclusions,
409+
string expectedLocalExclusions,
410+
string expectedServerExclusions)
411+
{
412+
var analysisDir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);
413+
var settings = BuildSettings.CreateNonTeamBuildSettingsForTesting(analysisDir);
414+
Directory.CreateDirectory(settings.SonarConfigDirectory);
415+
var commandLineArguments = new ListPropertiesProvider();
416+
if (!string.IsNullOrWhiteSpace(localExclusions)) // You cannot provide an empty /d:sonar.exclusions="" argument
417+
{
418+
commandLineArguments.AddProperty("sonar.exclusions", localExclusions);
419+
}
420+
if (!string.IsNullOrWhiteSpace(localCoverageReportPath))
421+
{
422+
commandLineArguments.AddProperty("sonar.cs.vscoveragexml.reportsPaths", localCoverageReportPath);
423+
}
424+
var serverSettings = new Dictionary<string, string>();
425+
if (!string.IsNullOrWhiteSpace(serverExclusions))
426+
{
427+
serverSettings.Add("sonar.exclusions", serverExclusions);
428+
}
429+
if (!string.IsNullOrWhiteSpace(serverCoverageReportPath))
430+
{
431+
serverSettings.Add("sonar.cs.vscoveragexml.reportsPaths", serverCoverageReportPath);
432+
}
433+
434+
var args = CreateProcessedArgs(commandLineArguments, EmptyPropertyProvider.Instance, Substitute.For<ILogger>());
435+
var config = AnalysisConfigGenerator.GenerateFile(args, settings, [], serverSettings, [], "1.2.3.4", string.Empty);
436+
437+
if (string.IsNullOrWhiteSpace(expectedLocalExclusions))
438+
{
439+
config.LocalSettings.Should().NotContain(x => x.Id == "sonar.exclusions");
440+
}
441+
else
442+
{
443+
config.LocalSettings.Should().ContainSingle(x => x.Id == "sonar.exclusions")
444+
.Which.Value.Should().Be(expectedLocalExclusions);
445+
}
446+
447+
if (string.IsNullOrWhiteSpace(expectedServerExclusions))
448+
{
449+
config.ServerSettings.Should().NotContain(x => x.Id == "sonar.exclusions");
450+
}
451+
else
452+
{
453+
config.ServerSettings.Should().ContainSingle(x => x.Id == "sonar.exclusions")
454+
.Which.Value.Should().Be(expectedServerExclusions);
455+
}
456+
}
457+
387458
private void AssertConfigFileExists(AnalysisConfig config)
388459
{
389460
config.Should().NotBeNull("Supplied config should not be null");

Tests/SonarScanner.MSBuild.Shim.Test/AdditionalFilesServiceTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ public void AdditionalFiles_ExtensionsFound_AllExtensionPermutations(string prop
206206
[DataRow("sonar.tsql.file.suffixes")]
207207
[DataRow("sonar.plsql.file.suffixes")]
208208
[DataRow("sonar.yaml.file.suffixes")]
209-
[DataRow("sonar.xml.file.suffixes")]
210209
[DataRow("sonar.json.file.suffixes")]
211210
[DataRow("sonar.css.file.suffixes")]
212211
[DataRow("sonar.html.file.suffixes")]

Tests/SonarScanner.MSBuild.Shim.Test/PropertiesFileGeneratorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public void GenerateFile_MissingFilesAreSkipped()
640640
Encoding = "UTF-8"
641641
};
642642

643-
var analysisFileList = CreateFileList(projectBaseDir, "filesToAnalyze.txt", existingManagedFile, missingManagedFile, existingContentFile, missingContentFile);
643+
var analysisFileList = CreateFileList(projectBaseDir, TestUtils.FilesToAnalyze, existingManagedFile, missingManagedFile, existingContentFile, missingContentFile);
644644
projectInfo.AddAnalyzerResult(AnalysisType.FilesToAnalyze, analysisFileList);
645645
var projectInfoDir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext, "ProjectInfo1Dir");
646646
var projectInfoFilePath = Path.Combine(projectInfoDir, FileConstants.ProjectInfoFileName);
@@ -849,7 +849,7 @@ public void TryWriteProperties_WhenThereIsNoCommonPath_LogsError()
849849
var outPath = Path.Combine(TestContext.TestRunDirectory!, ".sonarqube", "out");
850850
Directory.CreateDirectory(outPath);
851851
var fileToAnalyzePath = TestUtils.CreateEmptyFile(TestContext.TestRunDirectory, "file.cs");
852-
var filesToAnalyzePath = TestUtils.CreateFile(TestContext.TestRunDirectory, "FilesToAnalyze.txt", fileToAnalyzePath);
852+
var filesToAnalyzePath = TestUtils.CreateFile(TestContext.TestRunDirectory, TestUtils.FilesToAnalyze, fileToAnalyzePath);
853853
var config = new AnalysisConfig { SonarOutputDir = outPath };
854854
var sut = new PropertiesFileGenerator(config, logger);
855855

@@ -859,15 +859,15 @@ public void TryWriteProperties_WhenThereIsNoCommonPath_LogsError()
859859
FullPath = Path.Combine(TestContext.TestRunDirectory, "First"),
860860
ProjectName = "First",
861861
AnalysisSettings = [],
862-
AnalysisResults = [new AnalysisResult { Id = "FilesToAnalyze", Location = filesToAnalyzePath }]
862+
AnalysisResults = [new AnalysisResult { Id = TestUtils.FilesToAnalyze, Location = filesToAnalyzePath }]
863863
};
864864
var secondProjectInfo = new ProjectInfo
865865
{
866866
ProjectGuid = Guid.NewGuid(),
867867
FullPath = Path.Combine(Path.GetTempPath(), "Second"),
868868
ProjectName = "Second",
869869
AnalysisSettings = [],
870-
AnalysisResults = [new AnalysisResult { Id = "FilesToAnalyze", Location = filesToAnalyzePath }]
870+
AnalysisResults = [new AnalysisResult { Id = TestUtils.FilesToAnalyze, Location = filesToAnalyzePath }]
871871
};
872872
TestUtils.CreateEmptyFile(TestContext.TestRunDirectory, "First");
873873
TestUtils.CreateEmptyFile(Path.GetTempPath(), "Second");

Tests/SonarScanner.MSBuild.Shim.Test/PropertiesFileGeneratorTests_MultiTarget.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private static void CreateProjectInfoAndFilesToAnalyze(Guid guid,
268268

269269
// Create FilesToAnalyze.txt in each folder, they are the same,
270270
// because are the result of the compilation of the same project
271-
var filesToAnalyze_txt = Path.Combine(@out, "FilesToAnalyze.txt");
271+
var filesToAnalyze_txt = Path.Combine(@out, TestUtils.FilesToAnalyze);
272272
File.WriteAllLines(filesToAnalyze_txt, files.ToArray());
273273

274274
// Create project info for the configuration, the project path is important, the name is ignored
@@ -280,7 +280,7 @@ private static void CreateProjectInfoAndFilesToAnalyze(Guid guid,
280280
ProjectType = ProjectType.Product,
281281
Encoding = "UTF-8",
282282
IsExcluded = isExcluded,
283-
AnalysisResults = [new() { Id = "FilesToAnalyze", Location = filesToAnalyze_txt }]
283+
AnalysisResults = [new() { Id = TestUtils.FilesToAnalyze, Location = filesToAnalyze_txt }]
284284
};
285285
TestUtils.CreateEmptyFile(projectRoot, "Project1.csproj");
286286
projectInfo.Save(Path.Combine(@out, FileConstants.ProjectInfoFileName));

Tests/SonarScanner.MSBuild.Tasks.IntegrationTest/E2ETests/E2EAnalysisTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public void E2E_NoAnalyzableFiles()
235235
actualStructure.AssertConfigFileDoesNotExist(ExpectedAnalysisFilesListFileName);
236236

237237
// Check the projectInfo.xml does not have an analysis result
238-
actualStructure.ProjectInfo.AssertAnalysisResultDoesNotExists("FilesToAnalyze");
238+
actualStructure.ProjectInfo.AssertAnalysisResultDoesNotExists(TestUtils.FilesToAnalyze);
239239
}
240240

241241
[TestMethod]
@@ -959,7 +959,7 @@ private static void AssertProjectInfoContent(ProjectInfo projectInfo, string exp
959959
{
960960
projectInfo.ProjectLanguage.Should().Be("my.language", "Unexpected project language");
961961
projectInfo.ProjectType.Should().Be(ProjectType.Product, "Project should be marked as a product project");
962-
projectInfo.AnalysisResults.Single(x => x.Id.Equals("FilesToAnalyze")).Location.Should().Be(expectedFilesToAnalyzePath);
962+
projectInfo.AnalysisResults.Single(x => x.Id.Equals(TestUtils.FilesToAnalyze)).Location.Should().Be(expectedFilesToAnalyzePath);
963963
projectInfo.AnalysisSettings.Single(x => x.Id.Equals("sonar.cs.roslyn.reportFilePaths")).Value.Should().Be(expectedReportFilePaths);
964964
projectInfo.AnalysisSettings.Single(x => x.Id.Equals("sonar.cs.analyzer.projectOutPaths")).Value.Should().Be(expectedProjectOutPaths);
965965
}
@@ -1121,7 +1121,7 @@ public void AssertExpectedFileList(params string[] fileNames)
11211121
var expectedFullPaths = fileNames.Select(x => context.InputFolder + x);
11221122
File.ReadLines(filesToAnalyzeFile.FullPath).Should().BeEquivalentTo(expectedFullPaths);
11231123

1124-
var actualFilesToAnalyze = ProjectInfo.AssertAnalysisResultExists("FilesToAnalyze");
1124+
var actualFilesToAnalyze = ProjectInfo.AssertAnalysisResultExists(TestUtils.FilesToAnalyze);
11251125
actualFilesToAnalyze.Location.Should().Be(filesToAnalyzeFile.FullPath);
11261126

11271127
AssertFileIsUtf8Bom(filesToAnalyzeFile.FullPath);

Tests/TestUtilities/TestUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace TestUtilities;
3030

3131
public static class TestUtils
3232
{
33+
public const string FilesToAnalyze = nameof(FilesToAnalyze);
3334
// Target file names
3435
public const string AnalysisTargetFile = "SonarQube.Integration.targets";
35-
3636
public const string ImportsBeforeFile = "SonarQube.Integration.ImportBefore.targets";
3737

3838
/// <summary>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<parent><child /></parent>
2+
<?xml version="1.0" encoding="UTF-8"?> <!-- Noncompliant S1778 -->
3+
4+
<dependency>
5+
<groupId>semigroup</groupId>
6+
<artifactId>haskell.curry.monoid</artifactId>
7+
<version>42.0</version>
8+
</dependency>

its/src/test/java/com/sonar/it/scanner/msbuild/sonarqube/ScannerMSBuildTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ void testExcludedAndTest_simulateAzureDevopsEnvironmentSettingMalformedJson_Logs
292292

293293
@Test
294294
void testMultiLanguage() throws Exception {
295+
assumeTrue(ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9,9));
295296
String localProjectKey = PROJECT_KEY + ".12";
296297
ORCHESTRATOR.getServer().restoreProfile(FileLocation.of("projects/ConsoleMultiLanguage/TestQualityProfileCSharp.xml"));
297298
ORCHESTRATOR.getServer().restoreProfile(FileLocation.of("projects/ConsoleMultiLanguage/TestQualityProfileVBNet.xml"));
@@ -322,7 +323,9 @@ void testMultiLanguage() throws Exception {
322323
// Properties/AssemblyInfo.cs 15
323324
// Ny Properties/AssemblyInfo.cs 13
324325
// Module1.vb 10
325-
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(68);
326+
// ConsoleVBNet/App.config 6
327+
// ConsoleCSharp/App.config 6
328+
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(80);
326329
}
327330

328331
@Test
@@ -597,6 +600,7 @@ void testRazorCompilationNet7WithoutSourceGenerators() throws IOException {
597600

598601
@Test
599602
void testEsprojVueWithBackend() throws IOException {
603+
assumeTrue(ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9, 9));
600604
// For this test also the .vscode folder has been included in the project folder:
601605
// https://developercommunity.visualstudio.com/t/visual-studio-2022-freezes-when-opening-esproj-fil/1581344
602606
String localProjectKey = PROJECT_KEY + ".14";
@@ -629,9 +633,9 @@ void testEsprojVueWithBackend() throws IOException {
629633
"javascript:S2703",
630634
"typescript:S3626");
631635

632-
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "lines", ORCHESTRATOR)).isEqualTo(18644);
633-
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(13998);
634-
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "files", ORCHESTRATOR)).isEqualTo(212);
636+
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "lines", ORCHESTRATOR)).isEqualTo(18681);
637+
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(14028);
638+
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "files", ORCHESTRATOR)).isEqualTo(213);
635639
}
636640

637641
@Test

0 commit comments

Comments
 (0)