Skip to content

Commit

Permalink
SCAN4NET-18 Better messages for Multi-file analysis (#2156)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Aug 20, 2024
1 parent c2d6780 commit b482eda
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public void PostProc_NoProjectsToAnalyze_NoExecutionTriggered()
context.TfsProcessor.AssertNotExecuted();
context.Scanner.AssertNotExecuted();
context.Logger.AssertErrorsLogged(0);
context.Logger.AssertSingleWarningExists("""Multi-Language analysis is enabled. If this was not intended, please set "/d:sonar.scanner.scanAll=false" in the begin step.""");
context.Logger.AssertSingleWarningExists("""Multi-Language analysis is enabled. If this was not intended and you have issues such as hitting your LOC limit or analyzing unwanted files, please set "/d:sonar.scanner.scanAll=false" in the begin step.""");
context.VerifyTargetsUninstaller();

fileWrapper.Received(1).WriteAllText(
Path.Combine(context.Settings.SonarOutputDirectory, FileConstants.UIWarningsFileName),
"""
[
{
"text": "Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step."
"text": "Multi-Language analysis is enabled. If this was not intended and you have issues such as hitting your LOC limit or analyzing unwanted files, please set \"/d:sonar.scanner.scanAll=false\" in the begin step."
}
]
""");
Expand Down Expand Up @@ -192,7 +192,8 @@ public void PostProc_ValidArgsPassedThrough()
context.Scanner.AssertExecuted();
context.Scanner.SuppliedCommandLineArgs.Should().Equal(expectedArgs, "Unexpected command line args passed to the sonar-scanner");
context.Logger.AssertErrorsLogged(0);
context.Logger.AssertSingleWarningExists("""Multi-Language analysis is enabled. If this was not intended, please set "/d:sonar.scanner.scanAll=false" in the begin step.""");
context.Logger.AssertSingleWarningExists("""Multi-Language analysis is enabled. """ +
"""If this was not intended and you have issues such as hitting your LOC limit or analyzing unwanted files, please set "/d:sonar.scanner.scanAll=false" in the begin step.""");

context.VerifyTargetsUninstaller();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ public void TryWriteProperties_WhenThereIsNoCommonPath_LogsError()
// create a project in the test run directory and a second one in the temp folder.
sut.TryWriteProperties(new PropertiesWriter(config, this.logger), [firstProjectInfo, secondProjectInfo], out _);

logger.AssertErrorLogged("The project base directory cannot be automatically detected. Please specify the `sonar.projectBaseDir` on the begin step.");
logger.AssertErrorLogged("""The project base directory cannot be automatically detected. Please specify the "/d:sonar.projectBaseDir" on the begin step.""");
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ void checkMultiLanguageSupportReact() throws Exception {
Arrays.asList(
new EnvironmentVariable("AGENT_BUILDDIRECTORY", ""),
new EnvironmentVariable("BUILD_SOURCESDIRECTORY", "")),
TestUtils.TIMEOUT_LIMIT,
TestUtils.TIMEOUT_LIMIT * 5, // Longer timeout because of npm install
"/t:Restore,Rebuild",
"MultiLanguageSupportReact.csproj"
);
Expand Down Expand Up @@ -1158,7 +1158,7 @@ void checkMultiLanguageSupportAngular() throws Exception {
Arrays.asList(
new EnvironmentVariable("AGENT_BUILDDIRECTORY", ""),
new EnvironmentVariable("BUILD_SOURCESDIRECTORY", "")),
TestUtils.TIMEOUT_LIMIT,
TestUtils.TIMEOUT_LIMIT * 5, // Longer timeout because of npm install
"/t:Restore,Rebuild",
"MultiLanguageSupportAngular.csproj"
);
Expand Down Expand Up @@ -1252,7 +1252,7 @@ private void assertOnlyMultiFileAnalysisWarning(BuildResult buildResult) {
var warnings = TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult);
assertThat(warnings.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(warnings.getWarningsList()).containsExactly(
"Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
"Multi-Language analysis is enabled. If this was not intended and you have issues such as hitting your LOC limit or analyzing unwanted files, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
}

private void runCSharpSharedFileWithOneProjectUsingProjectBaseDir(Function<Path, String> getProjectBaseDir)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/SonarScanner.MSBuild.PostProcessor/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ Config file: {5}</value>
<value>Cannot process the code coverage information. Look at the previous warnings for details.</value>
</data>
<data name="WARN_UI_ScanAllAnalysisEnabled" xml:space="preserve">
<value>Multi-Language analysis is enabled. If this was not intended, please set "/d:sonar.scanner.scanAll=false" in the begin step.</value>
<value>Multi-Language analysis is enabled. If this was not intended and you have issues such as hitting your LOC limit or analyzing unwanted files, please set "/d:sonar.scanner.scanAll=false" in the begin step.</value>
</data>
</root>
3 changes: 2 additions & 1 deletion src/SonarScanner.MSBuild.Shim/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/SonarScanner.MSBuild.Shim/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Possible causes:
<value>File was referenced by the following projects: '{0}'.</value>
</data>
<data name="ERR_ProjectBaseDirCannotBeAutomaticallyDetected" xml:space="preserve">
<value>The project base directory cannot be automatically detected. Please specify the `sonar.projectBaseDir` on the begin step.</value>
<value>The project base directory cannot be automatically detected. Please specify the "/d:sonar.projectBaseDir" on the begin step.</value>
</data>
<data name="ERR_ProjectBaseDirDoesNotExist" xml:space="preserve">
<value>The project base directory doesn't exist.</value>
Expand Down

0 comments on commit b482eda

Please sign in to comment.