Skip to content

Commit

Permalink
SQ Plugin: Should align logging for not indexed files (#9571)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Pohlmann authored Aug 5, 2024
1 parent 13646f5 commit 2bcf101
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@

@FunctionalInterface
public interface CoverageParser extends BiConsumer<File, Coverage> {
String VERIFY_SONARPROJECTPROPERTIES_MESSAGE = "Verify sonar.sources in .sonarqube\\out\\sonar-project.properties.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,22 @@ public Optional<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2bcf101

Please sign in to comment.