Search in sources :

Example 1 with ServerIssue

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()));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) Test(org.junit.Test)

Example 2 with ServerIssue

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;
}
Also used : DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) TextRange(org.sonarsource.sonarlint.core.analysis.api.TextRange) DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) DefaultServerFlow(org.sonarsource.sonarlint.core.container.model.DefaultServerFlow)

Example 3 with ServerIssue

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"));
}
Also used : ProjectBinding(org.sonarsource.sonarlint.core.client.api.connected.ProjectBinding) HashMap(java.util.HashMap) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) Test(org.junit.Test)

Example 4 with ServerIssue

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();
}
Also used : ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) HashMap(java.util.HashMap) Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) Test(org.junit.Test)

Example 5 with ServerIssue

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());
}
Also used : Path(java.nio.file.Path) IssueStore(org.sonarsource.sonarlint.core.container.connected.IssueStore) List(java.util.List) DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) Map(java.util.Map) IssueStoreFactory(org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) Instant(java.time.Instant) ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) Path(java.nio.file.Path) Collectors(java.util.stream.Collectors) IssueStore(org.sonarsource.sonarlint.core.container.connected.IssueStore) DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue)

Aggregations

ServerIssue (org.sonarsource.sonarlint.core.client.api.connected.ServerIssue)8 Test (org.junit.Test)6 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 List (java.util.List)3 DefaultServerIssue (org.sonarsource.sonarlint.core.container.model.DefaultServerIssue)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2