use of org.sonarsource.sonarlint.core.client.api.connected.ServerIssue in project sonarlint-core by SonarSource.
the class IssueTrackerTest method should_match_server_issues_by_line_hash.
@Test
public void should_match_server_issues_by_line_hash() {
String ruleKey = "dummy ruleKey";
String message = "dummy message";
String lineContent = "dummy content";
int newLine = 7;
String serverIssueKey = "dummy serverIssueKey";
Issue issue = mock(Issue.class);
when(issue.getRuleKey()).thenReturn(ruleKey);
when(issue.getMessage()).thenReturn(message);
when(issue.getStartLine()).thenReturn(newLine);
Trackable trackable = new IssueTrackable(issue, mock(TextRange.class), null, lineContent);
ServerIssue serverIssue = mock(ServerIssue.class);
when(serverIssue.ruleKey()).thenReturn(ruleKey);
when(serverIssue.message()).thenReturn(message);
when(serverIssue.checksum()).thenReturn(DigestUtils.digest(lineContent));
when(serverIssue.line()).thenReturn(newLine + 3);
when(serverIssue.creationDate()).thenReturn(Instant.now());
when(serverIssue.key()).thenReturn(serverIssueKey);
when(serverIssue.resolution()).thenReturn("fixed");
Trackable movedTrackable = new ServerIssueTrackable(serverIssue);
Trackable nonMatchingTrackable = new IssueTrackable(mockIssue(), mock(TextRange.class), null, lineContent + "x");
tracker.matchAndTrackAsNew(file1, Collections.singletonList(trackable));
tracker.matchAndTrackAsBase(file1, Arrays.asList(movedTrackable, nonMatchingTrackable));
assertThat(movedTrackable.getLineHash()).isEqualTo(trackable.getLineHash());
assertThat(movedTrackable.getLineHash()).isNotEqualTo(nonMatchingTrackable.getLineHash());
assertThat(cache.getCurrentTrackables(file1)).extracting("line", "lineHash", "serverIssueKey", "resolved").containsOnly(tuple(newLine, movedTrackable.getLineHash(), movedTrackable.getServerIssueKey(), movedTrackable.isResolved()));
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerIssue in project sonarlint-core by SonarSource.
the class IssueStorePaths method toApiIssue.
public static ServerIssue toApiIssue(Sonarlint.ServerIssue pbIssue, String idePath) {
var issue = new DefaultServerIssue();
issue.setAssigneeLogin(pbIssue.getAssigneeLogin());
issue.setLineHash(pbIssue.getLineHash());
if (pbIssue.getPrimaryLocation().hasTextRange()) {
var textRange = pbIssue.getPrimaryLocation().getTextRange();
issue.setTextRange(new TextRange(textRange.getStartLine(), textRange.getStartLineOffset(), textRange.getEndLine(), textRange.getEndLineOffset()));
issue.setCodeSnippet(trimToNull(pbIssue.getPrimaryLocation().getCodeSnippet()));
}
issue.setFilePath(idePath);
issue.setMessage(pbIssue.getPrimaryLocation().getMsg());
issue.setSeverity(pbIssue.getSeverity());
issue.setType(pbIssue.getType());
issue.setCreationDate(Instant.ofEpochMilli(pbIssue.getCreationDate()));
issue.setResolution(pbIssue.getResolution());
issue.setKey(pbIssue.getKey());
issue.setRuleKey(pbIssue.getRuleRepository() + ":" + pbIssue.getRuleKey());
for (Sonarlint.ServerIssue.Flow f : pbIssue.getFlowList()) {
issue.getFlows().add(new DefaultServerFlow(f.getLocationList()));
}
return issue;
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerIssue in project sonarlint-core by SonarSource.
the class ConnectedDeveloperIssueDownloadTest method download_all_issues_for_branch.
@Test
public void download_all_issues_for_branch() throws IOException {
engine.downloadServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, false, LONG_BRANCH, null);
var file1Issues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "src/500lines.xoo");
var file2Issues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "src/10000lines.xoo");
// Number of issues is not limited to 10k
assertThat(file1Issues.size() + file2Issues.size()).isEqualTo(10_500);
Map<String, ServerIssue> allIssues = new HashMap<>();
engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "src/500lines.xoo").forEach(i -> allIssues.put(i.key(), i));
engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "src/10000lines.xoo").forEach(i -> allIssues.put(i.key(), i));
assertThat(allIssues).hasSize(10_500);
assertThat(allIssues.get(wfIssue.getKey()).resolution()).isEqualTo("WONTFIX");
assertThat(allIssues.get(fpIssue.getKey()).resolution()).isEqualTo("FALSE-POSITIVE");
assertThat(allIssues.get(overridenSeverityIssue.getKey()).severity()).isEqualTo("BLOCKER");
assertThat(allIssues.get(overridenTypeIssue.getKey()).type()).isEqualTo("BUG");
// No hotspots
assertThat(allIssues.values()).allSatisfy(i -> assertThat(i.type()).isIn("CODE_SMELL", "BUG", "VULNERABILITY"));
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerIssue in project sonarlint-core by SonarSource.
the class IssueStoreReaderTest method testDontSetTypeIfDoesntExist.
@Test
public void testDontSetTypeIfDoesntExist() {
// setup module hierarchy
Map<String, String> modulePaths = new HashMap<>();
modulePaths.put(MODULE_KEY, "");
Builder moduleConfigBuilder = ModuleConfiguration.newBuilder();
moduleConfigBuilder.getMutableModulePathByKey().putAll(modulePaths);
when(storage.readModuleConfig(MODULE_KEY)).thenReturn(moduleConfigBuilder.build());
ScannerInput.ServerIssue serverIssue = ScannerInput.ServerIssue.newBuilder().setModuleKey(MODULE_KEY).setPath("path").build();
issueStore.save(Collections.singletonList(serverIssue));
ServerIssue issue = issueStoreReader.getServerIssues(MODULE_KEY, "path").iterator().next();
assertThat(issue.type()).isNull();
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerIssue in project sonarlint-core by SonarSource.
the class IssueStoreReader method getServerIssues.
public List<ServerIssue> getServerIssues(String moduleKey, String filePath) {
String fileKey = getFileKey(moduleKey, filePath);
Path serverIssuesPath = storagePaths.getServerIssuesPath(moduleKey);
IssueStore issueStore = issueStoreFactory.apply(serverIssuesPath);
List<ScannerInput.ServerIssue> loadedIssues = issueStore.load(fileKey);
return loadedIssues.stream().map(pbIssue -> transformIssue(pbIssue, moduleKey, filePath)).collect(Collectors.toList());
}
Aggregations