Skip to content

Commit

Permalink
SCAN4NET-67 Bump version to 8.0.3 and cherry pick commits (#2192)
Browse files Browse the repository at this point in the history
Co-authored-by: Cristian <[email protected]>
  • Loading branch information
1 parent eac03da commit b3dda00
Show file tree
Hide file tree
Showing 19 changed files with 684 additions and 516 deletions.
6 changes: 3 additions & 3 deletions AssemblyInfo.Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
using System.Resources;
using System.Runtime.InteropServices;

[assembly: AssemblyVersion("8.0.2")]
[assembly: AssemblyFileVersion("8.0.2.0")]
[assembly: AssemblyInformationalVersion("Version:8.0.2.0 Branch:not-set Sha1:not-set")]
[assembly: AssemblyVersion("8.0.3")]
[assembly: AssemblyFileVersion("8.0.3.0")]
[assembly: AssemblyInformationalVersion("Version:8.0.3.0 Branch:not-set Sha1:not-set")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SonarSource and Microsoft")]
[assembly: AssemblyCopyright("Copyright © SonarSource and Microsoft 2015-2023")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
*/

using System;
using System.IO;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestUtilities;

namespace SonarScanner.MSBuild.Common.Test;

[TestClass]
public class ProjectInfoExtensionsTests
{
public TestContext TestContext { get; set; }

[TestMethod]
public void TryGetAnalysisSetting_WhenProjectInfoIsNull_ThrowsArgumentNullException()
{
Expand Down Expand Up @@ -136,4 +140,39 @@ public void GetProjectGuidAsString_WhenProjectInfoIsNull_ThrowsArgumentNullExcep
// Assert
action.Should().ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("projectInfo");
}

[TestMethod]
public void GetAllAnalysisFilesTest()
{
var dir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);
var filesToAnalyze = Path.Combine(dir, TestUtils.FilesToAnalyze);
var logger = new TestLogger();
var projectInfo = new ProjectInfo
{
AnalysisResults =
[
new AnalysisResult
{
Id = TestUtils.FilesToAnalyze,
Location = filesToAnalyze,
}
]
};
File.WriteAllLines(
filesToAnalyze,
[
"C:\\foo",
"C:\\bar",
"not:allowed",
"C:\\baz",
]);

var result = projectInfo.GetAllAnalysisFiles(logger);

result.Should().HaveCount(3);
result[0].Name.Should().Be("foo");
result[1].Name.Should().Be("bar");
result[2].Name.Should().Be("baz");
logger.AssertSingleDebugMessageExists("Could not add 'not:allowed' to the analysis. The given path's format is not supported.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,77 @@ public void GenerateFile_ExcludeCoverage_Exclusions_MultipleSpecified()
.Which.Value.Should().Be("coverage1.xml,coverage2.xml,coverage3.xml,coverage4.xml");
}

[DataTestMethod]
[DataRow("coverage.xml", "", "", "", "coverage.xml", "")]
[DataRow("coverage.xml", "", "local.cs,local.js", "", "local.cs,local.js,coverage.xml", "")]
[DataRow("coverage.xml", "", "", "server.cs,server.js", "server.cs,server.js,coverage.xml", "server.cs,server.js")]
[DataRow("coverage.xml", "", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js,coverage.xml", "server.cs,server.js")]
[DataRow("", "", "", "", "", "")]
[DataRow("", "", "local.cs,local.js", "", "local.cs,local.js", "")]
[DataRow("", "", "", "server.cs,server.js", "", "server.cs,server.js")]
[DataRow("", "", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js", "server.cs,server.js")]
[DataRow("", "coverage.xml", "", "", "coverage.xml", "")]
[DataRow("", "coverage.xml", "local.cs,local.js", "", "local.cs,local.js,coverage.xml", "")]
[DataRow("", "coverage.xml", "", "server.cs,server.js", "server.cs,server.js,coverage.xml", "server.cs,server.js")]
[DataRow("", "coverage.xml", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js,coverage.xml", "server.cs,server.js")]
[DataRow("localCoverage.xml", "serverCoverage.xml", "", "", "localCoverage.xml", "")]
[DataRow("localCoverage.xml", "serverCoverage.xml", "local.cs,local.js", "", "local.cs,local.js,localCoverage.xml", "")]
[DataRow("localCoverage.xml", "serverCoverage.xml", "", "server.cs,server.js", "server.cs,server.js,localCoverage.xml", "server.cs,server.js")]
[DataRow("localCoverage.xml", "serverCoverage.xml", "local.cs,local.js", "server.cs,server.js", "local.cs,local.js,localCoverage.xml", "server.cs,server.js")]
public void GenerateFile_ExcludeCoverage(
string localCoverageReportPath,
string serverCoverageReportPath,
string localExclusions,
string serverExclusions,
string expectedLocalExclusions,
string expectedServerExclusions)
{
var analysisDir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);
var settings = BuildSettings.CreateNonTeamBuildSettingsForTesting(analysisDir);
Directory.CreateDirectory(settings.SonarConfigDirectory);
var commandLineArguments = new ListPropertiesProvider();
if (!string.IsNullOrWhiteSpace(localExclusions)) // You cannot provide an empty /d:sonar.exclusions="" argument
{
commandLineArguments.AddProperty("sonar.exclusions", localExclusions);
}
if (!string.IsNullOrWhiteSpace(localCoverageReportPath))
{
commandLineArguments.AddProperty("sonar.cs.vscoveragexml.reportsPaths", localCoverageReportPath);
}
var serverSettings = new Dictionary<string, string>();
if (!string.IsNullOrWhiteSpace(serverExclusions))
{
serverSettings.Add("sonar.exclusions", serverExclusions);
}
if (!string.IsNullOrWhiteSpace(serverCoverageReportPath))
{
serverSettings.Add("sonar.cs.vscoveragexml.reportsPaths", serverCoverageReportPath);
}

var args = CreateProcessedArgs(commandLineArguments, EmptyPropertyProvider.Instance, Substitute.For<ILogger>());
var config = AnalysisConfigGenerator.GenerateFile(args, settings, [], serverSettings, [], "1.2.3.4", string.Empty);

if (string.IsNullOrWhiteSpace(expectedLocalExclusions))
{
config.LocalSettings.Should().NotContain(x => x.Id == "sonar.exclusions");
}
else
{
config.LocalSettings.Should().ContainSingle(x => x.Id == "sonar.exclusions")
.Which.Value.Should().Be(expectedLocalExclusions);
}

if (string.IsNullOrWhiteSpace(expectedServerExclusions))
{
config.ServerSettings.Should().NotContain(x => x.Id == "sonar.exclusions");
}
else
{
config.ServerSettings.Should().ContainSingle(x => x.Id == "sonar.exclusions")
.Which.Value.Should().Be(expectedServerExclusions);
}
}

private void AssertConfigFileExists(AnalysisConfig config)
{
config.Should().NotBeNull("Supplied config should not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ public void AdditionalFiles_ExtensionsFound_AllExtensionPermutations(string prop
[DataRow("sonar.tsql.file.suffixes")]
[DataRow("sonar.plsql.file.suffixes")]
[DataRow("sonar.yaml.file.suffixes")]
[DataRow("sonar.xml.file.suffixes")]
[DataRow("sonar.json.file.suffixes")]
[DataRow("sonar.css.file.suffixes")]
[DataRow("sonar.html.file.suffixes")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public void GenerateFile_MissingFilesAreSkipped()
Encoding = "UTF-8"
};

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

Expand All @@ -859,15 +859,15 @@ public void TryWriteProperties_WhenThereIsNoCommonPath_LogsError()
FullPath = Path.Combine(TestContext.TestRunDirectory, "First"),
ProjectName = "First",
AnalysisSettings = [],
AnalysisResults = [new AnalysisResult { Id = "FilesToAnalyze", Location = filesToAnalyzePath }]
AnalysisResults = [new AnalysisResult { Id = TestUtils.FilesToAnalyze, Location = filesToAnalyzePath }]
};
var secondProjectInfo = new ProjectInfo
{
ProjectGuid = Guid.NewGuid(),
FullPath = Path.Combine(Path.GetTempPath(), "Second"),
ProjectName = "Second",
AnalysisSettings = [],
AnalysisResults = [new AnalysisResult { Id = "FilesToAnalyze", Location = filesToAnalyzePath }]
AnalysisResults = [new AnalysisResult { Id = TestUtils.FilesToAnalyze, Location = filesToAnalyzePath }]
};
TestUtils.CreateEmptyFile(TestContext.TestRunDirectory, "First");
TestUtils.CreateEmptyFile(Path.GetTempPath(), "Second");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private static void CreateProjectInfoAndFilesToAnalyze(Guid guid,

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

// Create project info for the configuration, the project path is important, the name is ignored
Expand All @@ -280,7 +280,7 @@ private static void CreateProjectInfoAndFilesToAnalyze(Guid guid,
ProjectType = ProjectType.Product,
Encoding = "UTF-8",
IsExcluded = isExcluded,
AnalysisResults = [new() { Id = "FilesToAnalyze", Location = filesToAnalyze_txt }]
AnalysisResults = [new() { Id = TestUtils.FilesToAnalyze, Location = filesToAnalyze_txt }]
};
TestUtils.CreateEmptyFile(projectRoot, "Project1.csproj");
projectInfo.Save(Path.Combine(@out, FileConstants.ProjectInfoFileName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void E2E_NoAnalyzableFiles()
actualStructure.AssertConfigFileDoesNotExist(ExpectedAnalysisFilesListFileName);

// Check the projectInfo.xml does not have an analysis result
actualStructure.ProjectInfo.AssertAnalysisResultDoesNotExists("FilesToAnalyze");
actualStructure.ProjectInfo.AssertAnalysisResultDoesNotExists(TestUtils.FilesToAnalyze);
}

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

var actualFilesToAnalyze = ProjectInfo.AssertAnalysisResultExists("FilesToAnalyze");
var actualFilesToAnalyze = ProjectInfo.AssertAnalysisResultExists(TestUtils.FilesToAnalyze);
actualFilesToAnalyze.Location.Should().Be(filesToAnalyzeFile.FullPath);

AssertFileIsUtf8Bom(filesToAnalyzeFile.FullPath);
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestUtilities/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ namespace TestUtilities;

public static class TestUtils
{
public const string FilesToAnalyze = nameof(FilesToAnalyze);
// Target file names
public const string AnalysisTargetFile = "SonarQube.Integration.targets";

public const string ImportsBeforeFile = "SonarQube.Integration.ImportBefore.targets";

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions its/projects/MultiLanguageSupport/src/should_be_ignored.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<parent><child /></parent>
<?xml version="1.0" encoding="UTF-8"?> <!-- Noncompliant S1778 -->

<dependency>
<groupId>semigroup</groupId>
<artifactId>haskell.curry.monoid</artifactId>
<version>42.0</version>
</dependency>
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ void testExcludedAndTest_simulateAzureDevopsEnvironmentSettingMalformedJson_Logs

@Test
void testMultiLanguage() throws Exception {
assumeTrue(ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9,9));
String localProjectKey = PROJECT_KEY + ".12";
ORCHESTRATOR.getServer().restoreProfile(FileLocation.of("projects/ConsoleMultiLanguage/TestQualityProfileCSharp.xml"));
ORCHESTRATOR.getServer().restoreProfile(FileLocation.of("projects/ConsoleMultiLanguage/TestQualityProfileVBNet.xml"));
Expand Down Expand Up @@ -322,7 +323,9 @@ void testMultiLanguage() throws Exception {
// Properties/AssemblyInfo.cs 15
// Ny Properties/AssemblyInfo.cs 13
// Module1.vb 10
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(68);
// ConsoleVBNet/App.config 6
// ConsoleCSharp/App.config 6
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(80);
}

@Test
Expand Down Expand Up @@ -597,6 +600,7 @@ void testRazorCompilationNet7WithoutSourceGenerators() throws IOException {

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

assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "lines", ORCHESTRATOR)).isEqualTo(18644);
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(13998);
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "files", ORCHESTRATOR)).isEqualTo(212);
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "lines", ORCHESTRATOR)).isEqualTo(18681);
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "ncloc", ORCHESTRATOR)).isEqualTo(14028);
assertThat(TestUtils.getMeasureAsInteger(localProjectKey, "files", ORCHESTRATOR)).isEqualTo(213);
}

@Test
Expand Down
37 changes: 23 additions & 14 deletions its/src/test/java/com/sonar/it/scanner/msbuild/sonarqube/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,7 @@

public class Tests implements BeforeAllCallback, AfterAllCallback {

public static final Orchestrator ORCHESTRATOR = OrchestratorExtension.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "DEV")))
.setEdition(Edition.DEVELOPER)
.addPlugin(TestUtils.getMavenLocation("com.sonarsource.cpp", "sonar-cfamily-plugin", System.getProperty("sonar.cfamilyplugin.version", "LATEST_RELEASE")))
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.css", "sonar-css-plugin", System.getProperty("sonar.css.version", "LATEST_RELEASE")))
.addPlugin(FileLocation.of(TestUtils.getCustomRoslynPlugin().toFile()))
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.dotnet", "sonar-csharp-plugin", System.getProperty("sonar.csharpplugin.version", "DEV")))
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.dotnet", "sonar-vbnet-plugin", System.getProperty("sonar.vbnetplugin.version", "DEV")))
// The following plugin versions are hardcoded because `DEV` is not compatible with SQ < 8.9, to be fixed with this issue: https://github.com/SonarSource/sonar-scanner-msbuild/issues/1486
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.javascript", "sonar-javascript-plugin", System.getProperty("sonar.javascriptplugin.version", "7.4.4.15624")))
.addPlugin(TestUtils.getMavenLocation("com.sonarsource.plsql", "sonar-plsql-plugin", System.getProperty("sonar.plsqlplugin.version", "3.6.1.3873")))
.activateLicense()
.build();
public static final Orchestrator ORCHESTRATOR = createOrchestrator();

private volatile int usageCount;

Expand All @@ -62,4 +49,26 @@ public void afterAll(ExtensionContext extensionContext) throws Exception {
ORCHESTRATOR.stop();
}
}

private static Orchestrator createOrchestrator() {
var version = TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "DEV"));
var orchestrator = OrchestratorExtension.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(version)
.setEdition(Edition.DEVELOPER)
.addPlugin(TestUtils.getMavenLocation("com.sonarsource.cpp", "sonar-cfamily-plugin", System.getProperty("sonar.cfamilyplugin.version", "LATEST_RELEASE")))
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.css", "sonar-css-plugin", System.getProperty("sonar.css.version", "LATEST_RELEASE")))
.addPlugin(FileLocation.of(TestUtils.getCustomRoslynPlugin().toFile()))
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.dotnet", "sonar-csharp-plugin", System.getProperty("sonar.csharpplugin.version", "DEV")))
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.dotnet", "sonar-vbnet-plugin", System.getProperty("sonar.vbnetplugin.version", "DEV")))
// The following plugin versions are hardcoded because `DEV` is not compatible with SQ < 8.9, to be fixed with this issue: https://github.com/SonarSource/sonar-scanner-msbuild/issues/1486
.addPlugin(TestUtils.getMavenLocation("org.sonarsource.javascript", "sonar-javascript-plugin", System.getProperty("sonar.javascriptplugin.version", "7.4.4.15624")))
.addPlugin(TestUtils.getMavenLocation("com.sonarsource.plsql", "sonar-plsql-plugin", System.getProperty("sonar.plsqlplugin.version", "3.6.1.3873")))
.activateLicense();

if (!version.equals("LATEST_RELEASE[8.9]")) { // xml is not compatible with 8.9
orchestrator.addPlugin(TestUtils.getMavenLocation("org.sonarsource.xml", "sonar-xml-plugin", System.getProperty("sonar.xmlplugin.version", "LATEST_RELEASE")));
}
return orchestrator.build();
}
}
2 changes: 1 addition & 1 deletion nuspec/netcoreglobaltool/dotnet-sonarscanner.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>dotnet-sonarscanner</id>
<version>8.0.2</version>
<version>8.0.3</version>
<title>SonarScanner for .NET</title>
<authors>SonarSource,Microsoft</authors>
<projectUrl>https://redirect.sonarsource.com/doc/msbuild-sq-runner.html</projectUrl>
Expand Down
2 changes: 1 addition & 1 deletion scripts/version/Version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MainVersion>8.0.2</MainVersion>
<MainVersion>8.0.3</MainVersion>
<BuildNumber>0</BuildNumber>
<Sha1>not-set</Sha1>
<BranchName>not-set</BranchName>
Expand Down
Loading

0 comments on commit b3dda00

Please sign in to comment.