Skip to content

Commit

Permalink
SLLS-195 Fix relative paths used by issue tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
jblievremont committed Nov 17, 2023
1 parent 9c7ddf1 commit 9e80a58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private AnalysisResultsWrapper analyzeConnected(AnalysisTask task, ProjectBindin
engine.getPluginDetails(),
() -> filesToAnalyze.forEach((fileUri, openFile) -> {
var issues = issuesPerFiles.getOrDefault(fileUri, List.of());
var filePath = FileUtils.toSonarQubePath(FileUtils.getFileRelativePath(baseDir, fileUri));
var filePath = FileUtils.toSonarQubePath(binding.toServerRelativePath(FileUtils.getFileRelativePath(baseDir, fileUri)));
serverIssueTracker.matchAndTrack(filePath, issues, issueListener, task.shouldFetchServerIssues());
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public ServerIssueTrackerWrapper getServerIssueTracker() {
return issueTrackerWrapper;
}

public String toServerRelativePath(String localRelativePath) {
String relativePathWithMaybeLeadingSlash = localRelativePath.replace(binding.idePathPrefix(), binding.serverPathPrefix());
return relativePathWithMaybeLeadingSlash.replaceFirst("^/", "");
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ void test_getters() {
assertThat(underTest.getBinding()).isEqualTo(binding);
assertThat(underTest.getEngine()).isEqualTo(engine);
assertThat(underTest.getServerIssueTracker()).isEqualTo(issueTrackerWrapper);
assertThat(underTest.toServerRelativePath("idePrefix/some/file")).isEqualTo("prefix/some/file");
}

@Test
void test_fix_path_prefix() {
var binding = new ProjectBinding("projectKey", "", "some/folder");
var engine = mock(ConnectedSonarLintEngine.class);
var issueTrackerWrapper = mock(ServerIssueTrackerWrapper.class);
var underTest = new ProjectBindingWrapper("serverId", binding, engine, issueTrackerWrapper);

assertThat(underTest.toServerRelativePath("some/folder/some/file")).isEqualTo("some/file");
}
}

0 comments on commit 9e80a58

Please sign in to comment.