Skip to content

Commit

Permalink
Fixed issue #7 after testing by treating file separator the proper way
Browse files Browse the repository at this point in the history
  • Loading branch information
arburk committed Jun 6, 2021
1 parent 1a09b1d commit a444ba9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/com/baloise/open/maven/SonarIssueReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void correctPathes(SonarIssueMapper sonarIssueMapper) {
//process each mapped issue
final String filePath = issue.getPrimaryLocation().getFilePath();
srcDirPom.stream()
.map(s -> s.split("/")[0] + "/") // consider only first folder (e.g., src/) in order to capture generated folders also
// if filepath contains dir but does not start with it, it seems to be prefixed by module name
.filter(srcDirFilter -> !filePath.startsWith(srcDirFilter) && filePath.contains(srcDirFilter)).findFirst()
.ifPresent(path2Fix -> {
Expand All @@ -121,14 +122,18 @@ private List<String> getSourceDirectoryFromPom() {
}

final MavenProject project = (MavenProject) getPluginContext().get("project");
final List<String> compileSourceRoots = project.getCompileSourceRoots();
if (compileSourceRoots == null || compileSourceRoots.isEmpty()) {
final List<String> sourceRoots = new ArrayList<>();
sourceRoots.addAll(project.getCompileSourceRoots());
sourceRoots.addAll(project.getTestCompileSourceRoots());

if (sourceRoots.isEmpty()) {
return defaults;
}

final String absolutePath = project.getBasedir().getAbsolutePath();
return compileSourceRoots.stream()
final String absolutePath = project.getBasedir().getAbsolutePath() + File.separator;
return sourceRoots.stream()
.map(s -> s.replace(absolutePath, "").trim())
.map(s -> s.replace("\\", "/"))
.collect(Collectors.toList());
}

Expand Down

0 comments on commit a444ba9

Please sign in to comment.