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

Add support for Deterministic Source Paths (VS Coverage format) #3817

Merged
merged 15 commits into from
Dec 15, 2020

Conversation

andrei-epure-sonarsource
Copy link
Contributor

Fixes #3362

@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Andrei/deterministic source paths Add support for Deterministic Source Paths Dec 7, 2020
@andrei-epure-sonarsource
Copy link
Contributor Author

@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:

  • have a working integration test
  • do manual testing on Windows and Linux
  • add an integration test with _, _1 and _2 placeholders inside the deterministic source paths (which won't work, as this PR is an initial baby step)
  • add a setting to enable this feature - there are a few things that could go wrong, like CI systems where _ may be the starting folder (hard to predict) - I would rather have this feature require an explicit opt-in , get feedback , and avoid live site incidents

@andrei-epure-sonarsource andrei-epure-sonarsource force-pushed the andrei/deterministic-source-paths branch 2 times, most recently from 77f6fee to f448806 Compare December 10, 2020 14:57
@andrei-epure-sonarsource andrei-epure-sonarsource marked this pull request as ready for review December 10, 2020 15:59
@andrei-epure-sonarsource
Copy link
Contributor Author

andrei-epure-sonarsource commented Dec 10, 2020

@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

  • add an integration test with _, _1 and _2 placeholders inside the deterministic source paths (which won't work, as this PR is an initial baby step)
  • add a setting to enable this feature - there are a few things that could go wrong, like CI systems where _ may be the starting folder (hard to predict) - I would rather have this feature require an explicit opt-in , get feedback , and avoid live site incidents

@andrei-epure-sonarsource
Copy link
Contributor Author

I opened #3832 to improve coverage statistics in the logging.

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a 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.

@andrei-epure-sonarsource
Copy link
Contributor Author

@pavel-mikula-sonarsource the new commits , addressing your comments, start with "rename method and fields; modify UT" 3add2dd

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a 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 :)

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

Rewritten comment

where the folder is  '/D:/a/1/s/sonar-dotnet-shared-library/mod/root/some/path/file.cs'
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a 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.

Comment on lines +56 to +65
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;
}
}
Copy link
Contributor

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)
      ));

Copy link
Contributor Author

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)

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

PathPatternPredicate = predicates().matchesPathPattern()

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a 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.

@pavel-mikula-sonarsource pavel-mikula-sonarsource merged commit 913ded9 into master Dec 15, 2020
@pavel-mikula-sonarsource pavel-mikula-sonarsource deleted the andrei/deterministic-source-paths branch December 15, 2020 16:04
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Add support for Deterministic Source Paths Add support for Deterministic Source Paths (VS Coverage format) Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deterministic Source Paths Breaks Coverage - VS Coverage format
2 participants