-
Notifications
You must be signed in to change notification settings - Fork 184
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
Support wildcards for coverage report paths #2742
Conversation
39feb3d
to
fd5a001
Compare
fd5a001
to
9bf3b2f
Compare
import org.apache.commons.io.filefilter.TrueFileFilter; | ||
import org.sonar.api.utils.WildcardPattern; | ||
|
||
// Taken from https://github.com/SonarSource/sonar-python/blob/7a683a8da47ed8db51378fbc6c50a76d98b45097/sonar-python-plugin/src/main/java/org/sonar/plugins/python/DirectoryScanner.java |
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.
yeah, we should definitely move it into commons
List<File> lcovFiles = new ArrayList<>(); | ||
for (String reportPath : reportPaths) { | ||
LOG.debug("Using pattern '{}' to resolve LCOV files", reportPath); | ||
DirectoryScanner scanner = new DirectoryScanner(baseDir, WildcardPattern.create(reportPath)); |
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.
how about passing reportPath
directly to constructor to hide this WildcardPattern
usage?
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.
Agreed
|
||
// Taken from https://github.com/SonarSource/sonar-python/blob/7a683a8da47ed8db51378fbc6c50a76d98b45097/sonar-python-plugin/src/main/java/org/sonar/plugins/python/DirectoryScanner.java | ||
|
||
public class DirectoryScanner { |
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 would call this class PatternDirectoryScanner
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.
Agreed
this.pattern = pattern; | ||
} | ||
|
||
public List<File> getIncludedFiles() { |
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.
getMatchingFiles
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.
Agreed
if (includedFiles.isEmpty()) { | ||
File file = new File(reportPath); | ||
if (!file.exists()) { | ||
LOG.debug("No LCOV files were found using pattern {}", reportPath); |
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 think it should be INFO
private static List<File> getLcovFiles(File baseDir, Set<String> reportPaths) { | ||
List<File> lcovFiles = new ArrayList<>(); | ||
for (String reportPath : reportPaths) { | ||
LOG.debug("Using pattern '{}' to resolve LCOV files", reportPath); |
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.
how about drop pattern
from this message to not confuse users not using patterns?
@@ -285,6 +285,28 @@ public void should_resolve_absolute_path() throws Exception { | |||
assertThat(context.lineHits(file2Key, 2)).isEqualTo(5); | |||
} | |||
|
|||
@Test | |||
public void should_resolve_wildcard_report_paths() throws Exception { | |||
settings.setProperty(JavaScriptPlugin.LCOV_REPORT_PATHS, "**/reports/*.lcov"); |
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.
it's not clear which reports should match
@@ -0,0 +1,12 @@ | |||
TN: | |||
SF:tests/file1.js |
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.
let's simplify these 2 reports as much as possible (I think DA:2,1
is enough)
@@ -0,0 +1,29 @@ | |||
TN: | |||
SF:deep/nested/dir/js/file1.js |
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.
why having this long path?
BRH:0 | ||
end_of_record | ||
TN: | ||
SF:file1.js |
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.
why having another file in the report to prove that it's imported?
SonarQube Quality Gate |
It appears that this PR has broken support for using
And this was working fine before this PR was released. However now it does not work. Before this PR:
After this PR:
|
Fixes #578