diff --git a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/CoverageParser.java b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/CoverageParser.java index dcd0d91fd34..d19ee83c908 100644 --- a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/CoverageParser.java +++ b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/CoverageParser.java @@ -24,4 +24,5 @@ @FunctionalInterface public interface CoverageParser extends BiConsumer { + String VERIFY_SONARPROJECTPROPERTIES_MESSAGE = "Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."; } diff --git a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/DotCoverReportParser.java b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/DotCoverReportParser.java index 4545d52df7d..3361b9f82b5 100644 --- a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/DotCoverReportParser.java +++ b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/DotCoverReportParser.java @@ -70,8 +70,9 @@ public void parse() { if (fileCanonicalPath != null && fileService.isSupportedAbsolute(fileCanonicalPath)) { collectCoverage(fileCanonicalPath, contents); } else { - LOG.debug("Skipping the import of dotCover code coverage for file '{}'" - + " because it is not indexed or does not have the supported language.", fileCanonicalPath); + LOG.debug("Skipping the import of dotCover code coverage for file '{}' because it is not indexed or" + + " does not have the supported language. " + VERIFY_SONARPROJECTPROPERTIES_MESSAGE, + fileCanonicalPath); } } diff --git a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/NCover3ReportParser.java b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/NCover3ReportParser.java index 5c0590b3217..1fda868da14 100644 --- a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/NCover3ReportParser.java +++ b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/NCover3ReportParser.java @@ -128,8 +128,8 @@ private void handleSegmentPointTag(XmlParserHelper xmlParserHelper) { coverage.addHits(path, line, vc); } else { - LOG.debug("NCover3 doc '{}', line '{}', vc '{}' will be skipped because it has a path '{}'" + - " which is not indexed or does not have the supported language.", + LOG.debug("NCover3 doc '{}', line '{}', vc '{}' will be skipped because it has a path '{}'" + + " which is not indexed or does not have the supported language. " + VERIFY_SONARPROJECTPROPERTIES_MESSAGE, doc, line, vc, path); } } else if (!isExcludedLine(line)) { diff --git a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParser.java b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParser.java index e443254862a..9364ea3c8db 100644 --- a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParser.java +++ b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParser.java @@ -128,7 +128,8 @@ private void handleSequencePointTag(XmlParserHelper xmlParserHelper) { LOG.trace("OpenCover parser: add hits for file {}, line '{}', visitCount '{}'.", coveredFile, line, visitCount); } else { - LOG.debug("Skipping the file {}, line '{}', visitCount '{}' because file is not indexed or does not have the supported language.", + LOG.debug("Skipping the file {}, line '{}', visitCount '{}' because file is not indexed or does not have the supported language. " + + VERIFY_SONARPROJECTPROPERTIES_MESSAGE, coveredFile, line, visitCount); } } else { @@ -164,7 +165,7 @@ private void handleBranchPointTag(XmlParserHelper xmlParserHelper) { coveredFile, line, offset, visitCount); } else { LOG.debug("OpenCover parser: Skipping branch hits for file {}, line '{}', offset '{}', visitCount '{}' because file" + - " is not indexed or does not have the supported language.", + " is not indexed or does not have the supported language. " + VERIFY_SONARPROJECTPROPERTIES_MESSAGE, coveredFile, line, offset, visitCount); } } else { diff --git a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java index d0f1ad7c7b9..271f7d1d40d 100644 --- a/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java +++ b/sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java @@ -66,13 +66,22 @@ public Optional getAbsolutePath(String deterministicBuildPath) { String foundFile = foundFiles.get(0); LOG.trace("Found indexed file '{}' for '{}' (normalized to '{}').", foundFile, deterministicBuildPath, pathSuffix); return Optional.of(foundFile); + } else if (foundFiles.isEmpty()) { + LOG.debug("The file '{}' is not indexed or does not have the supported language. Will skip this coverage entry. " + + CoverageParser.VERIFY_SONARPROJECTPROPERTIES_MESSAGE, + deterministicBuildPath); + return Optional.empty(); } else { - LOG.debug("Found {} indexed files for '{}' (normalized to '{}'). Will skip this coverage entry. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + LOG.debug("Found {} indexed files for '{}' (normalized to '{}'). Will skip this coverage entry. " + + CoverageParser.VERIFY_SONARPROJECTPROPERTIES_MESSAGE, foundFiles.size(), deterministicBuildPath, pathSuffix); return Optional.empty(); } + } else { + LOG.debug("The file '{}' does not have a deterministic build path and is either not indexed or does not have a supported language. " + + "Will skip this coverage entry. " + CoverageParser.VERIFY_SONARPROJECTPROPERTIES_MESSAGE, + deterministicBuildPath); + return Optional.empty(); } - LOG.debug("Did not find deterministic source path in '{}'. Will skip this coverage entry. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", deterministicBuildPath); - return Optional.empty(); } } diff --git a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/DotCoverReportParserTest.java b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/DotCoverReportParserTest.java index 3db5d29f732..c87da243a6c 100644 --- a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/DotCoverReportParserTest.java +++ b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/DotCoverReportParserTest.java @@ -201,7 +201,8 @@ public void predicate_false() { assertThat(logTester.logs(Level.INFO).get(0)).startsWith("Parsing the dotCover report "); assertThat(logTester.logs(Level.DEBUG).get(0)) .startsWith("Skipping the import of dotCover code coverage for file '") - .endsWith("' because it is not indexed or does not have the supported language."); + .endsWith("' because it is not indexed or does not have the supported language. " + + "Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); } @Test diff --git a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/NCover3ReportParserTest.java b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/NCover3ReportParserTest.java index 448682728e9..a2a17d971d4 100644 --- a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/NCover3ReportParserTest.java +++ b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/NCover3ReportParserTest.java @@ -140,10 +140,12 @@ public void log_unsupported_file_extension() throws Exception { assertThat(debugLogs.get(0)).startsWith("The current user dir is '"); assertThat(debugLogs.get(1)) .startsWith("NCover3 doc '1', line '31', vc '4' will be skipped because it has a path '") - .endsWith("\\MyLibrary\\Adder.cs' which is not indexed or does not have the supported language."); + .endsWith("\\MyLibrary\\Adder.cs' which is not indexed or does not have the supported language. " + + "Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); assertThat(debugLogs.get(2)) .startsWith("NCover3 doc '1', line '32', vc '4' will be skipped because it has a path '") - .endsWith("\\MyLibrary\\Adder.cs' which is not indexed or does not have the supported language."); + .endsWith("\\MyLibrary\\Adder.cs' which is not indexed or does not have the supported language. " + + "Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); List traceLogs = logTester.logs(Level.TRACE); assertThat(traceLogs.get(0)).isEqualTo("Analyzing the doc tag with NCover3 ID '1' and url 'MyLibrary\\Adder.cs'."); assertThat(traceLogs.get(1)) diff --git a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParserTest.java b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParserTest.java index 4144090413f..461bedb5edf 100644 --- a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParserTest.java +++ b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/OpenCoverReportParserTest.java @@ -324,12 +324,12 @@ public void branchCoverage_codeFile_unsupportedFile() throws Exception { // The other logs contain system-dependants paths (e.g. "The current user dir is ...", "CoveredFile created: ...") .contains( // these are not ordered - "Skipping the file (ID '1', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', visitCount '1' because file is not indexed or does not have the supported language.", - "Skipping the file (ID '2', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', visitCount '1' because file is not indexed or does not have the supported language.", - "OpenCover parser: Skipping branch hits for file (ID '2', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '1' because file is not indexed or does not have the supported language.", - "OpenCover parser: Skipping branch hits for file (ID '2', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '0' because file is not indexed or does not have the supported language.", - "OpenCover parser: Skipping branch hits for file (ID '1', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '0' because file is not indexed or does not have the supported language.", - "OpenCover parser: Skipping branch hits for file (ID '1', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '1' because file is not indexed or does not have the supported language."); + "Skipping the file (ID '1', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', visitCount '1' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + "Skipping the file (ID '2', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', visitCount '1' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + "OpenCover parser: Skipping branch hits for file (ID '2', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '1' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + "OpenCover parser: Skipping branch hits for file (ID '2', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '0' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + "OpenCover parser: Skipping branch hits for file (ID '1', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '0' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + "OpenCover parser: Skipping branch hits for file (ID '1', path 'BranchCoverage3296\\Code\\ValueProvider.cs', NO INDEXED PATH), line '5', offset '1', visitCount '1' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); } @Test @@ -402,9 +402,9 @@ public void log_unsupported_file_extension() { assertThat(debugLogs.stream().skip(1)) .containsExactlyInAnyOrder( "CoveredFile created: (ID '1', path 'MyLibraryNUnitTest\\AdderNUnitTest.cs', NO INDEXED PATH).", - "Skipping the file (ID '1', path 'MyLibraryNUnitTest\\AdderNUnitTest.cs', NO INDEXED PATH), line '16', visitCount '1' because file is not indexed or does not have the supported language.", - "Skipping the file (ID '1', path 'MyLibraryNUnitTest\\AdderNUnitTest.cs', NO INDEXED PATH), line '17', visitCount '1' because file is not indexed or does not have the supported language.", - "Skipping the file (ID '1', path 'MyLibraryNUnitTest\\AdderNUnitTest.cs', NO INDEXED PATH), line '18', visitCount '1' because file is not indexed or does not have the supported language." + "Skipping the file (ID '1', path 'MyLibraryNUnitTest\\AdderNUnitTest.cs', NO INDEXED PATH), line '16', visitCount '1' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + "Skipping the file (ID '1', path 'MyLibraryNUnitTest\\AdderNUnitTest.cs', NO INDEXED PATH), line '17', visitCount '1' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.", + "Skipping the file (ID '1', path 'MyLibraryNUnitTest\\AdderNUnitTest.cs', NO INDEXED PATH), line '18', visitCount '1' because file is not indexed or does not have the supported language. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties." ); } diff --git a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java index 2dbef70fa7d..9995ab2c63e 100644 --- a/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java +++ b/sonar-dotnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java @@ -159,7 +159,8 @@ public void getAbsolutePath_when_filesystem_returns_empty_returns_empty() { // assert assertThat(result).isEmpty(); - assertThat(logTester.logs(Level.DEBUG)).containsExactly("Found 0 indexed files for '/_/some/path/file.cs' (normalized to 'some/path/file.cs'). Will skip this coverage entry. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); + assertThat(logTester.logs(Level.DEBUG)).containsExactly("The file '/_/some/path/file.cs' is not indexed or does not have the " + + "supported language. Will skip this coverage entry. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); } @Test @@ -199,8 +200,9 @@ public void getAbsolutePath_with_no_deterministic_path_in_windows_path_returns_e verify(fs, never()).predicates(); assertThat(logTester.logs(Level.TRACE)).isEmpty(); assertThat(logTester.logs(Level.DEBUG)).hasSize(1); - assertThat(logTester.logs(Level.DEBUG).get(0)).isEqualTo("Did not find deterministic source path in 'C:\\_\\some\\path\\file.cs'." + - " Will skip this coverage entry. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); + assertThat(logTester.logs(Level.DEBUG).get(0)).isEqualTo("The file 'C:\\_\\some\\path\\file.cs' " + + "does not have a deterministic build path and is either not indexed or does not have a supported language. " + + "Will skip this coverage entry. Verify sonar.sources in .sonarqube\\out\\sonar-project.properties."); } @Test