Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Language Support: Rework WriteSharedFiles #2098

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 67 additions & 5 deletions Tests/SonarScanner.MSBuild.Shim.Test/PropertiesWriterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void WriteGlobalSettings_VerboseIsSkipped()

sonar.modules=


""");
}

Expand All @@ -89,7 +89,7 @@ public void WriteGlobalSettings_HostUrlIsSetToSonarCloudIo_IfNotSet()

sonar.modules=


""");
}

Expand All @@ -103,7 +103,7 @@ public void WriteGlobalSettings_HostUrlIsPassedThroughIfSet()

sonar.modules=


""");
}

Expand All @@ -118,7 +118,7 @@ public void WriteGlobalSettings_HostUrlIsSetToSonarCloudUrlIfSet()

sonar.modules=


""".NormalizeLineEndings());
}

Expand All @@ -136,10 +136,72 @@ public void WriteGlobalSettings_HostUrlIsKeptIfHostUrlAndSonarcloudUrlAreSet()

sonar.modules=


""".NormalizeLineEndings());
}

[TestMethod]
public void WriteSharedProperties_EmptySources_EmptyTests()
{
var propertiesWriter = new PropertiesWriter(new(), new TestLogger());
propertiesWriter.WriteSharedFiles([], []);
propertiesWriter.Flush().Should().Be("""

sonar.modules=


""");
}

[TestMethod]
public void WriteSharedProperties_WithSources_EmptyTests()
{
var propertiesWriter = new PropertiesWriter(new(), new TestLogger());
propertiesWriter.WriteSharedFiles([new("C:/dev/main.hs"), new("C:/dev/lambdas.hs")], []);
propertiesWriter.Flush().Should().Be("""
sonar.sources=\
C:\\dev\\main.hs,\
C:\\dev\\lambdas.hs

sonar.modules=


""");
}

[TestMethod]
public void WriteSharedProperties_EmptySources_WithTests()
{
var propertiesWriter = new PropertiesWriter(new(), new TestLogger());
propertiesWriter.WriteSharedFiles([], [new("C:/dev/test.hs"), new("C:/dev/test2.hs")]);
propertiesWriter.Flush().Should().Be("""
sonar.tests=\
C:\\dev\\test.hs,\
C:\\dev\\test2.hs

sonar.modules=


""");
}

[TestMethod]
public void WriteSharedProperties_WithSources_WithTests()
{
var propertiesWriter = new PropertiesWriter(new(), new TestLogger());
propertiesWriter.WriteSharedFiles([new("C:/dev/main.hs")], [new("C:/dev/test.hs")]);
propertiesWriter.Flush().Should().Be("""
sonar.sources=\
C:\\dev\\main.hs
sonar.tests=\
C:\\dev\\test.hs

sonar.modules=


""");
}

[TestMethod]
public void WriteAnalyzerOutputPaths_ForUnexpectedLanguage_DoNotWritesOutPaths()
{
Expand Down
2 changes: 1 addition & 1 deletion src/SonarScanner.MSBuild.Shim/PropertiesFileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public bool TryWriteProperties(PropertiesWriter writer, out IEnumerable<ProjectD
}

writer.WriteSonarProjectInfo(projectBaseDir);
writer.WriteSharedFiles(rootModuleFiles);
writer.WriteSharedFiles(rootModuleFiles, []); // TODO: Populate the test files
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already working on this part on a follow up PR.

validProjects.ForEach(writer.WriteSettingsForProject);
// Handle global settings
writer.WriteGlobalSettings(analysisProperties);
Expand Down
10 changes: 7 additions & 3 deletions src/SonarScanner.MSBuild.Shim/PropertiesWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,15 @@ public void WriteSonarProjectInfo(DirectoryInfo projectBaseDir)
AppendKeyValue(SonarProperties.PullRequestCacheBasePath, config.GetConfigValue(SonarProperties.PullRequestCacheBasePath, null));
}

public void WriteSharedFiles(IEnumerable<FileInfo> sharedFiles)
public void WriteSharedFiles(IEnumerable<FileInfo> sources, IEnumerable<FileInfo> tests)
{
if (sharedFiles.Any())
if (sources.Any())
costin-zaharia-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
{
AppendKeyValue("sonar", "sources", sharedFiles);
AppendKeyValue("sonar", "sources", sources);
}
if (tests.Any())
{
AppendKeyValue("sonar", "tests", tests);
}
sb.AppendLine();
}
Expand Down
Loading