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

Support wildcards for coverage report paths #2742

Merged
merged 9 commits into from
Aug 9, 2021

Conversation

yassin-kammoun-sonarsource
Copy link
Contributor

Fixes #578

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
Copy link
Contributor

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));
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

getMatchingFiles

Copy link
Contributor Author

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);
Copy link
Contributor

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);
Copy link
Contributor

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");
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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?

@sonarsource-next
Copy link

@jackgeek
Copy link

jackgeek commented Aug 27, 2021

It appears that this PR has broken support for using .. in paths.
Our AzureDevOps pipeline configuration looks like this:

          - task: SonarCloudPrepare@1
            displayName: 'Prepare SonarCloud analysis'
            inputs:
              ...
              extraProperties: |
                sonar.projectBaseDir=packages/
                sonar.javascript.lcov.reportPaths=../lcov.info

And this was working fine before this PR was released. However now it does not work.

Before this PR:

INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: Analysing [/home/vsts/work/1/s/packages/../lcov.info]

After this PR:

INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: No LCOV files were found using ../lcov.info

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.

Support wildcards for coverage report paths
3 participants