-
Notifications
You must be signed in to change notification settings - Fork 231
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
Add support for Deterministic Source Paths (VS Coverage format) #3817
Add support for Deterministic Source Paths (VS Coverage format) #3817
Conversation
@pavel-mikula-sonarsource , if you want, you can have an initial look. Currently, this implementation is not working (at least in the ITs - which is an artificial use case, as the coverage file is checked in and the code runs under a temporary folder - see the details in 6969a9a commit message). Left things:
|
77f6fee
to
f448806
Compare
@pavel-mikula-sonarsource I should still test this manually on Linux , and maybe with a more complex project than the one in the integration tests Also, please share your thoughts if these are necessary
|
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Outdated
Show resolved
Hide resolved
...ry/src/test/java/org/sonar/plugins/dotnet/tests/VisualStudioCoverageXmlReportParserTest.java
Outdated
Show resolved
Hide resolved
...r-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java
Outdated
Show resolved
Hide resolved
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Show resolved
Hide resolved
I opened #3832 to improve coverage statistics in the logging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some questions and improvement suggestions.
add an integration test with _, _1 and _2 placeholders
I'd add just UTs. In one of the comments, I suggested implementing those, as it's easy.
add a setting to enable this feature
Can you demonstrate a case in UTs with what could go wrong? Having CI with _
root will just do the relative-path magic and should end in the same place as the absolute path. Shouldn't it?
I'm in for keeping it as out of the box feature. Coverage has already some pain to configure.
its/projects/CoverageWithDeterministicSourcePaths/VisualStudio.coveragexml
Show resolved
Hide resolved
...-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/NCover3ReportParser.java
Outdated
Show resolved
Hide resolved
sonar-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/FileService.java
Outdated
Show resolved
Hide resolved
...ry/src/test/java/org/sonar/plugins/dotnet/tests/VisualStudioCoverageXmlReportParserTest.java
Show resolved
Hide resolved
...ibrary/src/main/java/org/sonar/plugins/dotnet/tests/VisualStudioCoverageXmlReportParser.java
Outdated
Show resolved
Hide resolved
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Show resolved
Hide resolved
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Outdated
Show resolved
Hide resolved
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Outdated
Show resolved
Hide resolved
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Outdated
Show resolved
Hide resolved
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Outdated
Show resolved
Hide resolved
...ry/src/test/java/org/sonar/plugins/dotnet/tests/VisualStudioCoverageXmlReportParserTest.java
Show resolved
Hide resolved
6ef1c84
to
4869613
Compare
@pavel-mikula-sonarsource the new commits , addressing your comments, start with "rename method and fields; modify UT" 3add2dd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub won't let me add note to existing comment. Please take a look at the note that I will write in a minute :)
...r-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewritten comment
...r-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java
Outdated
Show resolved
Hide resolved
...r-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java
Outdated
Show resolved
Hide resolved
...tnet-shared-library/src/test/java/org/sonar/plugins/dotnet/tests/ScannerFileServiceTest.java
Outdated
Show resolved
Hide resolved
where the folder is '/D:/a/1/s/sonar-dotnet-shared-library/mod/root/some/path/file.cs'
...r-dotnet-shared-library/src/main/java/org/sonar/plugins/dotnet/tests/ScannerFileService.java
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing I didn't spot previously.
Iterable<InputFile> files = fileSystem.inputFiles(fileSystem.predicates().hasLanguage(languageKey)); | ||
int count = 0; | ||
InputFile foundFile = null; | ||
for (InputFile file : files) { | ||
String path = file.uri().getPath(); | ||
if (path.endsWith(relativePath)) { | ||
count++; | ||
foundFile = file; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new layout is great, as it's easy to follow. Now it's way more visible what's going.
Open question: The filtering in the for
is actually a manual way of implementing lambda. predicate
actually in Java terms. So can we replace this section with something predicate based?
There exists predicates().hasRelativePath()
. Does that one solve our issue (I'm not sure if it does the same)? If not, isn't it simpler to implement a predicate? Even in-lined one with the new FilePredicate(){accept(...)}
java syntax for inline abstract class implementation. As it should be 3 LOC.
We would not need the count
variable.
We would return to the structure I asked you to remove previously :D
FilePredicates fp = fileSystem.predicates();
Iterable<InputFile> files = fileSystem.inputFiles(
fp.and(
fp.hasRelativePath(path),
fp.hasLanguage(languageKey)
));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as previously mentioned during a standup on Friday, this doesn't work (the API doesn't find the file). This is why I ended up doing this logic, because I wanted to have something working.
I need to talk with someone from the scanner team for this - and I should indeed open a ticket for it.
L.E.: (it's unfortunate I didn't capture the notes for this problem in the PR; I need to create a reproducer project and report it to the scanner guild)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read your suggestion better now, getting it back in progress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy from Slack, as I just found out:
The relative path predicate does this:
return path.equals(f.relativePath());
so it will not help us 😞
As seen here: https://github.com/SonarSource/sonar-enterprise/blob/021961b86da874e4b733a566ce252[…]nar/api/batch/fs/internal/predicates/RelativePathPredicate.java
PathPatternPredicate could do the trick, but it doesn't worth the trouble with crafting the dynamic regex
So if you see easy way how to implement own predicate, let's do it. Otherwise, let's merge it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PathPatternPredicate = predicates().matchesPathPattern()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. As discussed, let's refactor the predicate in another PR.
Fixes #3362