Search in sources :

Example 16 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class JSONReport method writeJsonIssues.

private void writeJsonIssues(JsonWriter json, Set<RuleKey> ruleKeys, Set<String> logins) throws IOException {
    json.name("issues").beginArray();
    for (TrackedIssue issue : getIssues()) {
        if (issue.resolution() == null) {
            InputComponent component = componentStore.getByKey(issue.componentKey());
            String componentKey = getModule(component).definition().getKeyWithBranch();
            if (component instanceof InputPath) {
                componentKey = ComponentKeys.createEffectiveKey(componentKey, (InputPath) component);
            }
            json.beginObject().prop("key", issue.key()).prop("component", componentKey).prop("line", issue.startLine()).prop("startLine", issue.startLine()).prop("startOffset", issue.startLineOffset()).prop("endLine", issue.endLine()).prop("endOffset", issue.endLineOffset()).prop("message", issue.getMessage()).prop("severity", issue.severity()).prop("rule", issue.getRuleKey().toString()).prop("status", issue.status()).prop("resolution", issue.resolution()).prop("isNew", issue.isNew()).prop("assignee", issue.assignee()).prop("effortToFix", issue.gap()).propDateTime("creationDate", issue.creationDate());
            if (!StringUtils.isEmpty(issue.assignee())) {
                logins.add(issue.assignee());
            }
            json.endObject();
            ruleKeys.add(issue.getRuleKey());
        }
    }
    json.endArray();
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) InputPath(org.sonar.api.batch.fs.InputPath) InputComponent(org.sonar.api.batch.fs.InputComponent)

Example 17 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class ConsoleReport method execute.

@Override
public void execute() {
    if (settings.getBoolean(CONSOLE_REPORT_ENABLED_KEY)) {
        LOG.warn("Console report is deprecated. Use SonarLint CLI to have local reports of issues");
        Report r = new Report();
        r.setNoFile(!componentStore.allFilesToPublish().iterator().hasNext());
        for (TrackedIssue issue : issueCache.all()) {
            r.process(issue);
        }
        printReport(r);
    }
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue)

Example 18 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class TrackedIssueTest method hashes.

@Test
public void hashes() {
    String[] hashArr = new String[] { "hash1", "hash2", "hash3" };
    FileHashes hashes = FileHashes.create(hashArr);
    TrackedIssue issue = new TrackedIssue(hashes);
    issue.setStartLine(1);
    assertThat(issue.getLineHash()).isEqualTo("hash1");
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) FileHashes(org.sonar.scanner.issue.tracking.FileHashes) Test(org.junit.Test)

Example 19 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class TrackedIssueTest method round_trip.

@Test
public void round_trip() {
    TrackedIssue issue = new TrackedIssue();
    issue.setStartLine(15);
    assertThat(issue.getLine()).isEqualTo(15);
    assertThat(issue.startLine()).isEqualTo(15);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) Test(org.junit.Test)

Example 20 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class DefaultIssueCallbackTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    RuleKey ruleKey = RuleKey.of("repo", "key");
    issue = new TrackedIssue();
    issue.setKey("key");
    issue.setAssignee("user");
    issue.setRuleKey(ruleKey);
    when(issueCache.all()).thenReturn(ImmutableList.of(issue));
    ScannerInput.User.Builder userBuilder = ScannerInput.User.newBuilder();
    userBuilder.setLogin("user");
    userBuilder.setName("name");
    when(userRepository.map(Collections.singleton("user"))).thenReturn(Collections.singletonMap("user", userBuilder.build()));
    Rule r = mock(Rule.class);
    when(r.name()).thenReturn("rule name");
    when(rules.find(ruleKey)).thenReturn(r);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) RuleKey(org.sonar.api.rule.RuleKey) Rule(org.sonar.api.batch.rule.Rule) Before(org.junit.Before)

Aggregations

TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)25 Test (org.junit.Test)12 Date (java.util.Date)3 RuleKey (org.sonar.api.rule.RuleKey)3 AbstractCachesTest (org.sonar.scanner.index.AbstractCachesTest)3 File (java.io.File)2 StringWriter (java.io.StringWriter)2 InputComponent (org.sonar.api.batch.fs.InputComponent)2 Rule (org.sonar.api.batch.rule.Rule)2 Issue (org.sonar.api.issue.Issue)2 TaskResult (org.sonar.scanner.mediumtest.TaskResult)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Before (org.junit.Before)1 InputPath (org.sonar.api.batch.fs.InputPath)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 PostJobIssue (org.sonar.api.batch.postjob.issue.PostJobIssue)1 RulePriority (org.sonar.api.rules.RulePriority)1 IssueListener (org.sonar.batch.bootstrapper.IssueListener)1 DefaultIssue (org.sonar.core.issue.DefaultIssue)1 IssueCache (org.sonar.scanner.issue.IssueCache)1