Search in sources :

Example 1 with TrackedIssue

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

the class DefaultIssueCallback method execute.

@Override
public void execute() {
    if (listener == null) {
        return;
    }
    for (TrackedIssue issue : issues.all()) {
        collectInfo(issue);
    }
    getUsers();
    for (TrackedIssue issue : issues.all()) {
        IssueListener.Issue newIssue = new IssueListener.Issue();
        newIssue.setAssigneeLogin(issue.assignee());
        newIssue.setAssigneeName(getAssigneeName(issue.assignee()));
        newIssue.setComponentKey(issue.componentKey());
        newIssue.setKey(issue.key());
        newIssue.setMessage(issue.getMessage());
        newIssue.setNew(issue.isNew());
        newIssue.setResolution(issue.resolution());
        newIssue.setRuleKey(issue.getRuleKey().toString());
        newIssue.setRuleName(getRuleName(issue.getRuleKey()));
        newIssue.setSeverity(issue.severity());
        newIssue.setStatus(issue.status());
        newIssue.setStartLine(issue.startLine());
        newIssue.setStartLineOffset(issue.startLineOffset());
        newIssue.setEndLine(issue.endLine());
        newIssue.setEndLineOffset(issue.endLineOffset());
        listener.handle(newIssue);
    }
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) IssueListener(org.sonar.batch.bootstrapper.IssueListener)

Example 2 with TrackedIssue

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

the class IssueTransformer method toTrackedIssue.

public static TrackedIssue toTrackedIssue(InputComponent component, ScannerReport.Issue rawIssue, @Nullable SourceHashHolder hashes) {
    RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey());
    Preconditions.checkNotNull(component.key(), "Component key must be set");
    Preconditions.checkNotNull(ruleKey, "Rule key must be set");
    TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null);
    issue.setKey(Uuids.createFast());
    issue.setComponentKey(component.key());
    issue.setRuleKey(ruleKey);
    issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null);
    issue.setSeverity(rawIssue.getSeverity().name());
    issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg()));
    issue.setResolution(null);
    issue.setStatus(Issue.STATUS_OPEN);
    issue.setNew(true);
    if (rawIssue.hasTextRange()) {
        TextRange r = rawIssue.getTextRange();
        issue.setStartLine(r.getStartLine());
        issue.setStartLineOffset(r.getStartOffset());
        issue.setEndLine(r.getEndLine());
        issue.setEndLineOffset(r.getEndOffset());
    }
    return issue;
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) RuleKey(org.sonar.api.rule.RuleKey) TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange)

Example 3 with TrackedIssue

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

the class IssueTransformer method toTrackedIssue.

public static TrackedIssue toTrackedIssue(ServerIssue serverIssue) {
    TrackedIssue issue = new TrackedIssue();
    issue.setKey(serverIssue.getKey());
    issue.setStatus(serverIssue.getStatus());
    issue.setResolution(serverIssue.hasResolution() ? serverIssue.getResolution() : null);
    issue.setMessage(serverIssue.hasMsg() ? serverIssue.getMsg() : null);
    issue.setStartLine(serverIssue.hasLine() ? serverIssue.getLine() : null);
    issue.setEndLine(serverIssue.hasLine() ? serverIssue.getLine() : null);
    issue.setSeverity(serverIssue.getSeverity().name());
    issue.setAssignee(serverIssue.hasAssigneeLogin() ? serverIssue.getAssigneeLogin() : null);
    issue.setComponentKey(ComponentKeys.createEffectiveKey(serverIssue.getModuleKey(), serverIssue.hasPath() ? serverIssue.getPath() : null));
    issue.setCreationDate(new Date(serverIssue.getCreationDate()));
    issue.setRuleKey(RuleKey.of(serverIssue.getRuleRepository(), serverIssue.getRuleKey()));
    issue.setNew(false);
    return issue;
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) Date(java.util.Date)

Example 4 with TrackedIssue

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

the class ResourceReport method addIssue.

public void addIssue(TrackedIssue issue, Rule rule, RulePriority severity) {
    ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity);
    initMaps(reportRuleKey);
    issues.add(issue);
    Integer line = issue.startLine();
    line = line != null ? line : 0;
    if (!issuesPerLine.containsKey(line)) {
        issuesPerLine.put(line, new ArrayList<TrackedIssue>());
    }
    issuesPerLine.get(line).add(issue);
    if (!issuesByRule.containsKey(rule)) {
        issuesByRule.put(rule, new AtomicInteger());
    }
    issuesByRule.get(rule).incrementAndGet();
    if (!issuesBySeverity.containsKey(severity)) {
        issuesBySeverity.put(severity, new AtomicInteger());
    }
    issuesBySeverity.get(severity).incrementAndGet();
    ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementCountInCurrentAnalysis();
    total.incrementCountInCurrentAnalysis();
    if (issue.isNew()) {
        if (!newIssuesPerLine.containsKey(line)) {
            newIssuesPerLine.put(line, new ArrayList<TrackedIssue>());
        }
        newIssuesPerLine.get(line).add(issue);
        total.incrementNewIssuesCount();
        ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementNewIssuesCount();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with TrackedIssue

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

the class DefaultProjectIssuesTest method should_get_all_issues.

@Test
public void should_get_all_issues() {
    DefaultIssue issueOnModule = new DefaultIssue().setKey("1").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core");
    DefaultIssue issueInModule = new DefaultIssue().setKey("2").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action");
    DefaultIssue resolvedIssueInModule = new DefaultIssue().setKey("3").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action").setResolution(Issue.RESOLUTION_FIXED);
    DefaultIssue issueOnRoot = new DefaultIssue().setKey("4").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts");
    DefaultIssue issueInRoot = new DefaultIssue().setKey("5").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts:FileInRoot");
    when(cache.all()).thenReturn(Arrays.<TrackedIssue>asList(toTrackedIssue(issueOnRoot), toTrackedIssue(issueInRoot), toTrackedIssue(issueOnModule), toTrackedIssue(issueInModule), toTrackedIssue(resolvedIssueInModule)));
    // unresolved issues
    List<Issue> issues = Lists.newArrayList(projectIssues.issues());
    assertThat(issues).containsOnly(issueOnRoot, issueInRoot, issueInModule, issueOnModule);
    List<Issue> resolvedIssues = Lists.newArrayList(projectIssues.resolvedIssues());
    assertThat(resolvedIssues).containsOnly(resolvedIssueInModule);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) Issue(org.sonar.api.issue.Issue) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

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